From 49033ff8e0dd89d964264f269930b0587b8479c4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 21 Jun 2012 18:53:10 +0200 Subject: [PATCH 1/8] dont change the encryption key during the test case --- apps/files_encryption/tests/proxy.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php index 4533289265a..fcfc4cfb9f0 100644 --- a/apps/files_encryption/tests/proxy.php +++ b/apps/files_encryption/tests/proxy.php @@ -8,10 +8,12 @@ class Test_CryptProxy extends UnitTestCase { private $oldConfig; + private $oldKey; public function setUp(){ $this->oldConfig=OCP\Config::getAppValue('files_encryption','enable_encryption','true'); OCP\Config::setAppValue('files_encryption','enable_encryption','true'); + $this->oldKey=isset($_SESSION['enckey'])?$_SESSION['enckey']:null; //set testing key @@ -36,6 +38,9 @@ class Test_CryptProxy extends UnitTestCase { public function tearDown(){ OCP\Config::setAppValue('files_encryption','enable_encryption',$this->oldConfig); + if(!is_null($this->oldKey)){ + $_SESSION['enckey']=$this->oldKey; + } } public function testSimple(){ From a9a913c27304c395c3f6af3487781d02790b8009 Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Thu, 21 Jun 2012 18:07:21 +0100 Subject: [PATCH 2/8] Implemented deleteAll() method in OC_FilesystemView (interface) and OC_Filestorage_Common (logic) Made OC_Filestorage_Local and OC_Filestorage_Shared extend OC_Filestorage_Common Set searchInDir() to protected instead of private in OC_Filestorage_Local and OC_Filestorage_Shared Added class documentation to OC_Filestorage_Common Cleaned up OCA_Versions::expireAll() --- apps/files_sharing/sharedstorage.php | 4 +- apps/files_versions/versions.php | 86 ++-------------------------- lib/filestorage/common.php | 85 +++++++++++++++++++++++++++ lib/filestorage/local.php | 4 +- lib/filesystemview.php | 3 + 5 files changed, 97 insertions(+), 85 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 62c86ee18e4..fed1b834fa3 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -25,7 +25,7 @@ require_once( 'lib_share.php' ); /** * Convert target path to source path and pass the function call to the correct storage provider */ -class OC_Filestorage_Shared extends OC_Filestorage { +class OC_Filestorage_Shared extends OC_Filestorage_Common { private $datadir; private $sourcePaths = array(); @@ -492,7 +492,7 @@ class OC_Filestorage_Shared extends OC_Filestorage { return $this->searchInDir($query); } - private function searchInDir($query, $path = "") { + protected function searchInDir($query, $path = "") { $files = array(); if ($dh = $this->opendir($path)) { while (($filename = readdir($dh)) !== false) { diff --git a/apps/files_versions/versions.php b/apps/files_versions/versions.php index 7522538caf2..9c0829ff1de 100644 --- a/apps/files_versions/versions.php +++ b/apps/files_versions/versions.php @@ -261,10 +261,8 @@ class Storage { } - - /** - * expire old versions of a file. + * @brief Erase a file's versions which exceed the set quota */ public static function expire($filename) { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { @@ -298,90 +296,16 @@ class Storage { } /** - * @brief erase all old versions of all user files - * @return + * @brief Erase all old versions of all user files + * @return true/false */ public static function expireAll() { - - function deleteAll( $directory, $empty = false ) { - // strip leading slash - if( substr( $directory, 0, 1 ) == "/" ) { - - $directory = substr( $directory, 1 ); - - } - - // strip trailing slash - if( substr( $directory, -1) == "/" ) { - - $directory = substr( $directory, 0, -1 ); - - } - - $view = new \OC_FilesystemView(''); - - if ( !$view->file_exists( $directory ) || !$view->is_dir( $directory ) ) { - - return false; - - } elseif( !$view->is_readable( $directory ) ) { - - return false; - - } else { - - $foldername = \OCP\Config::getSystemValue('datadirectory') .'/' . \OCP\USER::getUser() .'/' . $directory; // have to set an absolute path for use with PHP's opendir as OC version doesn't work - - $directoryHandle = $view->opendir( \OCP\USER::getUser() . '/' . $directory ); - - while ( $contents = readdir( $directoryHandle ) ) { - - if ( $contents != '.' && $contents != '..') { - - $path = $directory . "/" . $contents; - - if ( $view->is_dir( $path ) ) { - - deleteAll( $path ); - - } else { - - $view->unlink( \OCP\USER::getUser() .'/' . $path ); // TODO: make unlink use same system path as is_dir - - } - } - - } - - //$view->closedir( $directoryHandle ); // TODO: implement closedir in OC_FSV - - if ( $empty == false ) { - - if ( !$view->rmdir( $directory ) ) { - - return false; - - } - - } - - return true; - } - - } + $view = new \OC_FilesystemView(''); $dir = \OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER); - if ( deleteAll( $dir, true ) ) { - - return true; - - } else { - - return false; - - } + return $view->deleteAll( $dir, true ); } diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index f2a5775fd19..ba78fca80e5 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -20,6 +20,18 @@ * License along with this library. If not, see . */ +/** + * Storage backend class for providing common filesystem operation methods + * which are not storage-backend specific. + * + * OC_Filestorage_Common is never used directly; it is extended by all other + * storage backends, where its methods may be overridden, and additional + * (backend-specific) methods are defined. + * + * Some OC_Filestorage_Common methods call functions which are first defined + * in classes which extend it, e.g. $this->stat() . + */ + abstract class OC_Filestorage_Common extends OC_Filestorage { public function __construct($parameters){} @@ -87,6 +99,79 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { return $count>0; } // abstract public function fopen($path,$mode); + + /** + * @brief Deletes all files and folders recursively within a directory + * @param $directory The directory whose contents will be deleted + * @param $empty Flag indicating whether directory will be emptied + * @returns true/false + * + * @note By default the directory specified by $directory will be + * deleted together with its contents. To avoid this set $empty to true + */ + public function deleteAll( $directory, $empty = false ) { + + // strip leading slash + if( substr( $directory, 0, 1 ) == "/" ) { + + $directory = substr( $directory, 1 ); + + } + + // strip trailing slash + if( substr( $directory, -1) == "/" ) { + + $directory = substr( $directory, 0, -1 ); + + } + + if ( !$this->file_exists( \OCP\USER::getUser() . '/' . $directory ) || !$this->is_dir( \OCP\USER::getUser() . '/' . $directory ) ) { + + return false; + + } elseif( !$this->is_readable( \OCP\USER::getUser() . '/' . $directory ) ) { + + return false; + + } else { + + $directoryHandle = $this->opendir( \OCP\USER::getUser() . '/' . $directory ); + + while ( $contents = readdir( $directoryHandle ) ) { + + if ( $contents != '.' && $contents != '..') { + + $path = $directory . "/" . $contents; + + if ( $this->is_dir( $path ) ) { + + deleteAll( $path ); + + } else { + + $this->unlink( \OCP\USER::getUser() .'/' . $path ); // TODO: make unlink use same system path as is_dir + + } + } + + } + + //$this->closedir( $directoryHandle ); // TODO: implement closedir in OC_FSV + + if ( $empty == false ) { + + if ( !$this->rmdir( $directory ) ) { + + return false; + + } + + } + + return true; + } + + } public function getMimeType($path){ if(!$this->file_exists($path)){ return false; diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 44a2ab0f634..b2eba051515 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -2,7 +2,7 @@ /** * for local filestore, we only have to map the paths */ -class OC_Filestorage_Local extends OC_Filestorage{ +class OC_Filestorage_Local extends OC_Filestorage_Common{ protected $datadir; private static $mimetypes=null; public function __construct($arguments){ @@ -172,7 +172,7 @@ class OC_Filestorage_Local extends OC_Filestorage{ return $this->datadir.$path; } - private function searchInDir($query,$dir=''){ + protected function searchInDir($query,$dir=''){ $files=array(); foreach (scandir($this->datadir.$dir) as $item) { if ($item == '.' || $item == '..') continue; diff --git a/lib/filesystemview.php b/lib/filesystemview.php index da622bcf920..99e08c50e75 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -252,6 +252,9 @@ class OC_FilesystemView { public function unlink($path){ return $this->basicOperation('unlink',$path,array('delete')); } + public function deleteAll( $directory, $empty = false ) { + return $this->basicOperation( 'deleteAll', $directory, array('delete'), $empty ); + } public function rename($path1,$path2){ $absolutePath1=$this->getAbsolutePath($path1); $absolutePath2=$this->getAbsolutePath($path2); From b9e3b0ddf9260c7db468268714b75e2dfdbf5a3e Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 21 Jun 2012 18:20:25 +0200 Subject: [PATCH 3/8] Tasks: Fix position of the summary input --- apps/tasks/css/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/tasks/css/style.css b/apps/tasks/css/style.css index 23aac4e9ca7..ccebe60df0f 100644 --- a/apps/tasks/css/style.css +++ b/apps/tasks/css/style.css @@ -33,7 +33,7 @@ .task .completed {position:absolute;left:3em;top:0.3em;} .task .summary{padding-left:4em;height:2em;} -.task .summary input{position:relative;left:5px;top:0.5em;} +.task .summary input{position:absolute;left:5em;top:0;} .task.done .summary{text-decoration:line-through;} .task .tag{border-radius:0.4em;display:inline-block;opacity:0.2;margin:0 0.2em;border:1px solid transparent;padding:0 0.4em;cursor:pointer;} From 10351550cd822c08b605ce9a249ff880c64b0211 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 21 Jun 2012 18:21:15 +0200 Subject: [PATCH 4/8] Tasks: Use list label for ordering by list --- apps/tasks/templates/tasks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/tasks/templates/tasks.php b/apps/tasks/templates/tasks.php index ab6138b613f..c0e2f8d4e23 100644 --- a/apps/tasks/templates/tasks.php +++ b/apps/tasks/templates/tasks.php @@ -2,7 +2,7 @@ - + From b17e6826099f2ba58d1abd246cf3c103520efea4 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 21 Jun 2012 18:21:38 +0200 Subject: [PATCH 5/8] Tasks: Add delete action --- apps/tasks/css/style.css | 2 ++ apps/tasks/js/tasks.js | 30 +++++++++++++++--------------- apps/tasks/templates/tasks.php | 3 +++ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/apps/tasks/css/style.css b/apps/tasks/css/style.css index ccebe60df0f..80b6e777b5d 100644 --- a/apps/tasks/css/style.css +++ b/apps/tasks/css/style.css @@ -58,3 +58,5 @@ .task .due{position:absolute;right:0.3em;} .task .due .date{width:6em;} .task .due .time{width:6em;} + +.task_delete{position:absolute;bottom:2px;right:5px} diff --git a/apps/tasks/js/tasks.js b/apps/tasks/js/tasks.js index 6547b80981c..bc92965bb0b 100644 --- a/apps/tasks/js/tasks.js +++ b/apps/tasks/js/tasks.js @@ -97,8 +97,10 @@ OC.Tasks = { due.find('.time').timepicker('setTime', date.getHours()+':'+date.getMinutes()); } } + var delete_action = task_container.find('.task_delete').click(OC.Tasks.deleteClickHandler); $('
') .addClass('more') + .append(delete_action) .append(description) .append(due) .appendTo(task_container); @@ -273,6 +275,19 @@ OC.Tasks = { $task.find('div.location').show(); $task.find('input.location').hide(); }, + deleteClickHandler:function(event){ + var $task = $(this).closest('.task'), + task = $task.data('task'); + $.post(OC.filePath('tasks', 'ajax', 'delete.php'),{'id':task.id},function(jsondata){ + if(jsondata.status == 'success'){ + $task.remove(); + } + else{ + alert(jsondata.data.message); + } + }); + return false; + }, complete_task:function() { var $task = $(this).closest('.task'), task = $task.data('task'), @@ -441,21 +456,6 @@ $(document).ready(function(){ }); }); - $('#tasks_delete').live('click',function(){ - var id = $('#task_details').data('id'); - $.post('ajax/delete.php',{'id':id},function(jsondata){ - if(jsondata.status == 'success'){ - $('#tasks [data-id="'+jsondata.data.id+'"]').remove(); - $('#task_details').data('id',''); - $('#task_details').html(''); - } - else{ - alert(jsondata.data.message); - } - }); - return false; - }); - $('#tasks_addtask').click(function(){ var input = $('#tasks_newtask').val(); $.post(OC.filePath('tasks', 'ajax', 'addtask.php'),{text:input},function(jsondata){ diff --git a/apps/tasks/templates/tasks.php b/apps/tasks/templates/tasks.php index c0e2f8d4e23..8c0c89e4970 100644 --- a/apps/tasks/templates/tasks.php +++ b/apps/tasks/templates/tasks.php @@ -25,6 +25,9 @@ t('Less') ?> + + t('Delete') ?> +

diff --git a/apps/contacts/templates/part.contacts.php b/apps/contacts/templates/part.contacts.php index f0b14c8e5f2..c33c5832e82 100644 --- a/apps/contacts/templates/part.contacts.php +++ b/apps/contacts/templates/part.contacts.php @@ -3,7 +3,7 @@ foreach($_['books'] as $id => $addressbook) { echo '

'.$addressbook['displayname'].'

'; echo ''; } From 37d12144c2debd27271378d2adc5c2b65a25e1f7 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Thu, 21 Jun 2012 22:03:57 +0200 Subject: [PATCH 8/8] Fix URL delimiter. --- apps/contacts/lib/search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/contacts/lib/search.php b/apps/contacts/lib/search.php index 19330fa9be1..5a5632a1520 100644 --- a/apps/contacts/lib/search.php +++ b/apps/contacts/lib/search.php @@ -11,7 +11,7 @@ class OC_Search_Provider_Contacts extends OC_Search_Provider{ $vcards = OC_Contacts_VCard::all($addressbook['id']); foreach($vcards as $vcard){ if(substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0){ - $link = OCP\Util::linkTo('contacts', 'index.php').'?id='.urlencode($vcard['id']); + $link = OCP\Util::linkTo('contacts', 'index.php').'&id='.urlencode($vcard['id']); $results[]=new OC_Search_Result($vcard['fullname'],'', $link,$l->t('Contact'));//$name,$text,$link,$type } }