From 60fdc13ae60a4d1bb62cbf29a8ab4b5ac1159709 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 22 May 2012 20:22:53 +0200 Subject: enable running unit tests from cli --- tests/index.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/index.php b/tests/index.php index 6dec1b050fb..9c5178f81a8 100644 --- a/tests/index.php +++ b/tests/index.php @@ -38,7 +38,13 @@ foreach($apps as $app){ } function loadTests($dir=''){ - $test=isset($_GET['test'])?$_GET['test']:false; + if(OC::$CLI){ + $reporter='TextReporter'; + $test=isset($_SERVER['argv'][1])?$_SERVER['argv'][1]:false; + }else{ + $reporter='HtmlReporter'; + $test=isset($_GET['test'])?$_GET['test']:false; + } if($dh=opendir($dir)){ while($name=readdir($dh)){ if(substr($name,0,1)!='.'){//no hidden files, '.' or '..' @@ -51,7 +57,7 @@ function loadTests($dir=''){ $testCase=new TestSuite($name); $testCase->addFile($file); if($testCase->getSize()>0){ - $testCase->run(new HtmlReporter()); + $testCase->run(new $reporter()); } } } -- cgit v1.2.3 From 410b556a8651695dd15e742e0501d4da341ef594 Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Fri, 1 Jun 2012 18:59:57 +0100 Subject: Added class comment block --- tests/lib/user/backend.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/lib/user/backend.php b/tests/lib/user/backend.php index 5dab5afb186..984249e84eb 100644 --- a/tests/lib/user/backend.php +++ b/tests/lib/user/backend.php @@ -20,6 +20,16 @@ * */ +/** + * Abstract class to provide the basis of backend-specific unit test classes. + * + * All subclasses MUST assign a backend property in setUp() which implements + * user operations (add, remove, etc.). Test methods in this class will then be + * run on each separate subclass and backend therein. + * + * For an example see /tests/lib/user/dummy.php + */ + abstract class Test_User_Backend extends UnitTestCase { /** * @var OC_User_Backend $backend -- cgit v1.2.3 From 301a14dcd6502f3eaaa621476c1fd788727f60ec Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 5 Jun 2012 19:58:30 +0200 Subject: add XCache backend and testcases for OC_Cache --- lib/cache/xcache.php | 37 +++++++++++++++++++++++++++++++++++++ tests/lib/cache.php | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/lib/cache/file.php | 27 +++++++++++++++++++++++++++ tests/lib/cache/xcache.php | 27 +++++++++++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 lib/cache/xcache.php create mode 100644 tests/lib/cache.php create mode 100644 tests/lib/cache/file.php create mode 100644 tests/lib/cache/xcache.php (limited to 'tests') diff --git a/lib/cache/xcache.php b/lib/cache/xcache.php new file mode 100644 index 00000000000..a1f4d905b89 --- /dev/null +++ b/lib/cache/xcache.php @@ -0,0 +1,37 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + + +class OC_Cache_XCache{ + /** + * entries in XCache gets namespaced to prevent collisions between owncloud instaces and users + */ + protected function getNameSpace() { + return OC_Util::getInstanceId().'/'.OC_User::getUser().'/'; + } + + public function get($key) { + return xcache_get($this->getNamespace().$key); + } + + public function set($key, $value, $ttl=0) { + if($ttl>0){ + return xcache_set($this->getNamespace().$key,$value,$ttl); + }else{ + return xcache_set($this->getNamespace().$key,$value); + } + } + + public function remove($key) { + return xcache_unset($this->getNamespace().$key); + } + + public function clear(){ + return xcache_unset_by_prefix($this->getNamespace()); + } +} diff --git a/tests/lib/cache.php b/tests/lib/cache.php new file mode 100644 index 00000000000..35e83a9ddcb --- /dev/null +++ b/tests/lib/cache.php @@ -0,0 +1,42 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +abstract class Test_Cache extends UnitTestCase { + /** + * @var OC_Cache cache; + */ + protected $instance; + + public function tearDown(){ + $this->instance->clear(); + } + + function testSimple(){ + $this->assertNull($this->instance->get('value1')); + + $value='foobar'; + $this->instance->set('value1',$value); + $received=$this->instance->get('value1'); + $this->assertEqual($value,$received,'Value recieved from cache not equal to the original'); + $value='ipsum lorum'; + $this->instance->set('value1',$value); + $received=$this->instance->get('value1'); + $this->assertEqual($value,$received,'Value not overwritten by seccond set'); + + $value2='foobar'; + $this->instance->set('value2',$value2); + $received2=$this->instance->get('value2'); + $this->assertEqual($value,$received,'Value changed while setting other variable'); + $this->assertEqual($value2,$received2,'Seccond value not equal to original'); + + $this->assertNull($this->instance->get('not_set'),'Unset value not equal to null'); + } + + function testTTL(){ + } +} \ No newline at end of file diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php new file mode 100644 index 00000000000..226e5068c41 --- /dev/null +++ b/tests/lib/cache/file.php @@ -0,0 +1,27 @@ +. +* +*/ + +class Test_Cache_File extends Test_Cache { + public function setUp(){ + $this->instance=new OC_Cache_File(); + } +} diff --git a/tests/lib/cache/xcache.php b/tests/lib/cache/xcache.php new file mode 100644 index 00000000000..9ec80ff83c8 --- /dev/null +++ b/tests/lib/cache/xcache.php @@ -0,0 +1,27 @@ +. +* +*/ + +class Test_Cache_XCache extends Test_Cache { + public function setUp(){ + $this->instance=new OC_Cache_XCache(); + } +} -- cgit v1.2.3 From f6298cb74fe7485856e2353e371f2923d5d47890 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 5 Jun 2012 20:54:07 +0200 Subject: add hasKey for XCache backend --- lib/cache/xcache.php | 4 ++++ tests/lib/cache.php | 5 +++++ 2 files changed, 9 insertions(+) (limited to 'tests') diff --git a/lib/cache/xcache.php b/lib/cache/xcache.php index a1f4d905b89..ad1e3e2c1f2 100644 --- a/lib/cache/xcache.php +++ b/lib/cache/xcache.php @@ -27,6 +27,10 @@ class OC_Cache_XCache{ } } + public function hasKey($key) { + return xcache_isset($this->getNamespace().$key); + } + public function remove($key) { return xcache_unset($this->getNamespace().$key); } diff --git a/tests/lib/cache.php b/tests/lib/cache.php index 35e83a9ddcb..23cbd3506eb 100644 --- a/tests/lib/cache.php +++ b/tests/lib/cache.php @@ -18,9 +18,11 @@ abstract class Test_Cache extends UnitTestCase { function testSimple(){ $this->assertNull($this->instance->get('value1')); + $this->assertFalse($this->instance->hasKey('value1')); $value='foobar'; $this->instance->set('value1',$value); + $this->assertTrue($this->instance->hasKey('value1')); $received=$this->instance->get('value1'); $this->assertEqual($value,$received,'Value recieved from cache not equal to the original'); $value='ipsum lorum'; @@ -31,9 +33,12 @@ abstract class Test_Cache extends UnitTestCase { $value2='foobar'; $this->instance->set('value2',$value2); $received2=$this->instance->get('value2'); + $this->assertTrue($this->instance->hasKey('value1')); + $this->assertTrue($this->instance->hasKey('value2')); $this->assertEqual($value,$received,'Value changed while setting other variable'); $this->assertEqual($value2,$received2,'Seccond value not equal to original'); + $this->assertFalse($this->instance->hasKey('not_set')); $this->assertNull($this->instance->get('not_set'),'Unset value not equal to null'); } -- cgit v1.2.3 From 86ddf386d981341224bbb64635d140fbfe6b5c2b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 5 Jun 2012 20:59:52 +0200 Subject: add TTL tests for OC_Cache --- tests/lib/cache.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/lib/cache.php b/tests/lib/cache.php index 23cbd3506eb..fdc39aec184 100644 --- a/tests/lib/cache.php +++ b/tests/lib/cache.php @@ -43,5 +43,14 @@ abstract class Test_Cache extends UnitTestCase { } function testTTL(){ + $value='foobar'; + $this->instance->set('value1',$value,1); + $value2='foobar'; + $this->instance->set('value2',$value2); + sleep(2); + $this->assertFalse($this->instance->hasKey('value1')); + $this->assertNull($this->instance->get('value1')); + $this->assertTrue($this->instance->hasKey('value2')); + $this->assertEqual($value2,$this->instance->get('value2')); } } \ No newline at end of file -- cgit v1.2.3 From 9984c2a5937b38d6bed294c12f58d3a62730c6c8 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 5 Jun 2012 21:11:18 +0200 Subject: Spelling fixes in XCache files --- lib/cache/xcache.php | 5 ++--- tests/lib/cache.php | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/lib/cache/xcache.php b/lib/cache/xcache.php index ad1e3e2c1f2..b57338929e0 100644 --- a/lib/cache/xcache.php +++ b/lib/cache/xcache.php @@ -6,10 +6,9 @@ * See the COPYING-README file. */ - -class OC_Cache_XCache{ +class OC_Cache_XCache { /** - * entries in XCache gets namespaced to prevent collisions between owncloud instaces and users + * entries in XCache gets namespaced to prevent collisions between owncloud instances and users */ protected function getNameSpace() { return OC_Util::getInstanceId().'/'.OC_User::getUser().'/'; diff --git a/tests/lib/cache.php b/tests/lib/cache.php index fdc39aec184..e90826b85f2 100644 --- a/tests/lib/cache.php +++ b/tests/lib/cache.php @@ -28,7 +28,7 @@ abstract class Test_Cache extends UnitTestCase { $value='ipsum lorum'; $this->instance->set('value1',$value); $received=$this->instance->get('value1'); - $this->assertEqual($value,$received,'Value not overwritten by seccond set'); + $this->assertEqual($value,$received,'Value not overwritten by second set'); $value2='foobar'; $this->instance->set('value2',$value2); @@ -36,7 +36,7 @@ abstract class Test_Cache extends UnitTestCase { $this->assertTrue($this->instance->hasKey('value1')); $this->assertTrue($this->instance->hasKey('value2')); $this->assertEqual($value,$received,'Value changed while setting other variable'); - $this->assertEqual($value2,$received2,'Seccond value not equal to original'); + $this->assertEqual($value2,$received2,'Second value not equal to original'); $this->assertFalse($this->instance->hasKey('not_set')); $this->assertNull($this->instance->get('not_set'),'Unset value not equal to null'); @@ -53,4 +53,4 @@ abstract class Test_Cache extends UnitTestCase { $this->assertTrue($this->instance->hasKey('value2')); $this->assertEqual($value2,$this->instance->get('value2')); } -} \ No newline at end of file +} -- cgit v1.2.3 From 86961b64451ac45270274d4de07cd7fc1122521b Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 5 Jun 2012 23:10:51 +0200 Subject: Skip test for XCache when the module is not there --- tests/lib/cache/xcache.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/lib/cache/xcache.php b/tests/lib/cache/xcache.php index 9ec80ff83c8..a5e954f827c 100644 --- a/tests/lib/cache/xcache.php +++ b/tests/lib/cache/xcache.php @@ -21,6 +21,10 @@ */ class Test_Cache_XCache extends Test_Cache { + function skip() { + $this->skipUnless(function_exists('xcache_get')); + } + public function setUp(){ $this->instance=new OC_Cache_XCache(); } -- cgit v1.2.3 From fc56a668ce756811f8b98557548fff2bf34799a4 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 5 Jun 2012 23:19:28 +0200 Subject: Add OC_Cache implementation for APC --- lib/cache/apc.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tests/lib/cache.php | 2 ++ tests/lib/cache/apc.php | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 lib/cache/apc.php create mode 100644 tests/lib/cache/apc.php (limited to 'tests') diff --git a/lib/cache/apc.php b/lib/cache/apc.php new file mode 100644 index 00000000000..f814afbe494 --- /dev/null +++ b/lib/cache/apc.php @@ -0,0 +1,46 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class OC_Cache_APC { + /** + * entries in APC gets namespaced to prevent collisions between owncloud instances and users + */ + protected function getNameSpace() { + return OC_Util::getInstanceId().'/'.OC_User::getUser().'/'; + } + + public function get($key) { + $result = apc_fetch($this->getNamespace().$key, $success); + if (!$success) { + return null; + } + return $result; + } + + public function set($key, $value, $ttl=0) { + return apc_store($this->getNamespace().$key, $value, $ttl); + } + + public function hasKey($key) { + return apc_exists($this->getNamespace().$key); + } + + public function remove($key) { + return apc_delete($this->getNamespace().$key); + } + + public function clear(){ + $ns = $this->getNamespace(); + $cache = apc_cache_info('user'); + foreach($cache['cache_list'] as $entry) { + if (strpos($entry['info'], $ns) === 0) { + apc_delete($entry['info']); + } + } + } +} diff --git a/tests/lib/cache.php b/tests/lib/cache.php index e90826b85f2..bb5cfc6ee19 100644 --- a/tests/lib/cache.php +++ b/tests/lib/cache.php @@ -40,6 +40,8 @@ abstract class Test_Cache extends UnitTestCase { $this->assertFalse($this->instance->hasKey('not_set')); $this->assertNull($this->instance->get('not_set'),'Unset value not equal to null'); + + $this->assertTrue($this->instance->remove('value1')); } function testTTL(){ diff --git a/tests/lib/cache/apc.php b/tests/lib/cache/apc.php new file mode 100644 index 00000000000..ab8eb188664 --- /dev/null +++ b/tests/lib/cache/apc.php @@ -0,0 +1,36 @@ +. +* +*/ + +class Test_Cache_APC extends Test_Cache { + function skip() { + $this->skipUnless(function_exists('apc_store')); + } + + public function setUp(){ + $this->instance=new OC_Cache_APC(); + } + + function testTTL(){ + // ttl doesn't work correctly in the same request + // see https://bugs.php.net/bug.php?id=58084 + } +} -- cgit v1.2.3 From ac365121022f8b03ac47c41f8b3e32f9ba3f90e6 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 8 Jun 2012 21:23:25 +0200 Subject: Don't use substr to get first char of string --- apps/files_archive/lib/storage.php | 2 +- apps/files_external/lib/ftp.php | 2 +- apps/files_external/lib/smb.php | 8 ++++---- apps/files_external/lib/swift.php | 2 +- apps/files_external/lib/webdav.php | 4 ++-- apps/user_ldap/lib_ldap.php | 4 ++-- lib/app.php | 2 +- lib/archive/tar.php | 4 ++-- lib/archive/zip.php | 2 +- lib/filesystem.php | 10 +++++----- lib/filesystemview.php | 2 +- lib/installer.php | 2 +- lib/user/database.php | 2 +- tests/index.php | 2 +- 14 files changed, 24 insertions(+), 24 deletions(-) (limited to 'tests') diff --git a/apps/files_archive/lib/storage.php b/apps/files_archive/lib/storage.php index b8f7d468385..86761663611 100644 --- a/apps/files_archive/lib/storage.php +++ b/apps/files_archive/lib/storage.php @@ -18,7 +18,7 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{ private static $rootView; private function stripPath($path){//files should never start with / - if(substr($path,0,1)=='/'){ + if(!$path || $path[0]=='/'){ $path=substr($path,1); } return $path; diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php index e9655ebf3a5..4d5ae670de5 100644 --- a/apps/files_external/lib/ftp.php +++ b/apps/files_external/lib/ftp.php @@ -21,7 +21,7 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{ $this->password=$params['password']; $this->secure=isset($params['secure'])?(bool)$params['secure']:false; $this->root=isset($params['root'])?$params['root']:'/'; - if(substr($this->root,0,1)!='/'){ + if(!$this->root || $this->root[0]!='/'){ $this->root='/'.$this->root; } diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index f594fbb880d..9112655194a 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -23,13 +23,13 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ $this->password=$params['password']; $this->share=$params['share']; $this->root=isset($params['root'])?$params['root']:'/'; + if(!$this->root || $this->root[0]!='/'){ + $this->root='/'.$this->root; + } if(substr($this->root,-1,1)!='/'){ $this->root.='/'; } - if(substr($this->root,0,1)!='/'){ - $this->root='/'.$this->root; - } - if(substr($this->share,0,1)!='/'){ + if(!$this->share || $this->share[0]!='/'){ $this->share='/'.$this->share; } if(substr($this->share,-1,1)=='/'){ diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index e3ba9c240cf..58b95a6ae01 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -269,7 +269,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{ $this->user=$params['user']; $this->root=isset($params['root'])?$params['root']:'/'; $this->secure=isset($params['secure'])?(bool)$params['secure']:true; - if(substr($this->root,0,1)!='/'){ + if(!$this->root || $this->root[0]!='/'){ $this->root='/'.$this->root; } $this->auth = new CF_Authentication($this->user, $this->token, null, $this->host); diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index 07c90d4878e..d136f04f3eb 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -25,7 +25,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{ $this->password=$params['password']; $this->secure=isset($params['secure'])?(bool)$params['secure']:false; $this->root=isset($params['root'])?$params['root']:'/'; - if(substr($this->root,0,1)!='/'){ + if(!$this->root || $this->root[0]!='/'){ $this->root='/'.$this->root; } if(substr($this->root,-1,1)!='/'){ @@ -273,7 +273,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{ } private function cleanPath($path){ - if(substr($path,0,1)=='/'){ + if(!$path || $path[0]=='/'){ return substr($path,1); }else{ return $path; diff --git a/apps/user_ldap/lib_ldap.php b/apps/user_ldap/lib_ldap.php index 22d464b65a2..befdf267bcd 100644 --- a/apps/user_ldap/lib_ldap.php +++ b/apps/user_ldap/lib_ldap.php @@ -576,7 +576,7 @@ class OC_LDAP { static private function combineFilter($filters, $operator) { $combinedFilter = '('.$operator; foreach($filters as $filter) { - if(substr($filter,0,1) != '(') { + if($filter[0] != '(') { $filter = '('.$filter.')'; } $combinedFilter.=$filter; @@ -692,4 +692,4 @@ class OC_LDAP { return false; } - } \ No newline at end of file + } diff --git a/lib/app.php b/lib/app.php index e8a5a1291d9..0c51e3c5532 100755 --- a/lib/app.php +++ b/lib/app.php @@ -469,7 +469,7 @@ class OC_App{ $apps=array(); $dh=opendir(OC::$APPSROOT.'/apps'); while($file=readdir($dh)){ - if(substr($file,0,1)!='.' and is_file(OC::$APPSROOT.'/apps/'.$file.'/appinfo/app.php')){ + if($file[0]!='.' and is_file(OC::$APPSROOT.'/apps/'.$file.'/appinfo/app.php')){ $apps[]=$file; } } diff --git a/lib/archive/tar.php b/lib/archive/tar.php index 4ff78779834..944a0ac4ba4 100644 --- a/lib/archive/tar.php +++ b/lib/archive/tar.php @@ -150,7 +150,7 @@ class OC_Archive_TAR extends OC_Archive{ $folderContent=array(); $pathLength=strlen($path); foreach($files as $file){ - if(substr($file,0,1)=='/'){ + if($file[0]=='/'){ $file=substr($file,1); } if(substr($file,0,$pathLength)==$path and $file!=$path){ @@ -241,7 +241,7 @@ class OC_Archive_TAR extends OC_Archive{ } } } - if(substr($path,0,1)!='/'){//not all programs agree on the use of a leading / + if($path[0]!='/'){//not all programs agree on the use of a leading / return $this->fileExists('/'.$path); }else{ return false; diff --git a/lib/archive/zip.php b/lib/archive/zip.php index 22ab48937eb..6631a649b16 100644 --- a/lib/archive/zip.php +++ b/lib/archive/zip.php @@ -191,7 +191,7 @@ class OC_Archive_ZIP extends OC_Archive{ } private function stripPath($path){ - if(substr($path,0,1)=='/'){ + if(!$path || $path[0]=='/'){ return substr($path,1); }else{ return $path; diff --git a/lib/filesystem.php b/lib/filesystem.php index 43d743b639d..337b0f1464b 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -150,7 +150,7 @@ class OC_Filesystem{ if(!$path){ $path='/'; } - if(substr($path,0,1)!=='/'){ + if($path[0]!=='/'){ $path='/'.$path; } $foundMountPoint=''; @@ -313,12 +313,12 @@ class OC_Filesystem{ * @param string mountpoint */ static public function mount($class,$arguments,$mountpoint){ + if($mountpoint[0]!='/'){ + $mountpoint='/'.$mountpoint; + } if(substr($mountpoint,-1)!=='/'){ $mountpoint=$mountpoint.'/'; } - if(substr($mountpoint,0,1)!=='/'){ - $mountpoint='/'.$mountpoint; - } self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments); } @@ -349,7 +349,7 @@ class OC_Filesystem{ * @return bool */ static public function isValidPath($path){ - if(substr($path,0,1)!=='/'){ + if(!$path || $path[0]!=='/'){ $path='/'.$path; } if(strstr($path,'/../') || strrchr($path, '/') === '/..' ){ diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 8aa7b49f413..6e34257a460 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -51,7 +51,7 @@ class OC_FilesystemView { if(!$path){ $path='/'; } - if(substr($path,0,1)!=='/'){ + if($path[0]!=='/'){ $path='/'.$path; } return $this->fakeRoot.$path; diff --git a/lib/installer.php b/lib/installer.php index 5c030d2917d..34c6f8c7bb9 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -110,7 +110,7 @@ class OC_Installer{ //try to find it in a subdir $dh=opendir($extractDir); while($folder=readdir($dh)){ - if(substr($folder,0,1)!='.' and is_dir($extractDir.'/'.$folder)){ + if($folder[0]!='.' and is_dir($extractDir.'/'.$folder)){ if(is_file($extractDir.'/'.$folder.'/appinfo/info.xml')){ $extractDir.='/'.$folder; } diff --git a/lib/user/database.php b/lib/user/database.php index bb077c8364f..a48b8357d64 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -129,7 +129,7 @@ class OC_User_Database extends OC_User_Backend { $row=$result->fetchRow(); if($row){ $storedHash=$row['password']; - if (substr($storedHash,0,1)=='$'){//the new phpass based hashing + if ($storedHash[0]=='$'){//the new phpass based hashing $hasher=$this->getHasher(); if($hasher->CheckPassword($password.OC_Config::getValue('passwordsalt', ''), $storedHash)){ return $row['uid']; diff --git a/tests/index.php b/tests/index.php index 9c5178f81a8..691bf2a5d45 100644 --- a/tests/index.php +++ b/tests/index.php @@ -47,7 +47,7 @@ function loadTests($dir=''){ } if($dh=opendir($dir)){ while($name=readdir($dh)){ - if(substr($name,0,1)!='.'){//no hidden files, '.' or '..' + if($name[0]!='.'){//no hidden files, '.' or '..' $file=$dir.'/'.$name; if(is_dir($file)){ loadTests($file); -- cgit v1.2.3 From 449760f665a2416875458cbb3f34387df038b08a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 15 Jun 2012 16:43:24 +0200 Subject: add hasUpdated to oc_filestorage --- apps/files_sharing/sharedstorage.php | 9 +++++++++ lib/filestorage.php | 9 +++++++++ lib/filestorage/common.php | 9 +++++++++ lib/filestorage/local.php | 9 +++++++++ tests/lib/filestorage.php | 8 ++++++++ 5 files changed, 44 insertions(+) (limited to 'tests') diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 3bb6e73035e..1a6942ad160 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -512,6 +512,15 @@ class OC_Filestorage_Shared extends OC_Filestorage { OC_Filesystem::mount('OC_Filestorage_Shared', array('datadir' => '/'.OCP\USER::getUser().'/files/Shared'), '/'.OCP\USER::getUser().'/files/Shared/'); } + /** + * check if a file or folder has been updated since $time + * @param int $time + * @return bool + */ + public function hasUpdated($path,$time){ + //TODO + return $this->filemtime($path)>$time; + } } if (OCP\USER::isLoggedIn()) { diff --git a/lib/filestorage.php b/lib/filestorage.php index 1d7e004af3b..71ef4aed00b 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -50,4 +50,13 @@ abstract class OC_Filestorage{ abstract public function search($query); abstract public function touch($path, $mtime=null); abstract public function getLocalFile($path);// get a path to a local version of the file, whether the original file is local or remote + /** + * check if a file or folder has been updated since $time + * @param int $time + * @return bool + * + * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. + * returning true for other changes in the folder is optional + */ + abstract public function hasUpdated($path,$time); } diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index f0bfc064cb5..f2a5775fd19 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -156,4 +156,13 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { } return $files; } + + /** + * check if a file or folder has been updated since $time + * @param int $time + * @return bool + */ + public function hasUpdated($path,$time){ + return $this->filemtime($path)>$time; + } } diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index ea9a9070263..44a2ab0f634 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -194,4 +194,13 @@ class OC_Filestorage_Local extends OC_Filestorage{ public function getFolderSize($path){ return 0;//depricated, use OC_FileCach instead } + + /** + * check if a file or folder has been updated since $time + * @param int $time + * @return bool + */ + public function hasUpdated($path,$time){ + return $this->filemtime($path)>$time; + } } diff --git a/tests/lib/filestorage.php b/tests/lib/filestorage.php index f71b658253a..00f37b9f1a2 100644 --- a/tests/lib/filestorage.php +++ b/tests/lib/filestorage.php @@ -149,6 +149,9 @@ abstract class Test_FileStorage extends UnitTestCase { $this->assertTrue(($ctimeStart-1)<=$cTime); $this->assertTrue($cTime<=($ctimeEnd+1)); } + $this->assertTrue($this->instance->hasUpdated('/lorem.txt',$ctimeStart-1)); + $this->assertTrue($this->instance->hasUpdated('/',$ctimeStart-1)); + $this->assertTrue(($ctimeStart-1)<=$mTime); $this->assertTrue($mTime<=($ctimeEnd+1)); $this->assertEqual(filesize($textFile),$this->instance->filesize('/lorem.txt')); @@ -168,6 +171,8 @@ abstract class Test_FileStorage extends UnitTestCase { $this->assertTrue(($mtimeStart-1)<=$mTime); $this->assertTrue($mTime<=($mtimeEnd+1)); $this->assertEqual($cTime,$originalCTime); + + $this->assertTrue($this->instance->hasUpdated('/lorem.txt',$mtimeStart-1)); if($this->instance->touch('/lorem.txt',100)!==false){ $mTime=$this->instance->filemtime('/lorem.txt'); @@ -184,6 +189,9 @@ abstract class Test_FileStorage extends UnitTestCase { $mTime=$this->instance->filemtime('/lorem.txt'); $this->assertTrue(($mtimeStart-1)<=$mTime); $this->assertTrue($mTime<=($mtimeEnd+1)); + + $this->instance->unlink('/lorem.txt'); + $this->assertTrue($this->instance->hasUpdated('/',$mtimeStart-1)); } public function testSearch(){ -- cgit v1.2.3 From d43ed43b5a5614b05a6949b4a1e757c2c5246254 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 30 Jun 2012 01:13:33 +0200 Subject: cant to ttl tests for xcache --- tests/lib/cache/xcache.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/lib/cache/xcache.php b/tests/lib/cache/xcache.php index a5e954f827c..cc2077076ce 100644 --- a/tests/lib/cache/xcache.php +++ b/tests/lib/cache/xcache.php @@ -28,4 +28,8 @@ class Test_Cache_XCache extends Test_Cache { public function setUp(){ $this->instance=new OC_Cache_XCache(); } + + function testTTL(){ + // ttl doesn't work correctly in the same request + } } -- cgit v1.2.3 From 2c35e185f714f24c6c1a2a53a47e33cf01310ebe Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 30 Jun 2012 01:14:01 +0200 Subject: make sure the filesystem is setup properly for oc_cache_file tests --- tests/lib/cache/file.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php index 226e5068c41..54e60e6569d 100644 --- a/tests/lib/cache/file.php +++ b/tests/lib/cache/file.php @@ -21,7 +21,26 @@ */ class Test_Cache_File extends Test_Cache { + function skip() { + $this->skipUnless(OC_User::isLoggedIn()); + } + public function setUp(){ + //clear all proxies and hooks so we can do clean testing + OC_FileProxy::clearProxies(); + OC_Hook::clear('OC_Filesystem'); + + //enable only the encryption hook + OC_FileProxy::register(new OC_FileProxy_Encryption()); + + //set up temporary storage + OC_Filesystem::clearMounts(); + OC_Filesystem::mount('OC_Filestorage_Temporary',array(),'/'); + + //set up the users dir + $rootView=new OC_FilesystemView(''); + $rootView->mkdir('/'.OC_User::getUser()); + $this->instance=new OC_Cache_File(); } } -- cgit v1.2.3 From 5de2a292fcfe9174542e7708b033c8026a2c46a6 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 13 Jul 2012 13:41:13 +0200 Subject: restructuring test suite invocation - now we load all test cases into one suite and execute this single suite. this is necessary to be able to generate one xml report and is also a precondition for code coverage analysis(which will follow soon) --- tests/index.php | 52 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/index.php b/tests/index.php index 691bf2a5d45..e91b3f0da56 100644 --- a/tests/index.php +++ b/tests/index.php @@ -26,39 +26,59 @@ require_once 'simpletest/mock_objects.php'; require_once 'simpletest/collector.php'; require_once 'simpletest/default_reporter.php'; +// test suite instance +$testSuite=new TestSuite("ownCloud Unit Test Suite"); + +// prepare the reporter +if(OC::$CLI){ + $reporter=new TextReporter; + $test=isset($_SERVER['argv'][1])?$_SERVER['argv'][1]:false; + if($test=='xml') + { + $reporter= new XmlReporter; + $test=false; + } +}else{ + $reporter='HtmlReporter'; + $test=isset($_GET['test'])?$_GET['test']:false; +} + //load core test cases -loadTests(dirname(__FILE__)); +loadTests(dirname(__FILE__), $testSuite, $test); //load app test cases + +// +// TODO: define a list of apps to be enabled + enable them +// + $apps=OC_App::getEnabledApps(); foreach($apps as $app){ if(is_dir(OC::$SERVERROOT.'/apps/'.$app.'/tests')){ - loadTests(OC::$SERVERROOT.'/apps/'.$app.'/tests'); + loadTests(OC::$SERVERROOT.'/apps/'.$app.'/tests', $testSuite, $test); } } -function loadTests($dir=''){ - if(OC::$CLI){ - $reporter='TextReporter'; - $test=isset($_SERVER['argv'][1])?$_SERVER['argv'][1]:false; - }else{ - $reporter='HtmlReporter'; - $test=isset($_GET['test'])?$_GET['test']:false; - } +// run the suite +if($testSuite->getSize()>0){ + $testSuite->run($reporter); +} + +// helper below +function loadTests($dir,$testSuite, $test){ if($dh=opendir($dir)){ while($name=readdir($dh)){ if($name[0]!='.'){//no hidden files, '.' or '..' $file=$dir.'/'.$name; if(is_dir($file)){ - loadTests($file); + loadTests($file, $testSuite, $test); }elseif(substr($file,-4)=='.php' and $file!=__FILE__){ $name=getTestName($file); if($test===false or $test==$name or substr($name,0,strlen($test))==$test){ - $testCase=new TestSuite($name); - $testCase->addFile($file); - if($testCase->getSize()>0){ - $testCase->run(new $reporter()); - } + $extractor = new SimpleFileLoader(); + $loadedSuite=$extractor->load($file); + if ($loadedSuite->getSize() > 0) + $testSuite->add($loadedSuite); } } } -- cgit v1.2.3 From 3ffc96c3e96de8bb26729f510e6a35be5477c6c1 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 16 Jul 2012 00:07:40 +0200 Subject: add database type to xml report --- autotest.sh | 2 +- tests/index.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/autotest.sh b/autotest.sh index fe55c1066da..bf98932a4af 100755 --- a/autotest.sh +++ b/autotest.sh @@ -69,7 +69,7 @@ function execute_tests { #test execution echo "Testing with $1 ..." cd tests - php -f index.php -- xml > autotest-results-$1.xml + php -f index.php -- xml $1 > autotest-results-$1.xml } # diff --git a/tests/index.php b/tests/index.php index e91b3f0da56..935ce39531a 100644 --- a/tests/index.php +++ b/tests/index.php @@ -26,8 +26,7 @@ require_once 'simpletest/mock_objects.php'; require_once 'simpletest/collector.php'; require_once 'simpletest/default_reporter.php'; -// test suite instance -$testSuite=new TestSuite("ownCloud Unit Test Suite"); +$testSuiteName="ownCloud Unit Test Suite"; // prepare the reporter if(OC::$CLI){ @@ -37,12 +36,19 @@ if(OC::$CLI){ { $reporter= new XmlReporter; $test=false; + + if(isset($_SERVER['argv'][2])){ + $testSuiteName=$testSuiteName." (".$_SERVER['argv'][2].")"; + } } }else{ $reporter='HtmlReporter'; $test=isset($_GET['test'])?$_GET['test']:false; } +// test suite instance +$testSuite=new TestSuite($testSuiteName); + //load core test cases loadTests(dirname(__FILE__), $testSuite, $test); -- cgit v1.2.3 From e031b9b88009ed7b1d1986d9a58e7cb39b5dd825 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 19 Jul 2012 16:19:23 +0200 Subject: fix running test cases from browser --- tests/index.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/index.php b/tests/index.php index 935ce39531a..0be27ee3fd7 100644 --- a/tests/index.php +++ b/tests/index.php @@ -32,8 +32,7 @@ $testSuiteName="ownCloud Unit Test Suite"; if(OC::$CLI){ $reporter=new TextReporter; $test=isset($_SERVER['argv'][1])?$_SERVER['argv'][1]:false; - if($test=='xml') - { + if($test=='xml'){ $reporter= new XmlReporter; $test=false; @@ -42,7 +41,7 @@ if(OC::$CLI){ } } }else{ - $reporter='HtmlReporter'; + $reporter=new HtmlReporter; $test=isset($_GET['test'])?$_GET['test']:false; } @@ -81,10 +80,10 @@ function loadTests($dir,$testSuite, $test){ }elseif(substr($file,-4)=='.php' and $file!=__FILE__){ $name=getTestName($file); if($test===false or $test==$name or substr($name,0,strlen($test))==$test){ - $extractor = new SimpleFileLoader(); + $extractor = new SimpleFileLoader(); $loadedSuite=$extractor->load($file); if ($loadedSuite->getSize() > 0) - $testSuite->add($loadedSuite); + $testSuite->add($loadedSuite); } } } -- cgit v1.2.3 From 0e6238c66fc5f37b11800e632dbcccd72833628f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 17:57:18 +0200 Subject: fix OC_Cache_File tests if encryption is not enabled --- tests/lib/cache/file.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php index 54e60e6569d..c33c513fcff 100644 --- a/tests/lib/cache/file.php +++ b/tests/lib/cache/file.php @@ -30,8 +30,10 @@ class Test_Cache_File extends Test_Cache { OC_FileProxy::clearProxies(); OC_Hook::clear('OC_Filesystem'); - //enable only the encryption hook - OC_FileProxy::register(new OC_FileProxy_Encryption()); + //enable only the encryption hook if needed + if(OC_App::isEnabled('files_encryption')){ + OC_FileProxy::register(new OC_FileProxy_Encryption()); + } //set up temporary storage OC_Filesystem::clearMounts(); -- cgit v1.2.3 From c9be9ab251681d96cfb620ca26778ba0005023d3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 18:56:18 +0200 Subject: remove unused variables --- apps/files_encryption/lib/cryptstream.php | 3 --- apps/files_external/lib/smb.php | 2 -- apps/files_external/tests/ftp.php | 1 - apps/files_external/tests/google.php | 1 - apps/files_external/tests/smb.php | 1 - apps/files_external/tests/swift.php | 1 - apps/files_external/tests/webdav.php | 1 - apps/gallery/lib/album.php | 2 +- apps/gallery/lib/managers.php | 1 - apps/gallery/lib/tiles.php | 2 +- apps/media/lib_ampache.php | 1 - apps/media/lib_collection.php | 3 +-- apps/media/lib_media.php | 6 +++--- apps/remoteStorage/lib_remoteStorage.php | 13 ++++++------- lib/archive/zip.php | 1 - lib/filecache/update.php | 1 - lib/filestorage/common.php | 2 +- lib/group/database.php | 5 ++--- lib/group/dummy.php | 3 ++- lib/group/example.php | 18 +++++++++--------- lib/public/app.php | 22 ---------------------- lib/search/provider.php | 10 +++++++--- lib/user/database.php | 8 +++----- lib/user/example.php | 12 +++--------- tests/lib/user/database.php | 1 - 25 files changed, 39 insertions(+), 82 deletions(-) (limited to 'tests') diff --git a/apps/files_encryption/lib/cryptstream.php b/apps/files_encryption/lib/cryptstream.php index e0020537563..46471911d94 100644 --- a/apps/files_encryption/lib/cryptstream.php +++ b/apps/files_encryption/lib/cryptstream.php @@ -31,9 +31,7 @@ class OC_CryptStream{ public static $sourceStreams=array(); private $source; private $path; - private $readBuffer;//for streams that dont support seeking private $meta=array();//header/meta for source stream - private $count; private $writeCache; private $size; private static $rootView; @@ -100,7 +98,6 @@ class OC_CryptStream{ public function stream_write($data){ $length=strlen($data); - $written=0; $currentPos=ftell($this->source); if($this->writeCache){ $data=$this->writeCache.$data; diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index 5e34deb2337..8a5e993b1d0 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -15,8 +15,6 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ private $root; private $share; - private static $tempFiles=array(); - public function __construct($params){ $this->host=$params['host']; $this->user=$params['user']; diff --git a/apps/files_external/tests/ftp.php b/apps/files_external/tests/ftp.php index 68481b4e66b..97796bca128 100644 --- a/apps/files_external/tests/ftp.php +++ b/apps/files_external/tests/ftp.php @@ -13,7 +13,6 @@ if(!is_array($config) or !isset($config['ftp']) or !$config['ftp']['run']){ }else{ class Test_Filestorage_FTP extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/files_external/tests/google.php b/apps/files_external/tests/google.php index 08116f0e748..806db5a6aaa 100644 --- a/apps/files_external/tests/google.php +++ b/apps/files_external/tests/google.php @@ -28,7 +28,6 @@ if(!is_array($config) or !isset($config['google']) or !$config['google']['run']) class Test_Filestorage_Google extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/files_external/tests/smb.php b/apps/files_external/tests/smb.php index e1495b7480d..001ef842276 100644 --- a/apps/files_external/tests/smb.php +++ b/apps/files_external/tests/smb.php @@ -14,7 +14,6 @@ if(!is_array($config) or !isset($config['smb']) or !$config['smb']['run']){ }else{ class Test_Filestorage_SMB extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/files_external/tests/swift.php b/apps/files_external/tests/swift.php index f0bde6ed605..1520c9473d3 100644 --- a/apps/files_external/tests/swift.php +++ b/apps/files_external/tests/swift.php @@ -13,7 +13,6 @@ if(!is_array($config) or !isset($config['swift']) or !$config['swift']['run']){ }else{ class Test_Filestorage_SWIFT extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/files_external/tests/webdav.php b/apps/files_external/tests/webdav.php index 144659819b6..14abbef2cbf 100644 --- a/apps/files_external/tests/webdav.php +++ b/apps/files_external/tests/webdav.php @@ -13,7 +13,6 @@ if(!is_array($config) or !isset($config['webdav']) or !$config['webdav']['run']) }else{ class Test_Filestorage_DAV extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php index 39d6d3aded1..701949d4d80 100644 --- a/apps/gallery/lib/album.php +++ b/apps/gallery/lib/album.php @@ -58,7 +58,7 @@ class OC_Gallery_Album { return $stmt->execute($args); } - public static function removeByName($owner, $name) { self::remove($ownmer, $name); } + public static function removeByName($owner, $name) { self::remove($owner, $name); } public static function removeByPath($owner, $path) { self::remove($owner, null, $path); } public static function removeByParentPath($owner, $parent) { self::remove($owner, null, null, $parent); } diff --git a/apps/gallery/lib/managers.php b/apps/gallery/lib/managers.php index b6ade3d1b1e..575d962dbe3 100644 --- a/apps/gallery/lib/managers.php +++ b/apps/gallery/lib/managers.php @@ -29,7 +29,6 @@ class DatabaseManager { $stmt = \OCP\DB::prepare('INSERT INTO *PREFIX*pictures_images_cache (uid_owner, path, width, height) VALUES (?, ?, ?, ?)'); $stmt->execute(array(\OCP\USER::getUser(), $path, $width, $height)); $ret = array('path' => $path, 'width' => $width, 'height' => $height); - unset($image); $dir = dirname($path); $this->cache[$dir][$path] = $ret; return $ret; diff --git a/apps/gallery/lib/tiles.php b/apps/gallery/lib/tiles.php index 754734e609e..e36d26d3191 100644 --- a/apps/gallery/lib/tiles.php +++ b/apps/gallery/lib/tiles.php @@ -33,7 +33,7 @@ class TilesLine { } public function setAvailableSpace($space) { - $available_space = $space; + $this->available_space = $space; } public function getTilesCount() { diff --git a/apps/media/lib_ampache.php b/apps/media/lib_ampache.php index d35cca150b2..d5a093338cc 100644 --- a/apps/media/lib_ampache.php +++ b/apps/media/lib_ampache.php @@ -271,7 +271,6 @@ class OC_MEDIA_AMPACHE{ "); return; } - global $SITEROOT; $filter=$params['filter']; $albums=OC_MEDIA_COLLECTION::getAlbums($filter); $artist=OC_MEDIA_COLLECTION::getArtistName($filter); diff --git a/apps/media/lib_collection.php b/apps/media/lib_collection.php index e65930f551d..cacab8e959f 100644 --- a/apps/media/lib_collection.php +++ b/apps/media/lib_collection.php @@ -27,7 +27,6 @@ class OC_MEDIA_COLLECTION{ public static $uid; private static $artistIdCache=array(); private static $albumIdCache=array(); - private static $songIdCache=array(); private static $queries=array(); /** @@ -152,7 +151,7 @@ class OC_MEDIA_COLLECTION{ return $artistId; }else{ $query=OCP\DB::prepare("INSERT INTO `*PREFIX*media_artists` (`artist_name`) VALUES (?)"); - $result=$query->execute(array($name)); + $query->execute(array($name)); return self::getArtistId($name);; } } diff --git a/apps/media/lib_media.php b/apps/media/lib_media.php index 9e687a4af2c..54502f42575 100644 --- a/apps/media/lib_media.php +++ b/apps/media/lib_media.php @@ -27,12 +27,12 @@ class OC_MEDIA{ * @param array $params, parameters passed from OC_Hook */ public static function loginListener($params){ - if(isset($_POST['user']) and $_POST['password']){ - $name=$_POST['user']; + if(isset($params['uid']) and $params['password']){ + $name=$params['uid']; $query=OCP\DB::prepare("SELECT user_id from *PREFIX*media_users WHERE user_id LIKE ?"); $uid=$query->execute(array($name))->fetchAll(); if(count($uid)==0){ - $password=hash('sha256',$_POST['password']); + $password=hash('sha256',$params['password']); $query=OCP\DB::prepare("INSERT INTO *PREFIX*media_users (user_id, user_password_sha256) VALUES (?, ?);"); $query->execute(array($name,$password)); } diff --git a/apps/remoteStorage/lib_remoteStorage.php b/apps/remoteStorage/lib_remoteStorage.php index 42cd9c90f64..c1765640c5d 100644 --- a/apps/remoteStorage/lib_remoteStorage.php +++ b/apps/remoteStorage/lib_remoteStorage.php @@ -17,12 +17,11 @@ class OC_remoteStorage { $user=OCP\USER::getUser(); $query=OCP\DB::prepare("SELECT token FROM *PREFIX*authtoken WHERE user=? AND appUrl=? AND category=? LIMIT 1"); $result=$query->execute(array($user, $appUrl, $categories)); - $ret = array(); if($row=$result->fetchRow()) { - return base64_encode('remoteStorage:'.$row['token']); - } else { - return false; - } + return base64_encode('remoteStorage:'.$row['token']); + } else { + return false; + } } public static function getAllTokens() { @@ -42,13 +41,13 @@ class OC_remoteStorage { public static function deleteToken($token) { $user=OCP\USER::getUser(); $query=OCP\DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND user=?"); - $result=$query->execute(array($token,$user)); + $query->execute(array($token,$user)); return 'unknown';//how can we see if any rows were affected? } private static function addToken($token, $appUrl, $categories){ $user=OCP\USER::getUser(); $query=OCP\DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`category`) VALUES(?,?,?,?)"); - $result=$query->execute(array($token,$appUrl,$user,$categories)); + $query->execute(array($token,$appUrl,$user,$categories)); } public static function createCategories($appUrl, $categories) { $token=uniqid(); diff --git a/lib/archive/zip.php b/lib/archive/zip.php index ff405ce098b..b2d6674d639 100644 --- a/lib/archive/zip.php +++ b/lib/archive/zip.php @@ -11,7 +11,6 @@ class OC_Archive_ZIP extends OC_Archive{ * @var ZipArchive zip */ private $zip=null; - private $success=false; private $path; function __construct($source){ diff --git a/lib/filecache/update.php b/lib/filecache/update.php index dd77f491ca0..93b632acb4e 100644 --- a/lib/filecache/update.php +++ b/lib/filecache/update.php @@ -207,7 +207,6 @@ class OC_FileCache_Update{ $cached=OC_FileCache_Cached::get($oldPath,$root); $oldSize=$cached['size']; - $size=$view->filesize($newPath); OC_FileCache::increaseSize(dirname($oldPath),-$oldSize,$root); OC_FileCache::increaseSize(dirname($newPath),$oldSize,$root); OC_FileCache::move($oldPath,$newPath); diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index ba78fca80e5..fd389d3e2d7 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -220,7 +220,7 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { } $tmpFile=OC_Helper::tmpFile($extension); $target=fopen($tmpFile,'w'); - $count=OC_Helper::streamCopy($source,$target); + OC_Helper::streamCopy($source,$target); return $tmpFile; } // abstract public function touch($path, $mtime=null); diff --git a/lib/group/database.php b/lib/group/database.php index fb173665eb8..2770ec185c4 100644 --- a/lib/group/database.php +++ b/lib/group/database.php @@ -41,7 +41,6 @@ * Class for group management in a SQL Database (e.g. MySQL, SQLite) */ class OC_Group_Database extends OC_Group_Backend { - private $userGroupCache=array(); /** * @brief Try to create a new group @@ -116,7 +115,7 @@ class OC_Group_Database extends OC_Group_Backend { // No duplicate entries! if( !$this->inGroup( $uid, $gid )){ $query = OC_DB::prepare( "INSERT INTO `*PREFIX*group_user` ( `uid`, `gid` ) VALUES( ?, ? )" ); - $result = $query->execute( array( $uid, $gid )); + $query->execute( array( $uid, $gid )); return true; }else{ return false; @@ -133,7 +132,7 @@ class OC_Group_Database extends OC_Group_Backend { */ public function removeFromGroup( $uid, $gid ){ $query = OC_DB::prepare( "DELETE FROM *PREFIX*group_user WHERE uid = ? AND gid = ?" ); - $result = $query->execute( array( $uid, $gid )); + $query->execute( array( $uid, $gid )); return true; } diff --git a/lib/group/dummy.php b/lib/group/dummy.php index 0825b10708a..1243891023f 100644 --- a/lib/group/dummy.php +++ b/lib/group/dummy.php @@ -126,7 +126,8 @@ class OC_Group_Dummy extends OC_Group_Backend { */ public function getUserGroups($uid){ $groups=array(); - foreach($this->groups as $group=>$user){ + $allGroups=array_keys($this->groups); + foreach($allGroups as $group){ if($this->inGroup($uid,$group)){ $groups[]=$group; } diff --git a/lib/group/example.php b/lib/group/example.php index c18562db7a4..f9c62fb9789 100644 --- a/lib/group/example.php +++ b/lib/group/example.php @@ -34,7 +34,7 @@ abstract class OC_Group_Example { * Trys to create a new group. If the group name already exists, false will * be returned. */ - public static function createGroup($gid){} + abstract public static function createGroup($gid); /** * @brief delete a group @@ -43,7 +43,7 @@ abstract class OC_Group_Example { * * Deletes a group and removes it from the group_user-table */ - public static function deleteGroup($gid){} + abstract public static function deleteGroup($gid); /** * @brief is user in group? @@ -53,7 +53,7 @@ abstract class OC_Group_Example { * * Checks whether the user is member of a group or not. */ - public static function inGroup($uid, $gid){} + abstract public static function inGroup($uid, $gid); /** * @brief Add a user to a group @@ -63,7 +63,7 @@ abstract class OC_Group_Example { * * Adds a user to a group. */ - public static function addToGroup($uid, $gid){} + abstract public static function addToGroup($uid, $gid); /** * @brief Removes a user from a group @@ -73,7 +73,7 @@ abstract class OC_Group_Example { * * removes the user from a group. */ - public static function removeFromGroup($uid,$gid){} + abstract public static function removeFromGroup($uid,$gid); /** * @brief Get all groups a user belongs to @@ -83,7 +83,7 @@ abstract class OC_Group_Example { * This function fetches all groups a user belongs to. It does not check * if the user exists at all. */ - public static function getUserGroups($uid){} + abstract public static function getUserGroups($uid); /** * @brief get a list of all groups @@ -91,19 +91,19 @@ abstract class OC_Group_Example { * * Returns a list with all groups */ - public static function getGroups(){} + abstract public static function getGroups(); /** * check if a group exists * @param string $gid * @return bool */ - public function groupExists($gid){} + public function groupExists($gid); /** * @brief get a list of all users in a group * @returns array with user ids */ - public static function usersInGroup($gid){} + abstract public static function usersInGroup($gid); } diff --git a/lib/public/app.php b/lib/public/app.php index 38c51af9cdb..28411933beb 100644 --- a/lib/public/app.php +++ b/lib/public/app.php @@ -34,28 +34,6 @@ namespace OCP; * This class provides functions to manage apps in ownCloud */ class App { - - /** - * @brief Makes owncloud aware of this app - * @brief This call is deprecated and not necessary to use. - * @param $data array with all information - * @returns true/false - * - * This function registers the application. $data is an associative array. - * The following keys are required: - * - id: id of the application, has to be unique ('addressbook') - * - name: Human readable name ('Addressbook') - * - version: array with Version (major, minor, bugfix) ( array(1, 0, 2)) - * - * The following keys are optional: - * - order: integer, that influences the position of your application in - * a list of applications. Lower values come first. - * - */ - public static function register( $data ){ - } - - /** * @brief adds an entry to the navigation * @param $data array containing the data diff --git a/lib/search/provider.php b/lib/search/provider.php index 838ab696d04..b3ee79b4770 100644 --- a/lib/search/provider.php +++ b/lib/search/provider.php @@ -2,13 +2,17 @@ /** * provides search functionalty */ -class OC_Search_Provider { - public function __construct($options){} +abstract class OC_Search_Provider { + private $options; + + public function __construct($options){ + $this->options=$options; + } /** * search for $query * @param string $query * @return array An array of OC_Search_Result's */ - public function search($query){} + abstract public function search($query); } diff --git a/lib/user/database.php b/lib/user/database.php index a48b8357d64..cc27b3ddbfd 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -39,7 +39,6 @@ require_once 'phpass/PasswordHash.php'; * Class for user management in a SQL Database (e.g. MySQL, SQLite) */ class OC_User_Database extends OC_User_Backend { - static private $userGroupCache=array(); /** * @var PasswordHash */ @@ -87,7 +86,7 @@ class OC_User_Database extends OC_User_Backend { public function deleteUser( $uid ){ // Delete user-group-relation $query = OC_DB::prepare( "DELETE FROM `*PREFIX*users` WHERE uid = ?" ); - $result = $query->execute( array( $uid )); + $query->execute( array( $uid )); return true; } @@ -104,11 +103,10 @@ class OC_User_Database extends OC_User_Backend { $hasher=$this->getHasher(); $hash = $hasher->HashPassword($password.OC_Config::getValue('passwordsalt', '')); $query = OC_DB::prepare( "UPDATE *PREFIX*users SET password = ? WHERE uid = ?" ); - $result = $query->execute( array( $hash, $uid )); + $query->execute( array( $hash, $uid )); return true; - } - else{ + }else{ return false; } } diff --git a/lib/user/example.php b/lib/user/example.php index 7f3fd1b8578..77246d8136c 100644 --- a/lib/user/example.php +++ b/lib/user/example.php @@ -35,9 +35,7 @@ abstract class OC_User_Example extends OC_User_Backend { * Creates a new user. Basic checking of username is done in OC_User * itself, not in its subclasses. */ - public function createUser($uid, $password){ - return OC_USER_BACKEND_NOT_IMPLEMENTED; - } + abstract public function createUser($uid, $password); /** * @brief Set password @@ -47,9 +45,7 @@ abstract class OC_User_Example extends OC_User_Backend { * * Change the password of a user */ - public function setPassword($uid, $password){ - return OC_USER_BACKEND_NOT_IMPLEMENTED; - } + abstract public function setPassword($uid, $password); /** * @brief Check if the password is correct @@ -60,7 +56,5 @@ abstract class OC_User_Example extends OC_User_Backend { * Check if the password is correct without logging in the user * returns the user id or false */ - public function checkPassword($uid, $password){ - return OC_USER_BACKEND_NOT_IMPLEMENTED; - } + abstract public function checkPassword($uid, $password); } diff --git a/tests/lib/user/database.php b/tests/lib/user/database.php index b2fcce93c5b..f484ffa78f7 100644 --- a/tests/lib/user/database.php +++ b/tests/lib/user/database.php @@ -21,7 +21,6 @@ */ class Test_User_Database extends Test_User_Backend { - private $user=array(); /** * get a new unique user name * test cases can override this in order to clean up created user -- cgit v1.2.3 From 51566e87c7343385ae3b6854386c20974c94a53d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 22 Jul 2012 02:31:43 +0200 Subject: add prefix option to OC_Cache::clear --- lib/cache.php | 7 ++++--- lib/cache/apc.php | 5 +++-- lib/cache/broker.php | 6 +++--- lib/cache/file.php | 5 +++-- lib/cache/xcache.php | 5 +++-- tests/lib/cache.php | 21 +++++++++++++++++++++ 6 files changed, 37 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/lib/cache.php b/lib/cache.php index 6f4b3e6e3f6..36f409ab71a 100644 --- a/lib/cache.php +++ b/lib/cache.php @@ -99,12 +99,13 @@ class OC_Cache { } /** - * clear the user cache + * clear the user cache of all entries starting with a prefix + * @param string prefix (optional) * @return bool */ - static public function clear() { + static public function clear($prefix='') { $user_cache = self::getUserCache(); - return $user_cache->clear(); + return $user_cache->clear($prefix); } /** diff --git a/lib/cache/apc.php b/lib/cache/apc.php index 6cf47d0c158..c192fe2f196 100644 --- a/lib/cache/apc.php +++ b/lib/cache/apc.php @@ -43,14 +43,15 @@ class OC_Cache_APC { return apc_delete($this->getNamespace().$key); } - public function clear(){ - $ns = $this->getNamespace(); + public function clear($prefix=''){ + $ns = $this->getNamespace().$prefix; $cache = apc_cache_info('user'); foreach($cache['cache_list'] as $entry) { if (strpos($entry['info'], $ns) === 0) { apc_delete($entry['info']); } } + return true; } } if(!function_exists('apc_exists')) { diff --git a/lib/cache/broker.php b/lib/cache/broker.php index 931d0dd407e..c2aceabaf53 100644 --- a/lib/cache/broker.php +++ b/lib/cache/broker.php @@ -46,8 +46,8 @@ class OC_Cache_Broker { return $this->slow_cache->remove($key); } - public function clear(){ - $this->fast_cache->clear(); - $this->slow_cache->clear(); + public function clear($prefix=''){ + $this->fast_cache->clear($prefix); + $this->slow_cache->clear($prefix); } } diff --git a/lib/cache/file.php b/lib/cache/file.php index 0b7d3e30508..562c3d17167 100644 --- a/lib/cache/file.php +++ b/lib/cache/file.php @@ -62,15 +62,16 @@ class OC_Cache_File{ return $storage->unlink($key); } - public function clear(){ + public function clear($prefix=''){ $storage = $this->getStorage(); if($storage and $storage->is_dir('/')){ $dh=$storage->opendir('/'); while($file=readdir($dh)){ - if($file!='.' and $file!='..'){ + if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)){ $storage->unlink('/'.$file); } } } + return true; } } diff --git a/lib/cache/xcache.php b/lib/cache/xcache.php index bd55cee8f6b..951f9b47545 100644 --- a/lib/cache/xcache.php +++ b/lib/cache/xcache.php @@ -43,7 +43,8 @@ class OC_Cache_XCache { return xcache_unset($this->getNamespace().$key); } - public function clear(){ - return xcache_unset_by_prefix($this->getNamespace()); + public function clear($prefix=''){ + xcache_unset_by_prefix($this->getNamespace().$prefix); + return true; } } diff --git a/tests/lib/cache.php b/tests/lib/cache.php index bb5cfc6ee19..511999be956 100644 --- a/tests/lib/cache.php +++ b/tests/lib/cache.php @@ -42,6 +42,27 @@ abstract class Test_Cache extends UnitTestCase { $this->assertNull($this->instance->get('not_set'),'Unset value not equal to null'); $this->assertTrue($this->instance->remove('value1')); + $this->assertFalse($this->instance->hasKey('value1')); + } + + function testClear(){ + $value='ipsum lorum'; + $this->instance->set('1_value1',$value); + $this->instance->set('1_value2',$value); + $this->instance->set('2_value1',$value); + $this->instance->set('3_value1',$value); + + $this->assertTrue($this->instance->clear('1_')); + $this->assertFalse($this->instance->hasKey('1_value1')); + $this->assertFalse($this->instance->hasKey('1_value2')); + $this->assertTrue($this->instance->hasKey('2_value1')); + $this->assertTrue($this->instance->hasKey('3_value1')); + + $this->assertTrue($this->instance->clear()); + $this->assertFalse($this->instance->hasKey('1_value1')); + $this->assertFalse($this->instance->hasKey('1_value2')); + $this->assertFalse($this->instance->hasKey('2_value1')); + $this->assertFalse($this->instance->hasKey('3_value1')); } function testTTL(){ -- cgit v1.2.3 From ab7a2d43e810da66087f3abf4a87afff219a33c0 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 23 Jul 2012 22:07:42 +0200 Subject: create a user for Test_Cache_File to allow unit tesing within ci --- tests/lib/cache/file.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php index c33c513fcff..be2a2a72778 100644 --- a/tests/lib/cache/file.php +++ b/tests/lib/cache/file.php @@ -22,7 +22,7 @@ class Test_Cache_File extends Test_Cache { function skip() { - $this->skipUnless(OC_User::isLoggedIn()); + //$this->skipUnless(OC_User::isLoggedIn()); } public function setUp(){ @@ -39,6 +39,13 @@ class Test_Cache_File extends Test_Cache { OC_Filesystem::clearMounts(); OC_Filesystem::mount('OC_Filestorage_Temporary',array(),'/'); + //login + if (OC_User::userExists('test')) + OC_User::deleteUser('test'); + OC_User::createUser('test', 'testtesttest'); + + OC_User::login('test', 'testtesttest'); + //set up the users dir $rootView=new OC_FilesystemView(''); $rootView->mkdir('/'.OC_User::getUser()); -- cgit v1.2.3 From 59364366d8c69ca217fb817535d1b5d1df316841 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 23 Jul 2012 22:32:07 +0200 Subject: use dummy user backend for oc_cache_file tests --- tests/lib/cache/file.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php index be2a2a72778..28778efb68c 100644 --- a/tests/lib/cache/file.php +++ b/tests/lib/cache/file.php @@ -21,6 +21,8 @@ */ class Test_Cache_File extends Test_Cache { + private $user; + function skip() { //$this->skipUnless(OC_User::isLoggedIn()); } @@ -39,17 +41,23 @@ class Test_Cache_File extends Test_Cache { OC_Filesystem::clearMounts(); OC_Filesystem::mount('OC_Filestorage_Temporary',array(),'/'); + OC_User::clearBackends(); + OC_User::useBackend(new OC_User_Dummy()); + //login - if (OC_User::userExists('test')) - OC_User::deleteUser('test'); - OC_User::createUser('test', 'testtesttest'); - - OC_User::login('test', 'testtesttest'); + OC_User::createUser('test', 'test'); + + $this->user=OC_User::getUser(); + OC_User::setUserId('test'); //set up the users dir $rootView=new OC_FilesystemView(''); - $rootView->mkdir('/'.OC_User::getUser()); + $rootView->mkdir('/test'); $this->instance=new OC_Cache_File(); } + + public function tearDown(){ + OC_User::setUserId($this->user); + } } -- cgit v1.2.3 From 0c8ce0bb32c4a79c248e71533f9fa00b844049fb Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 14 Aug 2012 02:44:45 +0200 Subject: some basic path normalization --- lib/filesystem.php | 22 ++++++++++++++++++++++ lib/filesystemview.php | 5 ++--- tests/lib/filesystem.php | 11 +++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/lib/filesystem.php b/lib/filesystem.php index 5af6e0aa54c..221345332b0 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -494,6 +494,28 @@ class OC_Filesystem{ } OC_Connector_Sabre_Node::removeETagPropertyForPath($path); } + + public static function normalizePath($path){ + //no windows style slashes + $path=str_replace('\\','/',$path); + //add leading slash + if($path[0]!=='/'){ + $path='/'.$path; + } + //remove trainling slash + if(substr($path,-1,1)==='/'){ + $path=substr($path,0,-1); + } + //remove duplicate slashes + while(strpos($path,'//')!==false){ + $path=str_replace('//','/',$path); + } + //normalize unicode if possible + if(class_exists('Normalizer')){ + $path=Normalizer::normalize($path); + } + return $path; + } } OC_Hook::connect('OC_Filesystem','post_write', 'OC_Filesystem','removeETagHook'); OC_Hook::connect('OC_Filesystem','post_delete','OC_Filesystem','removeETagHook'); diff --git a/lib/filesystemview.php b/lib/filesystemview.php index faf3f0bd4cc..17d09a07001 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -54,10 +54,9 @@ class OC_FilesystemView { if($path[0]!=='/'){ $path='/'.$path; } - return $this->fakeRoot.$path; + return OC_Filesystem::normalizePath($this->fakeRoot.$path); } - - + /** * change the root to a fake toor * @param string fakeRoot diff --git a/tests/lib/filesystem.php b/tests/lib/filesystem.php index 3e28d8c06e5..e041255ec91 100644 --- a/tests/lib/filesystem.php +++ b/tests/lib/filesystem.php @@ -59,6 +59,17 @@ class Test_Filesystem extends UnitTestCase{ $this->assertEqual('/',OC_Filesystem::getMountPoint('/some')); $this->assertEqual('folder',OC_Filesystem::getInternalPath('/some/folder')); } + + public function testNormalize(){ + $this->assertEqual('/path',OC_Filesystem::normalizePath('/path/')); + $this->assertEqual('/path',OC_Filesystem::normalizePath('path')); + $this->assertEqual('/path',OC_Filesystem::normalizePath('\path')); + $this->assertEqual('/foo/bar',OC_Filesystem::normalizePath('/foo//bar/')); + $this->assertEqual('/foo/bar',OC_Filesystem::normalizePath('/foo////bar')); + if(class_exists('Normalizer')){ + $this->assertEqual("/foo/bar\xC3\xBC",OC_Filesystem::normalizePath("/foo/baru\xCC\x88")); + } + } } ?> \ No newline at end of file -- cgit v1.2.3 From 137e4cb342c896dd843f418cdc6cd9daf27b3754 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 15 Aug 2012 11:55:54 -0400 Subject: Add tests for Share API, all tests passing :) --- lib/filestorage/commontest.php | 8 +- tests/lib/filestorage.php | 10 +- tests/lib/share/backend.php | 73 +++++----- tests/lib/share/share.php | 318 ++++++++++++++++++++++++++++------------- 4 files changed, 267 insertions(+), 142 deletions(-) (limited to 'tests') diff --git a/lib/filestorage/commontest.php b/lib/filestorage/commontest.php index 1b01ff856a3..b5126a407b3 100644 --- a/lib/filestorage/commontest.php +++ b/lib/filestorage/commontest.php @@ -51,11 +51,11 @@ class OC_Filestorage_CommonTest extends OC_Filestorage_Common{ public function filetype($path){ return $this->storage->filetype($path); } - public function is_readable($path){ - return $this->storage->is_readable($path); + public function isReadable($path){ + return $this->storage->isReadable($path); } - public function is_writable($path){ - return $this->storage->is_writable($path); + public function isUpdatable($path){ + return $this->storage->isUpdatable($path); } public function file_exists($path){ return $this->storage->file_exists($path); diff --git a/tests/lib/filestorage.php b/tests/lib/filestorage.php index 00f37b9f1a2..4120df18de6 100644 --- a/tests/lib/filestorage.php +++ b/tests/lib/filestorage.php @@ -31,13 +31,13 @@ abstract class Test_FileStorage extends UnitTestCase { */ public function testRoot(){ $this->assertTrue($this->instance->file_exists('/'),'Root folder does not exist'); - $this->assertTrue($this->instance->is_readable('/'),'Root folder is not readable'); + $this->assertTrue($this->instance->isReadable('/'),'Root folder is not readable'); $this->assertTrue($this->instance->is_dir('/'),'Root folder is not a directory'); $this->assertFalse($this->instance->is_file('/'),'Root folder is a file'); $this->assertEqual('dir',$this->instance->filetype('/')); //without this, any further testing would be useless, not an acutal requirement for filestorage though - $this->assertTrue($this->instance->is_writable('/'),'Root folder is not writable'); + $this->assertTrue($this->instance->isUpdatable('/'),'Root folder is not writable'); } public function testDirectories(){ @@ -50,8 +50,8 @@ abstract class Test_FileStorage extends UnitTestCase { $this->assertFalse($this->instance->is_file('/folder')); $this->assertEqual('dir',$this->instance->filetype('/folder')); $this->assertEqual(0,$this->instance->filesize('/folder')); - $this->assertTrue($this->instance->is_readable('/folder')); - $this->assertTrue($this->instance->is_writable('/folder')); + $this->assertTrue($this->instance->isReadable('/folder')); + $this->assertTrue($this->instance->isUpdatable('/folder')); $dh=$this->instance->opendir('/'); $content=array(); @@ -141,7 +141,7 @@ abstract class Test_FileStorage extends UnitTestCase { $textFile=OC::$SERVERROOT.'/tests/data/lorem.txt'; $ctimeStart=time(); $this->instance->file_put_contents('/lorem.txt',file_get_contents($textFile)); - $this->assertTrue($this->instance->is_readable('/lorem.txt')); + $this->assertTrue($this->instance->isReadable('/lorem.txt')); $ctimeEnd=time(); $cTime=$this->instance->filectime('/lorem.txt'); $mTime=$this->instance->filemtime('/lorem.txt'); diff --git a/tests/lib/share/backend.php b/tests/lib/share/backend.php index 4f2fcce235e..9fe625a1fa3 100644 --- a/tests/lib/share/backend.php +++ b/tests/lib/share/backend.php @@ -19,48 +19,49 @@ * License along with this library. If not, see . */ -abstract class Test_Share_Backend extends UnitTestCase { +class Test_Share_Backend implements OCP\Share_Backend { - protected $userBackend; - protected $user1; - protected $user2; - protected $groupBackend; - protected $group; - protected $itemType; - protected $item; + const FORMAT_SOURCE = 0; + const FORMAT_TARGET = 1; + const FORMAT_PERMISSIONS = 2; + + private $testItem = 'test.txt'; - public function setUp() { - OC_User::clearBackends(); - OC_User::useBackend('dummy'); - $this->user1 = uniqid('user_'); - $this->user2 = uniqid('user_'); - OC_User::createUser($this->user1, 'pass1'); - OC_User::createUser($this->user2, 'pass2'); - OC_Group::clearBackends(); - OC_Group::useBackend(new OC_Group_Dummy); - $this->group = uniqid('group_'); - OC_Group::createGroup($this->group); + public function isValidSource($itemSource, $uidOwner) { + if ($itemSource == $this->testItem) { + return true; + } } - public function testShareWithUserNonExistentItem() { - $this->assertFalse(OCP\Share::share($this->itemType, uniqid('foobar_'), OCP\Share::SHARETYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + public function generateTarget($itemSource, $shareWith, $exclude = null) { + $target = $itemSource; + if (isset($exclude)) { + $pos = strrpos($target, '.'); + $name = substr($target, 0, $pos); + $ext = substr($target, $pos); + $append = ''; + $i = 1; + while (in_array($name.$append.$ext, $exclude)) { + $append = $i; + $i++; + } + $target = $name.$append.$ext; + } + return $target; } - public function testShareWithUserItem() { - $this->assertTrue(OCP\Share::share($this->itemType, $this->item, OCP\Share::SHARETYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); - } - - public function testShareWithGroupNonExistentItem() { - $this->assertFalse(OCP\Share::share($this->itemType, uniqid('foobar_'), OCP\Share::SHARETYPE_GROUP, $this->group, OCP\Share::PERMISSION_READ)); - } - - public function testShareWithGroupItem() { - $this->assertTrue(OCP\Share::share($this->itemType, $this->item, OCP\Share::SHARETYPE_GROUP, $this->group, OCP\Share::PERMISSION_READ)); - } - - public function testShareWithUserAlreadySharedWith() { - $this->assertTrue(OCP\Share::share($this->itemType, $this->item, OCP\Share::SHARETYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); - $this->assertFalse(OCP\Share::share($this->itemType, $this->item, OCP\Share::SHARETYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + public function formatItems($items, $format, $parameters = null) { + $testItems = array(); + foreach ($items as $item) { + if ($format == self::FORMAT_SOURCE) { + $testItems[] = $item['item_source']; + } else if ($format == self::FORMAT_TARGET) { + $testItems[] = $item['item_target']; + } else if ($format == self::FORMAT_PERMISSIONS) { + $testItems[] = $item['permissions']; + } + } + return $testItems; } } diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index eca2c9bc58a..4b73cc183a3 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -19,7 +19,7 @@ * License along with this library. If not, see . */ -class Test_Share_Base extends UnitTestCase { +class Test_Share extends UnitTestCase { protected $itemType; protected $userBackend; @@ -35,127 +35,251 @@ class Test_Share_Base extends UnitTestCase { OC_User::useBackend('dummy'); $this->user1 = uniqid('user_'); $this->user2 = uniqid('user_'); - OC_User::createUser($this->user1, 'pass1'); - OC_User::createUser($this->user2, 'pass2'); + $this->user3 = uniqid('user_'); + OC_User::createUser($this->user1, 'pass'); + OC_User::createUser($this->user2, 'pass'); + OC_User::createUser($this->user3, 'pass'); + OC_User::setUserId($this->user1); OC_Group::clearBackends(); OC_Group::useBackend(new OC_Group_Dummy); $this->group1 = uniqid('group_'); $this->group2 = uniqid('group_'); OC_Group::createGroup($this->group1); OC_Group::createGroup($this->group2); + OC_Group::addToGroup($this->user1, $this->group1); + OC_Group::addToGroup($this->user2, $this->group1); + OC_Group::addToGroup($this->user3, $this->group1); + OCP\Share::registerBackend('test', 'Test_Share_Backend'); } - public function testShareInvalidShareType() { - $this->assertFalse(OCP\Share::share('file', 'test.txt', 'foobar', $this->user1, OCP\Share::PERMISSION_READ)); + public function tearDown() { + $query = OC_DB::prepare('DELETE FROM *PREFIX*share WHERE item_type = ?'); + $query->execute(array('test')); } - public function testShareInvalidItemType() { - $this->assertFalse(OCP\Share::share('foobar', 'test.txt', OCP\Share::SHARETYPE_USER, $this->user1, OCP\Share::PERMISSION_READ)); - } - - public function testShareWithSelf() { - OC_User::setUserId($this->user1); - $this->assertFalse(OCP\Share::share('file', 'test.txt', OCP\Share::SHARETYPE_USER, $this->user1, OCP\Share::PERMISSION_READ)); + public function testShareInvalidShareType() { + $this->expectException(new Exception('Share type foobar is not valid for test.txt')); + OCP\Share::shareItem('test', 'test.txt', 'foobar', $this->user2, OCP\Share::PERMISSION_READ); + } - public function testShareWithNonExistentUser() { - $this->assertFalse(OCP\Share::share('file', 'test.txt', OCP\Share::SHARETYPE_USER, 'foobar', OCP\Share::PERMISSION_READ)); + public function testInvalidItemType() { + $message = 'Sharing backend for foobar not found'; + try { + OCP\Share::shareItem('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::shareItem('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::getItemsSharedWith('foobar'); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::getItemSharedWith('foobar', 'test.txt'); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::getItemSharedWithBySource('foobar', 'test.txt'); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::getItemShared('foobar', 'test.txt'); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::unshare('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + try { + OCP\Share::setPermissions('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_UPDATE); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } } - public function testShareWithUserOwnerNotPartOfGroup() { + public function testShareWithUser() { + // Invalid shares + $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the item owner'; + try { + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + $message = 'Sharing test.txt failed, because the user foobar does not exist'; + try { + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, 'foobar', OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } - } - - public function testShareWithUserAlreadySharedWith() { + // Valid share + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + $this->assertEqual(OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); - } - - public function testShareWithNonExistentGroup() { - $this->assertFalse(OCP\Share::share('file', 'test.txt', OCP\Share::SHARETYPE_GROUP, 'foobar', OCP\Share::PERMISSION_READ)); - } - - public function testShareWithGroupOwnerNotPartOfGroup() { - - } - - - public function testShareWithGroupItem() { - - } - - public function testUnshareInvalidShareType() { - - } - - public function testUnshareNonExistentItem() { - - } - - public function testUnshareFromUserItem() { - - } - - public function testUnshareFromGroupItem() { - - } - - - - - - // Test owner not in same group (false) - + // Attempt to share again + OC_User::setUserId($this->user1); + $message = 'Sharing test.txt failed, because this item is already shared with '.$this->user2; + try { + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } - - // Test non-existant item type - - // Test valid item - - // Test existing shared item (false) + // Invalid item + $message = 'Sharing foobar failed, because the sharing backend for test could not find its source'; + try { + OCP\Share::shareItem('test', 'foobar', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } - // Test unsharing item - - // Test setting permissions - - // Test setting permissions not as owner (false) - - // Test setting target - - // Test setting target as owner (false) + // Attempt reshare without share permission + OC_User::setUserId($this->user2); + $message = 'Sharing test.txt failed, because resharing is not allowed'; + try { + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } - // Spam reshares - + // Owner grants share and update permission + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_SHARE)); - - // Test non-existant group + // Attempt reshare with escalated permissions + OC_User::setUserId($this->user2); + $message = 'Sharing test.txt failed, because the permissions exceed permissions granted to '.$this->user2; + try { + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } - - // Test owner not part of group - - // Test existing shared item with group - - // Test valid item, valid name for all users - - // Test unsharing item - - // Test item with name conflicts - - // Test unsharing item - - // Test setting permissions - - // Test setting target no name conflicts - - // Test setting target with conflicts - - // Spam reshares - + // Valid reshare + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE)); + $this->assertEqual(OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + OC_User::setUserId($this->user3); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE)); - + // Attempt to escalate permissions + OC_User::setUserId($this->user2); + $message = 'Setting permissions for test.txt failed, because the permissions exceed permissions granted to '.$this->user2; + try { + OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + // Remove update permission + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); + OC_User::setUserId($this->user3); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ)); + + // Remove share permission + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user3); + $this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt')); + + // Reshare again, and then have owner unshare + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); + OC_User::setUserId($this->user2); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2)); + OC_User::setUserId($this->user2); + $this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt')); + OC_User::setUserId($this->user3); + $this->assertFalse(OCP\Share::getItemSharedWith('test', 'test.txt')); + + // Attempt target conflict + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user3); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt')); + } - public function testPrivateLink() { + public function testShareWithGroup() { + // Invalid shares + $message = 'Sharing test.txt failed, because the group foobar does not exist'; + try { + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, 'foobar', OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + $message = 'Sharing test.txt failed, because '.$this->user1.' is not a member of the group '.$this->group2; + try { + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group2, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Valid share + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ)); + $this->assertEqual(OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + OC_User::setUserId($this->user3); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); + + // Attempt to share again + OC_User::setUserId($this->user1); + $message = 'Sharing test.txt failed, because this item is already shared with '.$this->group1; + try { + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Unshare + $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1)); + // Attempt user specific target conflict + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt')); + OC_User::setUserId($this->user3); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); } } -- cgit v1.2.3 From df8a2e5361714838637457373f9957c76fbf449f Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 16 Aug 2012 12:20:14 -0400 Subject: File sharing cleanup, works perfectly I think :) --- apps/files_sharing/lib/share/file.php | 91 ++++++++++++++------------------- apps/files_sharing/lib/share/folder.php | 73 ++++++++++---------------- apps/files_sharing/sharedstorage.php | 26 +++++----- core/js/share.js | 1 - lib/files.php | 4 +- lib/public/share.php | 29 ++++++++--- tests/lib/share/share.php | 8 +++ 7 files changed, 111 insertions(+), 121 deletions(-) (limited to 'tests') diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php index 66be5f2b155..ae6315600f8 100644 --- a/apps/files_sharing/lib/share/file.php +++ b/apps/files_sharing/lib/share/file.php @@ -27,10 +27,10 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { const FORMAT_OPENDIR = 3; public function isValidSource($item, $uid) { -// if (OC_Filesystem::file_exists($item)) { + if (OC_Filesystem::file_exists($item)) { return true; -// } -// return false; + } + return false; } public function getFilePath($item, $uid) { @@ -43,61 +43,48 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { } public function formatItems($items, $format, $parameters = null) { - if ($format == self::FORMAT_OPENDIR) { + if ($format == self::FORMAT_SHARED_STORAGE) { + // Only 1 item should come through for this format call + return array('path' => $items[key($items)]['file_source'], 'permissions' => $items[key($items)]['permissions']); + } else if ($format == self::FORMAT_FILE_APP) { $files = array(); - foreach ($items as $file) { - $files[] = basename($file['file_target']); + foreach ($items as $item) { + $file = array(); + $file['path'] = $item['file_target']; + $file['name'] = basename($item['file_target']); + $file['ctime'] = $item['ctime']; + $file['mtime'] = $item['mtime']; + $file['mimetype'] = $item['mimetype']; + $file['size'] = $item['size']; + $file['encrypted'] = $item['encrypted']; + $file['versioned'] = $item['versioned']; + $file['directory'] = $parameters['folder']; + $file['type'] = ($item['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file'; + $file['permissions'] = $item['permissions']; + if ($file['type'] == 'file') { + // Remove Create permission if type is file + $file['permissions'] &= ~OCP\Share::PERMISSION_CREATE; + } + $files[] = $file; } return $files; - } else if ($format == self::FORMAT_SHARED_STORAGE) { - $id = $items[key($items)]['file_source']; - $query = OCP\DB::prepare('SELECT path FROM *PREFIX*fscache WHERE id = ?'); - $result = $query->execute(array($id))->fetchAll(); - if (isset($result[0]['path'])) { - return array('path' => $result[0]['path'], 'permissions' => $items[key($items)]['permissions']); - } - return false; - } else { - $shares = array(); - $ids = array(); + } else if ($format == self::FORMAT_FILE_APP_ROOT) { + $mtime = 0; + $size = 0; foreach ($items as $item) { - $shares[$item['file_source']] = $item; - $ids[] = $item['file_source']; - } - $ids = "'".implode("','", $ids)."'"; - if ($format == self::FORMAT_FILE_APP) { - $query = OCP\DB::prepare('SELECT id, path, name, ctime, mtime, mimetype, size, encrypted, versioned, writable FROM *PREFIX*fscache WHERE id IN ('.$ids.')'); - $result = $query->execute(); - $files = array(); - while ($file = $result->fetchRow()) { - // Set target path - $file['path'] = $shares[$file['id']]['file_target']; - $file['name'] = basename($file['path']); - $file['directory'] = $parameters['folder']; - $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file'; - $permissions = $shares[$file['id']]['permissions']; - if ($file['type'] == 'file') { - // Remove Create permission if type is file - $permissions &= ~OCP\Share::PERMISSION_CREATE; - } - $file['permissions'] = $permissions; - $files[] = $file; - } - return $files; - } else if ($format == self::FORMAT_FILE_APP_ROOT) { - $query = OCP\DB::prepare('SELECT id, path, name, ctime, mtime, mimetype, size, encrypted, versioned, writable FROM *PREFIX*fscache WHERE id IN ('.$ids.')'); - $result = $query->execute(); - $mtime = 0; - $size = 0; - while ($file = $result->fetchRow()) { - if ($file['mtime'] > $mtime) { - $mtime = $file['mtime']; - } - $size += $file['size']; + if ($item['mtime'] > $mtime) { + $mtime = $item['mtime']; } - return array(0 => array('name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size, 'writable' => false, 'type' => 'dir', 'directory' => '', 'permissions' => OCP\Share::PERMISSION_READ)); + $size += $item['size']; } - } + return array(0 => array('name' => 'Shared', 'mtime' => $mtime, 'mimetype' => 'httpd/unix-directory', 'size' => $size, 'writable' => false, 'type' => 'dir', 'directory' => '', 'permissions' => OCP\Share::PERMISSION_READ)); + } else if ($format == self::FORMAT_OPENDIR) { + $files = array(); + foreach ($items as $item) { + $files[] = basename($item['file_target']); + } + return $files; + } return array(); } diff --git a/apps/files_sharing/lib/share/folder.php b/apps/files_sharing/lib/share/folder.php index 2f101d33c8a..b6db96614fd 100644 --- a/apps/files_sharing/lib/share/folder.php +++ b/apps/files_sharing/lib/share/folder.php @@ -21,8 +21,32 @@ class OC_Share_Backend_Folder extends OC_Share_Backend_File { - public function inCollection($collections, $item) { - // TODO + public function formatItems($items, $format, $parameters = null) { + if ($format == self::FORMAT_SHARED_STORAGE) { + // Only 1 item should come through for this format call + return array('path' => $items[key($items)]['file_source'], 'permissions' => $items[key($items)]['permissions']); + } else if ($format == self::FORMAT_FILE_APP && isset($parameters['folder'])) { + // Only 1 item should come through for this format call + $folder = $items[key($items)]; + if (isset($parameters['mimetype_filter'])) { + $mimetype_filter = $parameters['mimetype_filter']; + } else { + $mimetype_filter = ''; + } + $path = $folder['file_source'].substr($parameters['folder'], 7 + strlen($folder['file_target'])); + $files = OC_FileCache::getFolderContent($path, '', $mimetype_filter); + foreach ($files as &$file) { + $file['directory'] = $parameters['folder']; + $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file'; + $file['permissions'] = $folder['permissions']; + if ($file['type'] == 'file') { + // Remove Create permission if type is file + $file['permissions'] &= ~OCP\Share::PERMISSION_CREATE; + } + } + return $files; + } + return array(); } public function getChildren($itemSource) { @@ -34,47 +58,4 @@ class OC_Share_Backend_Folder extends OC_Share_Backend_File { return $sources; } - public function formatItems($items, $format, $parameters = null) { - if ($format == self::FORMAT_FILE_APP && isset($parameters['folder'])) { - $folder = $items[key($items)]; - $query = OCP\DB::prepare('SELECT path FROM *PREFIX*fscache WHERE id = ?'); - $result = $query->execute(array($folder['file_source']))->fetchRow(); - if (isset($result['path'])) { - if (isset($parameters['mimetype_filter'])) { - $mimetype_filter = $parameters['mimetype_filter']; - } else { - $mimetype_filter = ''; - } - $pos = strpos($result['path'], $folder['item']); - $path = substr($result['path'], $pos).substr($parameters['folder'], strlen($folder['file_target'])); - $root = substr($result['path'], 0, $pos); - $files = OC_FileCache::getFolderContent($path, $root, $mimetype_filter); - foreach ($files as &$file) { - $file['directory'] = $parameters['folder']; - $file['type'] = ($file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file'; - $permissions = $folder['permissions']; - if ($file['type'] == 'file') { - // Remove Create permission if type is file - $permissions &= ~OCP\Share::PERMISSION_CREATE; - } - $file['permissions'] = $permissions; - } - return $files; - } - }/* else if ($format == self::FORMAT_OPENDIR_ROOT) { - $query = OCP\DB::prepare('SELECT name FROM *PREFIX*fscache WHERE id IN ('.$ids.')'); - $result = $query->execute(); - $files = array(); - while ($file = $result->fetchRow()) { - // Set target path - $files[] = basename($shares[$file['id']]['item_target']); - } - return $files; - }*/ - return array(); - } - -} - - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index fc2e6e32c7c..582c9c66172 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -50,7 +50,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { if (isset($this->files[$folder])) { $file = $this->files[$folder]; } else { - $file = OCP\Share::getItemSharedWith('file', $folder, OC_Share_Backend_File::FORMAT_SHARED_STORAGE); + $file = OCP\Share::getItemSharedWith('folder', $folder, OC_Share_Backend_File::FORMAT_SHARED_STORAGE); } if ($file) { $this->files[$target]['path'] = $file['path'].substr($target, strlen($folder)); @@ -285,19 +285,21 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { } public function file_put_contents($path, $data) { - if ($this->is_writable($path)) { - $source = $this->getSourcePath($path); - if ($source) { - $info = array( - 'target' => $this->sharedFolder.$path, - 'source' => $source, - ); - OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info); - $storage = OC_Filesystem::getStorage($source); - $result = $storage->file_put_contents($this->getInternalPath($source), $data); - return $result; + if ($source = $this->getSourcePath($path)) { + // Check if permission is granted + if (($this->file_exists($path) && !$this->isUpdatable($path)) || ($this->is_dir($path) && !$this->isCreatable($path))) { + return false; } + $info = array( + 'target' => $this->sharedFolder.$path, + 'source' => $source, + ); + OCP\Util::emitHook('OC_Filestorage_Shared', 'file_put_contents', $info); + $storage = OC_Filesystem::getStorage($source); + $result = $storage->file_put_contents($this->getInternalPath($source), $data); + return $result; } + return false; } public function unlink($path) { diff --git a/core/js/share.js b/core/js/share.js index 70d822f8814..38c20a75709 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -267,7 +267,6 @@ $(document).ready(function() { if (typeof FileActions !== 'undefined') { OC.Share.loadIcons('file'); - OC.Share.loadIcons('folder'); FileActions.register('all', 'Share', FileActions.PERMISSION_SHARE, function(filename) { // Return the correct sharing icon if (scanFiles.scanning) { return; } // workaround to prevent additional http request block scanning feedback diff --git a/lib/files.php b/lib/files.php index fee71b777b3..07d432f8066 100644 --- a/lib/files.php +++ b/lib/files.php @@ -41,9 +41,9 @@ class OC_Files { $pos = strpos($directory, '/', 8); // Get shared folder name if ($pos !== false) { - $itemTarget = substr($directory, 0, $pos); + $itemTarget = substr($directory, 7, $pos - 7); } else { - $itemTarget = $directory; + $itemTarget = substr($directory, 7); } $files = OCP\Share::getItemSharedWith('folder', $itemTarget, OC_Share_Backend_File::FORMAT_FILE_APP, array('folder' => $directory, 'mimetype_filter' => $mimetype_filter)); } diff --git a/lib/public/share.php b/lib/public/share.php index c420943da26..940bf2d48a0 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -399,23 +399,28 @@ class Share { */ private static function getItems($itemType, $item = null, $shareType = null, $shareWith = null, $uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, $includeCollections = false, $itemShareWithBySource = false) { $backend = self::getBackend($itemType); - // Get filesystem root to add it to the file target and remove from the file source + // Get filesystem root to add it to the file target and remove from the file source, match file_source with the file cache if ($backend instanceof Share_Backend_File_Dependent) { + $fileDependent = true; $root = \OC_Filesystem::getRoot(); + // TODO No need to do this for FORMAT_STATUSES and loading the item in the dropdown, it's a performance waste + $where = 'INNER JOIN *PREFIX*fscache ON file_source = *PREFIX*fscache.id '; } else { + $fileDependent = false; + $where = ''; $root = ''; } if ($itemType == 'file' && !isset($item)) { - $where = 'WHERE file_target IS NOT NULL'; + $where .= 'WHERE file_target IS NOT NULL'; $query_args = array(); } else if ($includeCollections && !isset($item) && $collectionTypes = self::getCollectionItemTypes($itemType)) { // If includeCollections is true, find collections of this item type, e.g. a music album contains songs $item_types = array_merge(array($itemType), $collectionTypes); $placeholders = join(',', array_fill(0, count($item_types), '?')); - $where = "WHERE item_type IN ('".$placeholders."')"; + $where .= "WHERE item_type IN ('".$placeholders."')"; $query_args = $item_types; - } else { - $where = "WHERE item_type = ?"; + } else if ($itemType != 'file' && $itemType != 'folder') { + $where .= "WHERE item_type = ?"; $query_args = array($itemType); } if (isset($shareType) && isset($shareWith)) { @@ -445,7 +450,6 @@ class Share { $query_args[] = self::$shareTypeGroupUserUnique; } if ($itemType == 'file' || $itemType == 'folder') { - $where = "INNER JOIN *PREFIX*fscache ON file_source = *PREFIX*fscache.id ".$where; $column = 'file_source'; } else { $column = 'item_source'; @@ -491,6 +495,7 @@ class Share { } $where .= ' LIMIT '.$limit; } + // TODO Optimize selects if ($format == self::FORMAT_STATUSES) { if ($itemType == 'file' || $itemType == 'folder') { $select = '*PREFIX*share.id, item_type, *PREFIX*share.parent, share_type, *PREFIX*fscache.path as file_source'; @@ -505,7 +510,15 @@ class Share { $select = 'id, item_type, item_source, parent, share_type, share_with, permissions, stime, file_source'; } } else { - $select = '*'; + if ($fileDependent) { + if (($itemType == 'file' || $itemType == 'folder') && $format == \OC_Share_Backend_File::FORMAT_FILE_APP || $format == \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT) { + $select = '*PREFIX*share.id, item_type, *PREFIX*share.parent, share_type, share_with, permissions, file_target, *PREFIX*fscache.id, path as file_source, name, ctime, mtime, mimetype, size, encrypted, versioned, writable'; + } else { + $select = '*PREFIX*share.id, item_type, item_source, item_target, *PREFIX*share.parent, share_type, share_with, permissions, stime, path as file_source, file_target'; + } + } else { + $select = '*'; + } } } $root = strlen($root); @@ -534,7 +547,7 @@ class Share { // TODO Check this outside of the loop // Check if this is a collection of the requested item type if ($row['item_type'] != $itemType && $itemType != 'file' && !isset($item)) { - if ($collectionBackend = self::getBackend($row['item_type'])) { + if ($collectionBackend = self::getBackend($row['item_type'] && $collectionBackend instanceof Share_Backend_Collection)) { $row['collection'] = array('item_type' => $itemType, $column => $row[$column]); // Fetch all of the children sources $children = $collectionBackend->getChildren($row[$column]); diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index 4b73cc183a3..efff2c5522c 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -233,6 +233,8 @@ class Test_Share extends UnitTestCase { $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); OC_User::setUserId($this->user2); $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt')); + + // Remove user } public function testShareWithGroup() { @@ -280,6 +282,12 @@ class Test_Share extends UnitTestCase { $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt')); OC_User::setUserId($this->user3); $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + + // Remove user from group + + // Add user to group + + // Remove group } } -- cgit v1.2.3 From 53a888cc8130a81961dece245b35a226be4d67ab Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 17 Aug 2012 01:22:26 +0200 Subject: more path normalization --- apps/files/index.php | 2 +- lib/files.php | 4 ++ lib/filesystem.php | 13 +++++- lib/filesystemview.php | 118 +++++++++++++++++++++++++---------------------- tests/lib/filesystem.php | 1 + 5 files changed, 80 insertions(+), 58 deletions(-) (limited to 'tests') diff --git a/apps/files/index.php b/apps/files/index.php index 79bed8e357e..e1c4ad7f19b 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -92,7 +92,7 @@ $maxUploadFilesize = min($maxUploadFilesize ,$freeSpace); $tmpl = new OCP\Template( 'files', 'index', 'user' ); $tmpl->assign( 'fileList', $list->fetchPage(), false ); $tmpl->assign( 'breadcrumb', $breadcrumbNav->fetchPage(), false ); -$tmpl->assign( 'dir', $dir); +$tmpl->assign( 'dir', OC_Filesystem::normalizePath($dir)); $tmpl->assign( 'readonly', !OC_Filesystem::is_writable($dir.'/')); $tmpl->assign( 'files', $files ); $tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize); diff --git a/lib/files.php b/lib/files.php index d5bebb7e549..b9c2ead9443 100644 --- a/lib/files.php +++ b/lib/files.php @@ -33,6 +33,10 @@ class OC_Files { * @param dir $directory path under datadirectory */ public static function getDirectoryContent($directory, $mimetype_filter = ''){ + $directory=OC_Filesystem::normalizePath($directory); + if($directory=='/'){ + $directory=''; + } $files=OC_FileCache::getFolderContent($directory, false, $mimetype_filter); foreach($files as &$file){ $file['directory']=$directory; diff --git a/lib/filesystem.php b/lib/filesystem.php index 6cba6b1b547..ffb8643d491 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -495,7 +495,16 @@ class OC_Filesystem{ OC_Connector_Sabre_Node::removeETagPropertyForPath($path); } - public static function normalizePath($path){ + /** + * normalize a path + * @param string path + * @param bool $stripTrailingSlash + * @return string + */ + public static function normalizePath($path,$stripTrailingSlash=true){ + if($path==''){ + return '/'; + } //no windows style slashes $path=str_replace('\\','/',$path); //add leading slash @@ -503,7 +512,7 @@ class OC_Filesystem{ $path='/'.$path; } //remove trainling slash - if(strlen($path)>1 and substr($path,-1,1)==='/'){ + if($stripTrailingSlash and strlen($path)>1 and substr($path,-1,1)==='/'){ $path=substr($path,0,-1); } //remove duplicate slashes diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 9d85befdc8c..571c75f8f31 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -54,7 +54,7 @@ class OC_FilesystemView { if($path[0]!=='/'){ $path='/'.$path; } - return OC_Filesystem::normalizePath($this->fakeRoot.$path); + return $this->fakeRoot.$path; } /** @@ -227,7 +227,7 @@ class OC_FilesystemView { } public function file_put_contents($path, $data) { if(is_resource($data)) {//not having to deal with streams in file_put_contents makes life easier - $absolutePath = $this->getAbsolutePath($path); + $absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path)); if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && OC_Filesystem::isValidPath($path)) { $path = $this->getRelativePath($absolutePath); $exists = $this->file_exists($path); @@ -287,11 +287,14 @@ class OC_FilesystemView { return $this->basicOperation( 'deleteAll', $directory, array('delete'), $empty ); } public function rename($path1, $path2) { - $absolutePath1 = $this->getAbsolutePath($path1); - $absolutePath2 = $this->getAbsolutePath($path2); + $postFix1=(substr($path1,-1,1)==='/')?'/':''; + $postFix2=(substr($path2,-1,1)==='/')?'/':''; + $absolutePath1 = OC_Filesystem::normalizePath($this->getAbsolutePath($path1)); + $absolutePath2 = OC_Filesystem::normalizePath($this->getAbsolutePath($path2)); if(OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) { $path1 = $this->getRelativePath($absolutePath1); $path2 = $this->getRelativePath($absolutePath2); + if($path1 == null or $path2 == null) { return false; } @@ -305,20 +308,20 @@ class OC_FilesystemView { ) ); if($run) { - $mp1 = $this->getMountPoint($path1); - $mp2 = $this->getMountPoint($path2); + $mp1 = $this->getMountPoint($path1.$postFix1); + $mp2 = $this->getMountPoint($path2.$postFix2); if($mp1 == $mp2) { if($storage = $this->getStorage($path1)) { - $result = $storage->rename($this->getInternalPath($path1), $this->getInternalPath($path2)); + $result = $storage->rename($this->getInternalPath($path1.$postFix1), $this->getInternalPath($path2.$postFix2)); } } else { - $source = $this->fopen($path1, 'r'); - $target = $this->fopen($path2, 'w'); + $source = $this->fopen($path1.$postFix1, 'r'); + $target = $this->fopen($path2.$postFix2, 'w'); $count = OC_Helper::streamCopy($source, $target); $storage1 = $this->getStorage($path1); - $storage1->unlink($this->getInternalPath($path1)); + $storage1->unlink($this->getInternalPath($path1.$postFix1)); $result = $count>0; - } + } OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_rename, @@ -332,11 +335,14 @@ class OC_FilesystemView { } } public function copy($path1, $path2) { - $absolutePath1 = $this->getAbsolutePath($path1); - $absolutePath2 = $this->getAbsolutePath($path2); + $postFix1=(substr($path1,-1,1)==='/')?'/':''; + $postFix2=(substr($path2,-1,1)==='/')?'/':''; + $absolutePath1 = OC_Filesystem::normalizePath($this->getAbsolutePath($path1)); + $absolutePath2 = OC_Filesystem::normalizePath($this->getAbsolutePath($path2)); if(OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) { $path1 = $this->getRelativePath($absolutePath1); $path2 = $this->getRelativePath($absolutePath2); + if($path1 == null or $path2 == null) { return false; } @@ -372,15 +378,15 @@ class OC_FilesystemView { ); } if($run) { - $mp1=$this->getMountPoint($path1); - $mp2=$this->getMountPoint($path2); + $mp1=$this->getMountPoint($path1.$postFix1); + $mp2=$this->getMountPoint($path2.$postFix2); if($mp1 == $mp2){ - if($storage = $this->getStorage($path1)) { - $result=$storage->copy($this->getInternalPath($path1), $this->getInternalPath($path2)); + if($storage = $this->getStorage($path1.$postFix1)) { + $result=$storage->copy($this->getInternalPath($path1.$postFix1), $this->getInternalPath($path2.$postFix2)); } } else { - $source = $this->fopen($path1, 'r'); - $target = $this->fopen($path2, 'w'); + $source = $this->fopen($path1.$postFix1, 'r'); + $target = $this->fopen($path2.$postFix2, 'w'); $result = OC_Helper::streamCopy($source, $target); } OC_Hook::emit( @@ -475,7 +481,8 @@ class OC_FilesystemView { return $this->basicOperation('getMimeType', $path); } public function hash($type, $path, $raw = false) { - $absolutePath = $this->getAbsolutePath($path); + $postFix=(substr($path,-1,1)==='/')?'/':''; + $absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path)); if (OC_FileProxy::runPreProxies('hash', $absolutePath) && OC_Filesystem::isValidPath($path)) { $path = $this->getRelativePath($absolutePath); if ($path == null) { @@ -488,8 +495,8 @@ class OC_FilesystemView { array( OC_Filesystem::signal_param_path => $path) ); } - if ($storage = $this->getStorage($path)) { - $result = $storage->hash($type, $this->getInternalPath($path), $raw); + if ($storage = $this->getStorage($path.$postFix)) { + $result = $storage->hash($type, $this->getInternalPath($path.$postFix), $raw); $result = OC_FileProxy::runPostProxies('hash', $absolutePath, $result); return $result; } @@ -514,35 +521,16 @@ class OC_FilesystemView { * OC_Filestorage for delegation to a storage backend for execution */ private function basicOperation($operation, $path, $hooks=array(), $extraParam=null) { - $absolutePath = $this->getAbsolutePath($path); + $postFix=(substr($path,-1,1)==='/')?'/':''; + $absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path)); if(OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)) { $path = $this->getRelativePath($absolutePath); if($path == null) { return false; } - $internalPath = $this->getInternalPath($path); - $run = true; - if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()) { - foreach($hooks as $hook) { - if($hook!='read') { - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - $hook, - array( - OC_Filesystem::signal_param_path => $path, - OC_Filesystem::signal_param_run => &$run - ) - ); - } else { - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - $hook, - array( OC_Filesystem::signal_param_path => $path) - ); - } - } - } - if($run and $storage = $this->getStorage($path)) { + $internalPath = $this->getInternalPath($path.$postFix); + $run=$this->runHooks($hooks,$path); + if($run and $storage = $this->getStorage($path.$postFix)) { if(!is_null($extraParam)) { $result = $storage->$operation($internalPath, $extraParam); } else { @@ -551,15 +539,7 @@ class OC_FilesystemView { $result = OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result); if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()) { if($operation!='fopen') {//no post hooks for fopen, the file stream is still open - foreach($hooks as $hook) { - if($hook!='read'){ - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - 'post_'.$hook, - array( OC_Filesystem::signal_param_path => $path) - ); - } - } + $this->runHooks($hooks,$path,true); } } return $result; @@ -568,6 +548,34 @@ class OC_FilesystemView { return null; } + private function runHooks($hooks,$path,$post=false){ + $prefix=($post)?'post_':''; + $run=true; + if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()) { + foreach($hooks as $hook) { + if($hook!='read') { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + $prefix.$hook, + array( + OC_Filesystem::signal_param_run => &$run, + OC_Filesystem::signal_param_path => $path + ) + ); + } elseif(!$post) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + $prefix.$hook, + array( + OC_Filesystem::signal_param_path => $path + ) + ); + } + } + } + return $run; + } + /** * check if a file or folder has been updated since $time * @param int $time diff --git a/tests/lib/filesystem.php b/tests/lib/filesystem.php index e041255ec91..72af0835788 100644 --- a/tests/lib/filesystem.php +++ b/tests/lib/filesystem.php @@ -62,6 +62,7 @@ class Test_Filesystem extends UnitTestCase{ public function testNormalize(){ $this->assertEqual('/path',OC_Filesystem::normalizePath('/path/')); + $this->assertEqual('/path/',OC_Filesystem::normalizePath('/path/',false)); $this->assertEqual('/path',OC_Filesystem::normalizePath('path')); $this->assertEqual('/path',OC_Filesystem::normalizePath('\path')); $this->assertEqual('/foo/bar',OC_Filesystem::normalizePath('/foo//bar/')); -- cgit v1.2.3 From d54390b1a0e7b36ef9b806e7b61f5ff9f85d190d Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Sat, 18 Aug 2012 13:56:04 +0200 Subject: Optimized image size --- apps/bookmarks/img/bookmarks.png | Bin 496 -> 398 bytes apps/calendar/img/icon.png | Bin 423 -> 360 bytes apps/contacts/img/contact-new.png | Bin 658 -> 525 bytes apps/contacts/img/person.png | Bin 978 -> 852 bytes apps/contacts/img/person_large.png | Bin 7929 -> 6993 bytes apps/external/img/external.png | Bin 459 -> 412 bytes apps/files_imageviewer/img/fancybox-y.png | Bin 176 -> 166 bytes apps/gallery/img/breadcrumb.png | Bin 220 -> 201 bytes apps/gallery/img/delete.png | Bin 275 -> 240 bytes apps/gallery/img/rename.png | Bin 310 -> 267 bytes apps/gallery/img/share.png | Bin 377 -> 338 bytes apps/gallery/img/supersized/back.png | Bin 2629 -> 2319 bytes apps/gallery/img/supersized/bg-black.png | Bin 1074 -> 1065 bytes apps/gallery/img/supersized/button-tray-down.png | Bin 1506 -> 1464 bytes apps/gallery/img/supersized/button-tray-up.png | Bin 1466 -> 1451 bytes apps/gallery/img/supersized/forward.png | Bin 2614 -> 2316 bytes apps/gallery/img/supersized/nav-bg.png | Bin 995 -> 993 bytes apps/gallery/img/supersized/nav-dot.png | Bin 1901 -> 1640 bytes apps/gallery/img/supersized/pause.png | Bin 1131 -> 1124 bytes apps/gallery/img/supersized/play.png | Bin 1562 -> 1549 bytes apps/gallery/img/supersized/progress-back.png | Bin 929 -> 924 bytes apps/gallery/img/supersized/progress-bar.png | Bin 929 -> 924 bytes apps/gallery/img/supersized/supersized-logo.png | Bin 3982 -> 3488 bytes apps/gallery/img/supersized/thumb-back.png | Bin 2122 -> 2010 bytes apps/gallery/img/supersized/thumb-forward.png | Bin 2118 -> 2007 bytes apps/remoteStorage/img/remoteStorage.png | Bin 1273 -> 1024 bytes apps/tasks/img/icon.png | Bin 457 -> 372 bytes core/img/actions/add.png | Bin 488 -> 441 bytes core/img/actions/delete.png | Bin 275 -> 240 bytes core/img/actions/download.png | Bin 246 -> 236 bytes core/img/actions/history.png | Bin 370 -> 363 bytes core/img/actions/info.png | Bin 474 -> 423 bytes core/img/actions/logout.png | Bin 657 -> 592 bytes core/img/actions/mail.png | Bin 463 -> 405 bytes core/img/actions/pause-big.png | Bin 183 -> 166 bytes core/img/actions/pause.png | Bin 182 -> 170 bytes core/img/actions/play-add.png | Bin 275 -> 237 bytes core/img/actions/play-big.png | Bin 212 -> 210 bytes core/img/actions/play-next.png | Bin 253 -> 224 bytes core/img/actions/play-previous.png | Bin 260 -> 237 bytes core/img/actions/play.png | Bin 220 -> 201 bytes core/img/actions/public.png | Bin 459 -> 412 bytes core/img/actions/rename.png | Bin 310 -> 267 bytes core/img/actions/search.png | Bin 701 -> 554 bytes core/img/actions/settings.png | Bin 883 -> 683 bytes core/img/actions/share.png | Bin 377 -> 338 bytes core/img/actions/shared.png | Bin 437 -> 364 bytes core/img/actions/sound-off.png | Bin 217 -> 192 bytes core/img/actions/sound.png | Bin 292 -> 254 bytes core/img/actions/triangle-s.png | Bin 526 -> 515 bytes core/img/actions/upload-white.png | Bin 228 -> 226 bytes core/img/actions/upload.png | Bin 236 -> 235 bytes core/img/breadcrumb-start.png | Bin 452 -> 311 bytes core/img/breadcrumb.png | Bin 452 -> 320 bytes core/img/favicon-touch.png | Bin 5703 -> 3705 bytes core/img/favicon.png | Bin 1231 -> 912 bytes core/img/filetypes/application-msword.png | Bin 28346 -> 789 bytes core/img/filetypes/application-sgf.png | Bin 725 -> 702 bytes .../application-vnd.oasis.opendocument.formula.png | Bin 580 -> 479 bytes .../application-vnd.oasis.opendocument.graphics.png | Bin 572 -> 475 bytes ...lication-vnd.oasis.opendocument.presentation.png | Bin 441 -> 333 bytes ...plication-vnd.oasis.opendocument.spreadsheet.png | Bin 436 -> 344 bytes .../application-vnd.oasis.opendocument.text.png | Bin 420 -> 347 bytes core/img/filetypes/application-x-7z-compressed.png | Bin 652 -> 650 bytes .../filetypes/application-x-bzip-compressed-tar.png | Bin 652 -> 650 bytes core/img/filetypes/application-x-bzip.png | Bin 652 -> 650 bytes core/img/filetypes/application-x-compressed-tar.png | Bin 652 -> 650 bytes core/img/filetypes/application-x-deb.png | Bin 652 -> 650 bytes core/img/filetypes/application-x-debian-package.png | Bin 570 -> 548 bytes core/img/filetypes/application-x-gzip.png | Bin 652 -> 650 bytes .../filetypes/application-x-lzma-compressed-tar.png | Bin 652 -> 650 bytes core/img/filetypes/application-x-rar.png | Bin 652 -> 650 bytes core/img/filetypes/application-x-rpm.png | Bin 652 -> 650 bytes core/img/filetypes/application-x-tar.png | Bin 652 -> 650 bytes core/img/filetypes/application-x-tarz.png | Bin 652 -> 650 bytes core/img/filetypes/application-zip.png | Bin 652 -> 650 bytes core/img/filetypes/flash.png | Bin 582 -> 580 bytes core/img/icon-error.png | Bin 1573 -> 1344 bytes core/img/icon-sync.png | Bin 1577 -> 1271 bytes core/img/icon.png | Bin 1344 -> 1109 bytes core/img/logo-inverted.png | Bin 8116 -> 5938 bytes core/img/logo-square.png | Bin 22792 -> 16048 bytes core/img/logo-wide.png | Bin 2293 -> 1908 bytes core/img/logo.png | Bin 7356 -> 5860 bytes core/img/places/file.png | Bin 391 -> 364 bytes core/img/places/folder.png | Bin 386 -> 339 bytes core/img/places/home.png | Bin 416 -> 372 bytes core/img/places/music.png | Bin 561 -> 532 bytes core/img/places/picture.png | Bin 307 -> 300 bytes core/img/remoteStorage-big.png | Bin 9742 -> 8997 bytes settings/img/admin.png | Bin 302 -> 224 bytes settings/img/apps.png | Bin 255 -> 229 bytes settings/img/help.png | Bin 474 -> 423 bytes settings/img/log.png | Bin 441 -> 342 bytes settings/img/personal.png | Bin 589 -> 504 bytes settings/img/users.png | Bin 743 -> 639 bytes settings/trans.png | Bin 187 -> 185 bytes tests/data/logo-wide.png | Bin 3559 -> 2882 bytes 98 files changed, 0 insertions(+), 0 deletions(-) (limited to 'tests') diff --git a/apps/bookmarks/img/bookmarks.png b/apps/bookmarks/img/bookmarks.png index b92e4f50a42..3e8eed2380f 100644 Binary files a/apps/bookmarks/img/bookmarks.png and b/apps/bookmarks/img/bookmarks.png differ diff --git a/apps/calendar/img/icon.png b/apps/calendar/img/icon.png index eb9e07cbb10..267efd997f3 100644 Binary files a/apps/calendar/img/icon.png and b/apps/calendar/img/icon.png differ diff --git a/apps/contacts/img/contact-new.png b/apps/contacts/img/contact-new.png index 087ad9ab2d3..a91f2e620fa 100644 Binary files a/apps/contacts/img/contact-new.png and b/apps/contacts/img/contact-new.png differ diff --git a/apps/contacts/img/person.png b/apps/contacts/img/person.png index 17e79196540..e88bb5653af 100644 Binary files a/apps/contacts/img/person.png and b/apps/contacts/img/person.png differ diff --git a/apps/contacts/img/person_large.png b/apps/contacts/img/person_large.png index 4edba0c5489..8293df61829 100644 Binary files a/apps/contacts/img/person_large.png and b/apps/contacts/img/person_large.png differ diff --git a/apps/external/img/external.png b/apps/external/img/external.png index 75d1366326b..9e56f2919fd 100644 Binary files a/apps/external/img/external.png and b/apps/external/img/external.png differ diff --git a/apps/files_imageviewer/img/fancybox-y.png b/apps/files_imageviewer/img/fancybox-y.png index 7ef399b9908..62f31761998 100644 Binary files a/apps/files_imageviewer/img/fancybox-y.png and b/apps/files_imageviewer/img/fancybox-y.png differ diff --git a/apps/gallery/img/breadcrumb.png b/apps/gallery/img/breadcrumb.png index a252a751554..adbef1e576d 100644 Binary files a/apps/gallery/img/breadcrumb.png and b/apps/gallery/img/breadcrumb.png differ diff --git a/apps/gallery/img/delete.png b/apps/gallery/img/delete.png index bc0c782882d..fa8e18183ed 100644 Binary files a/apps/gallery/img/delete.png and b/apps/gallery/img/delete.png differ diff --git a/apps/gallery/img/rename.png b/apps/gallery/img/rename.png index 9993a092df1..3af6840071b 100644 Binary files a/apps/gallery/img/rename.png and b/apps/gallery/img/rename.png differ diff --git a/apps/gallery/img/share.png b/apps/gallery/img/share.png index 62c4627f317..099e4d6ab35 100644 Binary files a/apps/gallery/img/share.png and b/apps/gallery/img/share.png differ diff --git a/apps/gallery/img/supersized/back.png b/apps/gallery/img/supersized/back.png index 44cd0ae703c..f0e809ece09 100644 Binary files a/apps/gallery/img/supersized/back.png and b/apps/gallery/img/supersized/back.png differ diff --git a/apps/gallery/img/supersized/bg-black.png b/apps/gallery/img/supersized/bg-black.png index 8c2f00140d6..e7ce54412b8 100644 Binary files a/apps/gallery/img/supersized/bg-black.png and b/apps/gallery/img/supersized/bg-black.png differ diff --git a/apps/gallery/img/supersized/button-tray-down.png b/apps/gallery/img/supersized/button-tray-down.png index 99b92aef122..15645ae34ef 100644 Binary files a/apps/gallery/img/supersized/button-tray-down.png and b/apps/gallery/img/supersized/button-tray-down.png differ diff --git a/apps/gallery/img/supersized/button-tray-up.png b/apps/gallery/img/supersized/button-tray-up.png index 7cc57785f0a..0ee91d25ba0 100644 Binary files a/apps/gallery/img/supersized/button-tray-up.png and b/apps/gallery/img/supersized/button-tray-up.png differ diff --git a/apps/gallery/img/supersized/forward.png b/apps/gallery/img/supersized/forward.png index e2084ab3faf..a6408f75118 100644 Binary files a/apps/gallery/img/supersized/forward.png and b/apps/gallery/img/supersized/forward.png differ diff --git a/apps/gallery/img/supersized/nav-bg.png b/apps/gallery/img/supersized/nav-bg.png index 800f904ddc7..c1a9fc170f4 100644 Binary files a/apps/gallery/img/supersized/nav-bg.png and b/apps/gallery/img/supersized/nav-bg.png differ diff --git a/apps/gallery/img/supersized/nav-dot.png b/apps/gallery/img/supersized/nav-dot.png index a28a50789f3..4319ed04213 100644 Binary files a/apps/gallery/img/supersized/nav-dot.png and b/apps/gallery/img/supersized/nav-dot.png differ diff --git a/apps/gallery/img/supersized/pause.png b/apps/gallery/img/supersized/pause.png index a2c21a51cee..1e81d1856b6 100644 Binary files a/apps/gallery/img/supersized/pause.png and b/apps/gallery/img/supersized/pause.png differ diff --git a/apps/gallery/img/supersized/play.png b/apps/gallery/img/supersized/play.png index 16e53f86745..df94a034986 100644 Binary files a/apps/gallery/img/supersized/play.png and b/apps/gallery/img/supersized/play.png differ diff --git a/apps/gallery/img/supersized/progress-back.png b/apps/gallery/img/supersized/progress-back.png index 68cd45b6706..95992f1410c 100644 Binary files a/apps/gallery/img/supersized/progress-back.png and b/apps/gallery/img/supersized/progress-back.png differ diff --git a/apps/gallery/img/supersized/progress-bar.png b/apps/gallery/img/supersized/progress-bar.png index 49ebb0513b7..9758d178831 100644 Binary files a/apps/gallery/img/supersized/progress-bar.png and b/apps/gallery/img/supersized/progress-bar.png differ diff --git a/apps/gallery/img/supersized/supersized-logo.png b/apps/gallery/img/supersized/supersized-logo.png index b1243a29784..cc106293292 100644 Binary files a/apps/gallery/img/supersized/supersized-logo.png and b/apps/gallery/img/supersized/supersized-logo.png differ diff --git a/apps/gallery/img/supersized/thumb-back.png b/apps/gallery/img/supersized/thumb-back.png index 3c969ebd527..b86a9110ee4 100644 Binary files a/apps/gallery/img/supersized/thumb-back.png and b/apps/gallery/img/supersized/thumb-back.png differ diff --git a/apps/gallery/img/supersized/thumb-forward.png b/apps/gallery/img/supersized/thumb-forward.png index afe451c75d0..bff5ec1108a 100644 Binary files a/apps/gallery/img/supersized/thumb-forward.png and b/apps/gallery/img/supersized/thumb-forward.png differ diff --git a/apps/remoteStorage/img/remoteStorage.png b/apps/remoteStorage/img/remoteStorage.png index 6b751c09997..10c2be243c2 100644 Binary files a/apps/remoteStorage/img/remoteStorage.png and b/apps/remoteStorage/img/remoteStorage.png differ diff --git a/apps/tasks/img/icon.png b/apps/tasks/img/icon.png index df281f3ba86..e2802ae9387 100644 Binary files a/apps/tasks/img/icon.png and b/apps/tasks/img/icon.png differ diff --git a/core/img/actions/add.png b/core/img/actions/add.png index db1b1970f17..25d472b2dc4 100644 Binary files a/core/img/actions/add.png and b/core/img/actions/add.png differ diff --git a/core/img/actions/delete.png b/core/img/actions/delete.png index bc0c782882d..fa8e18183ed 100644 Binary files a/core/img/actions/delete.png and b/core/img/actions/delete.png differ diff --git a/core/img/actions/download.png b/core/img/actions/download.png index 14e88e14c0f..65954f941bb 100644 Binary files a/core/img/actions/download.png and b/core/img/actions/download.png differ diff --git a/core/img/actions/history.png b/core/img/actions/history.png index b1e743651f8..1d138b8cd5a 100644 Binary files a/core/img/actions/history.png and b/core/img/actions/history.png differ diff --git a/core/img/actions/info.png b/core/img/actions/info.png index 2257d144d11..37ccb356830 100644 Binary files a/core/img/actions/info.png and b/core/img/actions/info.png differ diff --git a/core/img/actions/logout.png b/core/img/actions/logout.png index 74dcd33bee7..eb2ea766c31 100644 Binary files a/core/img/actions/logout.png and b/core/img/actions/logout.png differ diff --git a/core/img/actions/mail.png b/core/img/actions/mail.png index 4d3192ef329..8e884fbc0ea 100644 Binary files a/core/img/actions/mail.png and b/core/img/actions/mail.png differ diff --git a/core/img/actions/pause-big.png b/core/img/actions/pause-big.png index 9bcfd0406d8..1c4cf503b8d 100644 Binary files a/core/img/actions/pause-big.png and b/core/img/actions/pause-big.png differ diff --git a/core/img/actions/pause.png b/core/img/actions/pause.png index ced8c43ab34..f74ed3a8619 100644 Binary files a/core/img/actions/pause.png and b/core/img/actions/pause.png differ diff --git a/core/img/actions/play-add.png b/core/img/actions/play-add.png index 0c330d4ac44..0097f671aef 100644 Binary files a/core/img/actions/play-add.png and b/core/img/actions/play-add.png differ diff --git a/core/img/actions/play-big.png b/core/img/actions/play-big.png index 3ccd36129ec..2da2426dcfc 100644 Binary files a/core/img/actions/play-big.png and b/core/img/actions/play-big.png differ diff --git a/core/img/actions/play-next.png b/core/img/actions/play-next.png index 0c0ccc87cdc..08568b3dc0b 100644 Binary files a/core/img/actions/play-next.png and b/core/img/actions/play-next.png differ diff --git a/core/img/actions/play-previous.png b/core/img/actions/play-previous.png index d98cedaa1e8..811cde46c15 100644 Binary files a/core/img/actions/play-previous.png and b/core/img/actions/play-previous.png differ diff --git a/core/img/actions/play.png b/core/img/actions/play.png index a252a751554..adbef1e576d 100644 Binary files a/core/img/actions/play.png and b/core/img/actions/play.png differ diff --git a/core/img/actions/public.png b/core/img/actions/public.png index 75d1366326b..9e56f2919fd 100644 Binary files a/core/img/actions/public.png and b/core/img/actions/public.png differ diff --git a/core/img/actions/rename.png b/core/img/actions/rename.png index 9993a092df1..3af6840071b 100644 Binary files a/core/img/actions/rename.png and b/core/img/actions/rename.png differ diff --git a/core/img/actions/search.png b/core/img/actions/search.png index bfedb80bb57..98e1d73ee34 100644 Binary files a/core/img/actions/search.png and b/core/img/actions/search.png differ diff --git a/core/img/actions/settings.png b/core/img/actions/settings.png index 5b1607e59fc..8b3acb00a4f 100644 Binary files a/core/img/actions/settings.png and b/core/img/actions/settings.png differ diff --git a/core/img/actions/share.png b/core/img/actions/share.png index 62c4627f317..099e4d6ab35 100644 Binary files a/core/img/actions/share.png and b/core/img/actions/share.png differ diff --git a/core/img/actions/shared.png b/core/img/actions/shared.png index 073ff741685..6e112e75b44 100644 Binary files a/core/img/actions/shared.png and b/core/img/actions/shared.png differ diff --git a/core/img/actions/sound-off.png b/core/img/actions/sound-off.png index 7900e500c90..2eddb00af0f 100644 Binary files a/core/img/actions/sound-off.png and b/core/img/actions/sound-off.png differ diff --git a/core/img/actions/sound.png b/core/img/actions/sound.png index 838c9cee171..9349c94e7a4 100644 Binary files a/core/img/actions/sound.png and b/core/img/actions/sound.png differ diff --git a/core/img/actions/triangle-s.png b/core/img/actions/triangle-s.png index d77d5db2caa..53590a2197b 100644 Binary files a/core/img/actions/triangle-s.png and b/core/img/actions/triangle-s.png differ diff --git a/core/img/actions/upload-white.png b/core/img/actions/upload-white.png index 09dba9e9108..fd9bdccc240 100644 Binary files a/core/img/actions/upload-white.png and b/core/img/actions/upload-white.png differ diff --git a/core/img/actions/upload.png b/core/img/actions/upload.png index 5744aad75a8..1d90165a552 100644 Binary files a/core/img/actions/upload.png and b/core/img/actions/upload.png differ diff --git a/core/img/breadcrumb-start.png b/core/img/breadcrumb-start.png index a79d675454e..b0df5f44037 100644 Binary files a/core/img/breadcrumb-start.png and b/core/img/breadcrumb-start.png differ diff --git a/core/img/breadcrumb.png b/core/img/breadcrumb.png index b124f349f56..84992be0d93 100644 Binary files a/core/img/breadcrumb.png and b/core/img/breadcrumb.png differ diff --git a/core/img/favicon-touch.png b/core/img/favicon-touch.png index cfaaa4399ac..24770fb634f 100644 Binary files a/core/img/favicon-touch.png and b/core/img/favicon-touch.png differ diff --git a/core/img/favicon.png b/core/img/favicon.png index c1b1cb65460..79b6795f6f6 100644 Binary files a/core/img/favicon.png and b/core/img/favicon.png differ diff --git a/core/img/filetypes/application-msword.png b/core/img/filetypes/application-msword.png index 6f7bb520f25..e8b230c59cb 100644 Binary files a/core/img/filetypes/application-msword.png and b/core/img/filetypes/application-msword.png differ diff --git a/core/img/filetypes/application-sgf.png b/core/img/filetypes/application-sgf.png index f171f5579e7..48996c54394 100644 Binary files a/core/img/filetypes/application-sgf.png and b/core/img/filetypes/application-sgf.png differ diff --git a/core/img/filetypes/application-vnd.oasis.opendocument.formula.png b/core/img/filetypes/application-vnd.oasis.opendocument.formula.png index 4cefbb690d1..e0cf49542d4 100644 Binary files a/core/img/filetypes/application-vnd.oasis.opendocument.formula.png and b/core/img/filetypes/application-vnd.oasis.opendocument.formula.png differ diff --git a/core/img/filetypes/application-vnd.oasis.opendocument.graphics.png b/core/img/filetypes/application-vnd.oasis.opendocument.graphics.png index 3d66cc97eb5..b326a0543a5 100644 Binary files a/core/img/filetypes/application-vnd.oasis.opendocument.graphics.png and b/core/img/filetypes/application-vnd.oasis.opendocument.graphics.png differ diff --git a/core/img/filetypes/application-vnd.oasis.opendocument.presentation.png b/core/img/filetypes/application-vnd.oasis.opendocument.presentation.png index 46942cba285..7c6fd246840 100644 Binary files a/core/img/filetypes/application-vnd.oasis.opendocument.presentation.png and b/core/img/filetypes/application-vnd.oasis.opendocument.presentation.png differ diff --git a/core/img/filetypes/application-vnd.oasis.opendocument.spreadsheet.png b/core/img/filetypes/application-vnd.oasis.opendocument.spreadsheet.png index abc38d4310c..8b0e85b0670 100644 Binary files a/core/img/filetypes/application-vnd.oasis.opendocument.spreadsheet.png and b/core/img/filetypes/application-vnd.oasis.opendocument.spreadsheet.png differ diff --git a/core/img/filetypes/application-vnd.oasis.opendocument.text.png b/core/img/filetypes/application-vnd.oasis.opendocument.text.png index 06c1f30c8fa..48452eb3e86 100644 Binary files a/core/img/filetypes/application-vnd.oasis.opendocument.text.png and b/core/img/filetypes/application-vnd.oasis.opendocument.text.png differ diff --git a/core/img/filetypes/application-x-7z-compressed.png b/core/img/filetypes/application-x-7z-compressed.png index 55dd0f75366..2cd08aebf95 100644 Binary files a/core/img/filetypes/application-x-7z-compressed.png and b/core/img/filetypes/application-x-7z-compressed.png differ diff --git a/core/img/filetypes/application-x-bzip-compressed-tar.png b/core/img/filetypes/application-x-bzip-compressed-tar.png index 55dd0f75366..2cd08aebf95 100644 Binary files a/core/img/filetypes/application-x-bzip-compressed-tar.png and b/core/img/filetypes/application-x-bzip-compressed-tar.png differ diff --git a/core/img/filetypes/application-x-bzip.png b/core/img/filetypes/application-x-bzip.png index 55dd0f75366..2cd08aebf95 100644 Binary files a/core/img/filetypes/application-x-bzip.png and b/core/img/filetypes/application-x-bzip.png differ diff --git a/core/img/filetypes/application-x-compressed-tar.png b/core/img/filetypes/application-x-compressed-tar.png index 55dd0f75366..2cd08aebf95 100644 Binary files a/core/img/filetypes/application-x-compressed-tar.png and b/core/img/filetypes/application-x-compressed-tar.png differ diff --git a/core/img/filetypes/application-x-deb.png b/core/img/filetypes/application-x-deb.png index 55dd0f75366..2cd08aebf95 100644 Binary files a/core/img/filetypes/application-x-deb.png and b/core/img/filetypes/application-x-deb.png differ diff --git a/core/img/filetypes/application-x-debian-package.png b/core/img/filetypes/application-x-debian-package.png index eff1b7fc8c2..b3f6b7e5cf9 100644 Binary files a/core/img/filetypes/application-x-debian-package.png and b/core/img/filetypes/application-x-debian-package.png differ diff --git a/core/img/filetypes/application-x-gzip.png b/core/img/filetypes/application-x-gzip.png index 55dd0f75366..2cd08aebf95 100644 Binary files a/core/img/filetypes/application-x-gzip.png and b/core/img/filetypes/application-x-gzip.png differ diff --git a/core/img/filetypes/application-x-lzma-compressed-tar.png b/core/img/filetypes/application-x-lzma-compressed-tar.png index 55dd0f75366..2cd08aebf95 100644 Binary files a/core/img/filetypes/application-x-lzma-compressed-tar.png and b/core/img/filetypes/application-x-lzma-compressed-tar.png differ diff --git a/core/img/filetypes/application-x-rar.png b/core/img/filetypes/application-x-rar.png index 55dd0f75366..2cd08aebf95 100644 Binary files a/core/img/filetypes/application-x-rar.png and b/core/img/filetypes/application-x-rar.png differ diff --git a/core/img/filetypes/application-x-rpm.png b/core/img/filetypes/application-x-rpm.png index 55dd0f75366..2cd08aebf95 100644 Binary files a/core/img/filetypes/application-x-rpm.png and b/core/img/filetypes/application-x-rpm.png differ diff --git a/core/img/filetypes/application-x-tar.png b/core/img/filetypes/application-x-tar.png index 55dd0f75366..2cd08aebf95 100644 Binary files a/core/img/filetypes/application-x-tar.png and b/core/img/filetypes/application-x-tar.png differ diff --git a/core/img/filetypes/application-x-tarz.png b/core/img/filetypes/application-x-tarz.png index 55dd0f75366..2cd08aebf95 100644 Binary files a/core/img/filetypes/application-x-tarz.png and b/core/img/filetypes/application-x-tarz.png differ diff --git a/core/img/filetypes/application-zip.png b/core/img/filetypes/application-zip.png index 55dd0f75366..2cd08aebf95 100644 Binary files a/core/img/filetypes/application-zip.png and b/core/img/filetypes/application-zip.png differ diff --git a/core/img/filetypes/flash.png b/core/img/filetypes/flash.png index 5769120b1b6..9f5db634a4f 100644 Binary files a/core/img/filetypes/flash.png and b/core/img/filetypes/flash.png differ diff --git a/core/img/icon-error.png b/core/img/icon-error.png index ed438a32fd8..1ce0be0fb2e 100644 Binary files a/core/img/icon-error.png and b/core/img/icon-error.png differ diff --git a/core/img/icon-sync.png b/core/img/icon-sync.png index 99a43d4c69a..a3d09704246 100644 Binary files a/core/img/icon-sync.png and b/core/img/icon-sync.png differ diff --git a/core/img/icon.png b/core/img/icon.png index 24a4b1c3e83..745b82584c6 100644 Binary files a/core/img/icon.png and b/core/img/icon.png differ diff --git a/core/img/logo-inverted.png b/core/img/logo-inverted.png index d9fd119dc18..265a8871b45 100644 Binary files a/core/img/logo-inverted.png and b/core/img/logo-inverted.png differ diff --git a/core/img/logo-square.png b/core/img/logo-square.png index 086d415db6d..b836de8f3be 100644 Binary files a/core/img/logo-square.png and b/core/img/logo-square.png differ diff --git a/core/img/logo-wide.png b/core/img/logo-wide.png index ea10828db5e..702f1d97e5b 100644 Binary files a/core/img/logo-wide.png and b/core/img/logo-wide.png differ diff --git a/core/img/logo.png b/core/img/logo.png index 8177c4cdba1..a84fe145bbd 100644 Binary files a/core/img/logo.png and b/core/img/logo.png differ diff --git a/core/img/places/file.png b/core/img/places/file.png index 49790448897..63837a1af90 100644 Binary files a/core/img/places/file.png and b/core/img/places/file.png differ diff --git a/core/img/places/folder.png b/core/img/places/folder.png index 3edbe257a34..46079e03e9e 100644 Binary files a/core/img/places/folder.png and b/core/img/places/folder.png differ diff --git a/core/img/places/home.png b/core/img/places/home.png index b3fb9bbaf6f..c3dbd3e3538 100644 Binary files a/core/img/places/home.png and b/core/img/places/home.png differ diff --git a/core/img/places/music.png b/core/img/places/music.png index 4c844425d64..85ee2474cd1 100644 Binary files a/core/img/places/music.png and b/core/img/places/music.png differ diff --git a/core/img/places/picture.png b/core/img/places/picture.png index 980a7c69813..9abcd09722c 100644 Binary files a/core/img/places/picture.png and b/core/img/places/picture.png differ diff --git a/core/img/remoteStorage-big.png b/core/img/remoteStorage-big.png index 7c429a6a738..f2254233031 100644 Binary files a/core/img/remoteStorage-big.png and b/core/img/remoteStorage-big.png differ diff --git a/settings/img/admin.png b/settings/img/admin.png index c1e6d6b8a7f..13d653f92a8 100644 Binary files a/settings/img/admin.png and b/settings/img/admin.png differ diff --git a/settings/img/apps.png b/settings/img/apps.png index 17f47d632b9..e9845d012be 100644 Binary files a/settings/img/apps.png and b/settings/img/apps.png differ diff --git a/settings/img/help.png b/settings/img/help.png index 2257d144d11..37ccb356830 100644 Binary files a/settings/img/help.png and b/settings/img/help.png differ diff --git a/settings/img/log.png b/settings/img/log.png index c84b3b29f19..b34a58f844c 100644 Binary files a/settings/img/log.png and b/settings/img/log.png differ diff --git a/settings/img/personal.png b/settings/img/personal.png index 8204028f70e..8edc5a16cd6 100644 Binary files a/settings/img/personal.png and b/settings/img/personal.png differ diff --git a/settings/img/users.png b/settings/img/users.png index f56e2442c9e..79ad3d667e1 100644 Binary files a/settings/img/users.png and b/settings/img/users.png differ diff --git a/settings/trans.png b/settings/trans.png index e6920168bf2..ef57510d530 100644 Binary files a/settings/trans.png and b/settings/trans.png differ diff --git a/tests/data/logo-wide.png b/tests/data/logo-wide.png index b2c16a0f60a..648cb7e6156 100644 Binary files a/tests/data/logo-wide.png and b/tests/data/logo-wide.png differ -- cgit v1.2.3 From 596246989217143d78e8987fa7b2c4154806a644 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 18 Aug 2012 01:17:28 +0200 Subject: add OC_Archive::addRecursive --- lib/archive.php | 21 +++++++++++++++++++++ tests/lib/archive.php | 8 ++++++++ 2 files changed, 29 insertions(+) (limited to 'tests') diff --git a/lib/archive.php b/lib/archive.php index 113f92e9604..fabd7cc7a51 100644 --- a/lib/archive.php +++ b/lib/archive.php @@ -112,4 +112,25 @@ abstract class OC_Archive{ * @return resource */ abstract function getStream($path,$mode); + /** + * add a folder and all it's content + * @param string $path + * @param string source + * @return bool + */ + function addRecursive($path,$source){ + if($dh=opendir($source)){ + $this->addFolder($path); + while($file=readdir($dh)){ + if($file=='.' or $file=='..'){ + continue; + } + if(is_dir($source.'/'.$file)){ + $this->addRecursive($path.'/'.$file,$source.'/'.$file); + }else{ + $this->addFile($path.'/'.$file,$source.'/'.$file); + } + } + } + } } diff --git a/tests/lib/archive.php b/tests/lib/archive.php index 1779127c932..1711be58e01 100644 --- a/tests/lib/archive.php +++ b/tests/lib/archive.php @@ -130,4 +130,12 @@ abstract class Test_Archive extends UnitTestCase { $this->instance->remove('target.txt'); $this->assertFalse($this->instance->fileExists('target.txt')); } + public function testRecursive(){ + $dir=OC::$SERVERROOT.'/apps/files_archive/tests/data'; + $this->instance=$this->getNew(); + $this->instance->addRecursive('/dir',$dir); + $this->assertTrue($this->instance->fileExists('/dir/lorem.txt')); + $this->assertTrue($this->instance->fileExists('/dir/data.zip')); + $this->assertTrue($this->instance->fileExists('/dir/data.tar.gz')); + } } -- cgit v1.2.3 From 9b44d0cb32795c5ec645922b204de88c8f33c196 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 19 Aug 2012 02:30:33 +0200 Subject: add OC_FileStorage::getLocalFolder --- lib/filestorage.php | 1 + lib/filestorage/common.php | 20 ++++++++++++++++++++ lib/filestorage/local.php | 5 ++++- tests/lib/filestorage.php | 15 ++++++++++++++- 4 files changed, 39 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/lib/filestorage.php b/lib/filestorage.php index fd4ad36530e..672b9cb0d72 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -50,6 +50,7 @@ abstract class OC_Filestorage{ abstract public function search($query); abstract public function touch($path, $mtime=null); abstract public function getLocalFile($path);// get a path to a local version of the file, whether the original file is local or remote + abstract public function getLocalFolder($path);// get a path to a local version of the folder, whether the original file is local or remote /** * check if a file or folder has been updated since $time * @param int $time diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index c77df38e6b1..4f506a31495 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -223,6 +223,26 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { OC_Helper::streamCopy($source,$target); return $tmpFile; } + public function getLocalFolder($path){ + $baseDir=OC_Helper::tmpFolder(); + $this->addLocalFolder($path,$baseDir); + return $baseDir; + } + private function addLocalFolder($path,$target){ + if($dh=$this->opendir($path)){ + while($file=readdir($dh)){ + if($file!=='.' and $file!=='..'){ + if($this->is_dir($path.'/'.$file)){ + mkdir($target.'/'.$file); + $this->addLocalFolder($path.'/'.$file,$target.'/'.$file); + }else{ + $tmp=$this->toTmpFile($path.'/'.$file); + rename($tmp,$target.'/'.$file); + } + } + } + } + } // abstract public function touch($path, $mtime=null); protected function searchInDir($query,$dir=''){ diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index d60f32b15be..2087663809f 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -168,7 +168,10 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{ return $this->searchInDir($query); } public function getLocalFile($path){ - return $this->datadir.$path; + return $this->datadir.$path; + } + public function getLocalFolder($path){ + return $this->datadir.$path; } protected function searchInDir($query,$dir=''){ diff --git a/tests/lib/filestorage.php b/tests/lib/filestorage.php index 00f37b9f1a2..e554a75e441 100644 --- a/tests/lib/filestorage.php +++ b/tests/lib/filestorage.php @@ -129,12 +129,25 @@ abstract class Test_FileStorage extends UnitTestCase { $this->assertEqual(file_get_contents($textFile),$this->instance->file_get_contents('/target.txt')); } - public function testLocalFile(){ + public function testLocal(){ $textFile=OC::$SERVERROOT.'/tests/data/lorem.txt'; $this->instance->file_put_contents('/lorem.txt',file_get_contents($textFile)); $localFile=$this->instance->getLocalFile('/lorem.txt'); $this->assertTrue(file_exists($localFile)); $this->assertEqual(file_get_contents($localFile),file_get_contents($textFile)); + + $this->instance->mkdir('/folder'); + $this->instance->file_put_contents('/folder/lorem.txt',file_get_contents($textFile)); + $this->instance->file_put_contents('/folder/bar.txt','asd'); + $this->instance->mkdir('/folder/recursive'); + $this->instance->file_put_contents('/folder/recursive/file.txt','foo'); + $localFolder=$this->instance->getLocalFolder('/folder'); + + $this->assertTrue(is_dir($localFolder)); + $this->assertTrue(file_exists($localFolder.'/lorem.txt')); + $this->assertEqual(file_get_contents($localFolder.'/lorem.txt'),file_get_contents($textFile)); + $this->assertEqual(file_get_contents($localFolder.'/bar.txt'),'asd'); + $this->assertEqual(file_get_contents($localFolder.'/recursive/file.txt'),'foo'); } public function testStat(){ -- cgit v1.2.3 From f987e22d85ebcf1761323855a6717a8f482beac5 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 19 Aug 2012 16:30:38 -0400 Subject: Large refactoring to allow for the same item to be shared to a group and again with a user in the group with different permissions --- lib/public/share.php | 249 ++++++++++++++++++++++++++++++---------------- tests/lib/share/share.php | 111 +++++++++++++++++++-- 2 files changed, 267 insertions(+), 93 deletions(-) (limited to 'tests') diff --git a/lib/public/share.php b/lib/public/share.php index 940bf2d48a0..d91529d7595 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -18,7 +18,6 @@ * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see . */ - namespace OCP; \OC_Hook::connect('OC_User', 'post_deleteUser', 'OCP\Share', 'post_deleteUser'); @@ -400,54 +399,54 @@ class Share { private static function getItems($itemType, $item = null, $shareType = null, $shareWith = null, $uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, $includeCollections = false, $itemShareWithBySource = false) { $backend = self::getBackend($itemType); // Get filesystem root to add it to the file target and remove from the file source, match file_source with the file cache - if ($backend instanceof Share_Backend_File_Dependent) { - $fileDependent = true; + if ($itemType == 'file' || $itemType == 'folder') { $root = \OC_Filesystem::getRoot(); - // TODO No need to do this for FORMAT_STATUSES and loading the item in the dropdown, it's a performance waste $where = 'INNER JOIN *PREFIX*fscache ON file_source = *PREFIX*fscache.id '; + if (!isset($item)) { + $where .= 'WHERE file_target IS NOT NULL'; + } + $fileDependent = true; } else { $fileDependent = false; - $where = ''; $root = ''; - } - if ($itemType == 'file' && !isset($item)) { - $where .= 'WHERE file_target IS NOT NULL'; - $query_args = array(); - } else if ($includeCollections && !isset($item) && $collectionTypes = self::getCollectionItemTypes($itemType)) { - // If includeCollections is true, find collections of this item type, e.g. a music album contains songs - $item_types = array_merge(array($itemType), $collectionTypes); - $placeholders = join(',', array_fill(0, count($item_types), '?')); - $where .= "WHERE item_type IN ('".$placeholders."')"; - $query_args = $item_types; - } else if ($itemType != 'file' && $itemType != 'folder') { - $where .= "WHERE item_type = ?"; - $query_args = array($itemType); + if ($includeCollections && !isset($item) && $collectionTypes = self::getCollectionItemTypes($itemType)) { + // If includeCollections is true, find collections of this item type, e.g. a music album contains songs + $itemTypes = array_merge(array($itemType), $collectionTypes); + $placeholders = join(',', array_fill(0, count($itemTypes), '?')); + $where = "WHERE item_type IN ('".$placeholders."')"; + $queryArgs = $itemTypes; + } else { + $where = 'WHERE item_type = ?'; + $queryArgs = array($itemType); + } } if (isset($shareType) && isset($shareWith)) { // Include all user and group items if ($shareType == self::$shareTypeUserAndGroups) { - $where .= " AND share_type IN (?,?,?)"; - $query_args[] = self::SHARE_TYPE_USER; - $query_args[] = self::SHARE_TYPE_GROUP; - $query_args[] = self::$shareTypeGroupUserUnique; - $groups = \OC_Group::getUserGroups($shareWith); - $userAndGroups = array_merge(array($shareWith), $groups); + $where .= ' AND share_type IN (?,?,?)'; + $queryArgs[] = self::SHARE_TYPE_USER; + $queryArgs[] = self::SHARE_TYPE_GROUP; + $queryArgs[] = self::$shareTypeGroupUserUnique; + $userAndGroups = array_merge(array($shareWith), \OC_Group::getUserGroups($shareWith)); $placeholders = join(',', array_fill(0, count($userAndGroups), '?')); $where .= " AND share_with IN (".$placeholders.")"; - $query_args = array_merge($query_args, $userAndGroups); + $queryArgs = array_merge($queryArgs, $userAndGroups); + // Don't include own group shares + $where .= ' AND uid_owner != ?'; + $queryArgs[] = $shareWith; } else { - $where .= " AND share_type = ? AND share_with = ?"; - $query_args[] = $shareType; - $query_args[] = $shareWith; + $where .= ' AND share_type = ? AND share_with = ?'; + $queryArgs[] = $shareType; + $queryArgs[] = $shareWith; } } if (isset($uidOwner)) { $where .= " AND uid_owner = ?"; - $query_args[] = $uidOwner; + $queryArgs[] = $uidOwner; if (!isset($shareType)) { // Prevent unique user targets for group shares from being selected $where .= " AND share_type != ?"; - $query_args[] = self::$shareTypeGroupUserUnique; + $queryArgs[] = self::$shareTypeGroupUserUnique; } if ($itemType == 'file' || $itemType == 'folder') { $column = 'file_source'; @@ -467,11 +466,11 @@ class Share { // If item type is a file, file source needs to be checked in case the item was converted if ($itemType == 'file' || $itemType == 'folder') { $where .= " AND path = ?"; - $query_args[] = $root.$item; + $queryArgs[] = $root.$item; } else { $where .= " AND item_source = ?"; $column = 'item_source'; - $query_args[] = $item; + $queryArgs[] = $item; } } else { if ($itemType == 'file' || $itemType == 'folder') { @@ -479,12 +478,12 @@ class Share { } else { $where .= " AND item_target = ?"; } - $query_args[] = $item; + $queryArgs[] = $item; } if ($includeCollections && $collectionTypes = self::getCollectionItemTypes($itemType)) { $placeholders = join(',', array_fill(0, count($collectionTypes), '?')); $where .= " OR item_type IN ('".$placeholders."')"; - $query_args = array_merge($query_args, $collectionTypes); + $queryArgs = array_merge($query_args, $collectionTypes); } } if ($limit != -1 && !$includeCollections) { @@ -493,7 +492,12 @@ class Share { // If the limit is not 1, the filtering can be done later $where .= ' ORDER BY *PREFIX*share.id DESC'; } - $where .= ' LIMIT '.$limit; + // The limit must be at least 3, because filtering needs to be done + if ($limit < 3) { + $where .= ' LIMIT 3'; + } else { + $where .= ' LIMIT '.$limit; + } } // TODO Optimize selects if ($format == self::FORMAT_STATUSES) { @@ -523,59 +527,79 @@ class Share { } $root = strlen($root); $query = \OC_DB::prepare('SELECT '.$select.' FROM *PREFIX*share '.$where); - $result = $query->execute($query_args); + $result = $query->execute($queryArgs); $items = array(); + $itemsSources = array(); while ($row = $result->fetchRow()) { - // Remove root from file source paths - if (isset($uidOwner) && isset($row['file_source'])) { - $row['file_source'] = substr($row['file_source'], $root); - } - // Return only the item instead of a 2-dimensional array - if ($limit == 1 && $row['item_type'] == $itemType && $row[$column] == $item) { - if ($format == self::FORMAT_NONE) { - return $row; - } else { - $items[$row['id']] = $row; - break; - } - } // Filter out duplicate group shares for users with unique targets if ($row['share_type'] == self::$shareTypeGroupUserUnique) { // Remove the parent group share - unset($items[$row['parent']]); + if (isset($items[$row['parent']])) { + unset($items[$row['parent']]); + } + } else if (!isset($uidOwner)) { + // Check if the same item source already exists + if (isset($itemsSources[$row[$column]])) { + // Check if the same owner shared with the user twice through a group and user share - this is allowed + $id = $itemsSources[$row[$column]]; + if ($items[$id]['uid_owner'] == $row['uid_owner']) { + // Combine the permissions for the item + $items[$id]['permissions'] |= (int)$row['permissions']; + continue; + } + } else { + $itemsSources[$row[$column]] = $row['id']; + } + } + // Remove root from file source paths if retrieving own shared items + if (isset($uidOwner) && isset($row['file_source'])) { + $row['file_source'] = substr($row['file_source'], $root); } - // TODO Check this outside of the loop - // Check if this is a collection of the requested item type - if ($row['item_type'] != $itemType && $itemType != 'file' && !isset($item)) { - if ($collectionBackend = self::getBackend($row['item_type'] && $collectionBackend instanceof Share_Backend_Collection)) { + $items[$row['id']] = $row; + } + if (!empty($items)) { + $collectionItems = array(); + foreach ($items as &$row) { + // Return only the item instead of a 2-dimensional array + if ($limit == 1 && $row['item_type'] == $itemType && $row[$column] == $item) { + if ($format == self::FORMAT_NONE) { + return $row; + } else { + break; + } + } + // Check if this is a collection of the requested item type + if ($includeCollections && $row['item_type'] != $itemType && $collectionBackend = self::getBackend($row['item_type']) && $collectionBackend instanceof Share_Backend_Collection) { $row['collection'] = array('item_type' => $itemType, $column => $row[$column]); // Fetch all of the children sources $children = $collectionBackend->getChildren($row[$column]); foreach ($children as $child) { - $row['item_source'] = $child; -// $row['item_target'] = $child['target']; TODO + $childItem = $row; + $childItem['item_source'] = $child; +// $childItem['item_target'] = $child['target']; TODO if (isset($item)) { - if ($row[$column] == $item) { + if ($childItem[$column] == $item) { // Return only the item instead of a 2-dimensional array if ($limit == 1 && $format == self::FORMAT_NONE) { - return $row; + return $childItem; } else { // Unset the items array and break out of both loops $items = array(); - $items[] = $row; + $items[] = $childItem; break 2; } } } else { - $items[] = $row; + $collectionItems[] = $childItem; } } + // Remove collection item + unset($items[$row['id']]); } - } else { - $items[$row['id']] = $row; } - } - if (!empty($items)) { + if (!empty($collectionItems)) { + $items = array_merge($items, $collectionItems); + } if ($format == self::FORMAT_NONE) { return $items; } else if ($format == self::FORMAT_STATUSES) { @@ -626,7 +650,27 @@ class Share { // Check if this is a reshare // TODO This query has pretty bad performance if there are large collections, figure out a way to make the collection searching more efficient if ($checkReshare = self::getItemSharedWithBySource($itemType, $itemSource, self::FORMAT_NONE, null, true)) { - if ((int)$checkReshare['permissions'] & self::PERMISSION_SHARE) { + if ($checkReshare['uid_owner'] == $shareWith && $shareType == self::SHARE_TYPE_USER) { + $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is the original sharer'; + \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); + throw new \Exception($message); + } else if ($shareType == self::SHARE_TYPE_GROUP && $checkReshare['share_with'] == $shareWith['group']) { + $message = 'Sharing '.$itemSource.' failed, because the item was orignally shared with the group '.$shareWith['group']; + \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); + throw new \Exception($message); + } else if (($checkReshare['share_type'] == self::SHARE_TYPE_GROUP || $checkReshare['share_type'] == self::$shareTypeGroupUserUnique) && $shareType == self::SHARE_TYPE_USER) { + if ($checkReshare['share_type'] == self::$shareTypeGroupUserUnique) { + $query = \OC_DB::prepare('SELECT share_with FROM *PREFIX*share WHERE id = ?'); + $group = $query->execute(array($checkReshare['parent']))->fetchOne(); + } else { + $group = $checkReshare['share_with']; + } + if (\OC_Group::inGroup($shareWith, $group)) { + $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is a member of the original group share'; + \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); + throw new \Exception($message); + } + } else if ((int)$checkReshare['permissions'] & self::PERMISSION_SHARE) { if (~(int)$checkReshare['permissions'] & $permissions) { $message = 'Sharing '.$itemSource.' failed, because the permissions exceed permissions granted to '.$uidOwner; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); @@ -671,7 +715,7 @@ class Share { if (isset($fileSource)) { if ($parentFolder) { if ($parentFolder === true) { - $groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group']); + $groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group'], $uidOwner); // Set group default file target for future use $parentFolders[0]['folder'] = $groupFileTarget; } else { @@ -683,22 +727,20 @@ class Share { $uidSharedWith = array_keys($parentFolder); } } else { - $groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group']); + $groupFileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith['group'], $uidOwner); } } else { $groupFileTarget = null; } - $groupItemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith['group']); - $query->execute(array($itemType, $itemSource, $groupItemTarget, $parent, $shareType, $shareWith['group'], $uidOwner, $permissions, time(), $fileSource, $groupFileTarget)); - // Save this id, any extra rows for this group share will need to reference it - $parent = \OC_DB::insertid('*PREFIX*share'); + $groupItemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner); + $uniqueTargets = array(); // Loop through all users of this group in case we need to add an extra row foreach ($shareWith['users'] as $uid) { - $itemTarget = self::generateTarget($itemType, $itemSource, self::SHARE_TYPE_USER, $uid); + $itemTarget = self::generateTarget($itemType, $itemSource, self::SHARE_TYPE_USER, $uid, $uidOwner); if (isset($fileSource)) { if ($parentFolder) { if ($parentFolder === true) { - $fileTarget = self::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid); + $fileTarget = self::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid, $uidOwner); if ($fileTarget != $groupFileTarget) { $parentFolders[$uid]['folder'] = $fileTarget; } @@ -707,16 +749,22 @@ class Share { $parent = $parentFolder[$uid]['id']; } } else { - $fileTarget = self::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid); + $fileTarget = self::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid, $uidOwner); } } else { $fileTarget = null; } // Insert an extra row for the group share if the item or file target is unique for this user if ($itemTarget != $groupItemTarget || (isset($fileSource) && $fileTarget != $groupFileTarget)) { - $query->execute(array($itemType, $itemSource, $itemTarget, $parent, self::$shareTypeGroupUserUnique, $uid, $uidOwner, $permissions, time(), $fileSource, $fileTarget)); - $id = \OC_DB::insertid('*PREFIX*share'); + $uniqueTargets[] = array('uid' => $uid, 'item_target' => $itemTarget, 'file_target' => $fileTarget); } + } + $query->execute(array($itemType, $itemSource, $groupItemTarget, $parent, $shareType, $shareWith['group'], $uidOwner, $permissions, time(), $fileSource, $groupFileTarget)); + // Save this id, any extra rows for this group share will need to reference it + $parent = \OC_DB::insertid('*PREFIX*share'); + foreach ($uniqueTargets as $unique) { + $query->execute(array($itemType, $itemSource, $unique['item_target'], $parent, self::$shareTypeGroupUserUnique, $unique['uid'], $uidOwner, $permissions, time(), $fileSource, $unique['file_target'])); + $id = \OC_DB::insertid('*PREFIX*share'); if ($parentFolder === true) { $parentFolders['id'] = $id; } @@ -726,18 +774,18 @@ class Share { return $parentFolders; } } else { - $itemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith); + $itemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner); if (isset($fileSource)) { if ($parentFolder) { if ($parentFolder === true) { - $fileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith); + $fileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith, $uidOwner); $parentFolders['folder'] = $fileTarget; } else { $fileTarget = $parentFolder['folder'].$itemSource; $parent = $parentFolder['id']; } } else { - $fileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith); + $fileTarget = self::generateTarget('file', $filePath, $shareType, $shareWith, $uidOwner); } } else { $fileTarget = null; @@ -761,7 +809,7 @@ class Share { * @param string User or group the item is being shared with * @return string Item target */ - private static function generateTarget($itemType, $itemSource, $shareType, $shareWith) { + private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner) { $backend = self::getBackend($itemType); if ($shareType == self::SHARE_TYPE_PRIVATE_LINK) { return $backend->generateTarget($itemSource, false); @@ -771,6 +819,13 @@ class Share { } else { $column = 'item_target'; } + if ($shareType == self::SHARE_TYPE_USER) { + // Share with is a user, so set share type to user and groups + $shareType = self::$shareTypeUserAndGroups; + $userAndGroups = array_merge(array($shareWith), \OC_Group::getUserGroups($shareWith)); + } else { + $userAndGroups = false; + } $exclude = null; // Backend has 3 opportunities to generate a unique target for ($i = 0; $i < 2; $i++) { @@ -784,10 +839,21 @@ class Share { } // Check if target already exists if ($checkTarget = self::getItems($itemType, $target, $shareType, $shareWith, null, self::FORMAT_NONE, null, 1)) { + // If matching target is from the same owner, use the same target. The share type will be different so this isn't the same share. + if ($checkTarget['uid_owner'] == $uidOwner) { + return $target; + } + if (!isset($exclude)) { + $exclude = array(); + } // Find similar targets to improve backend's chances to generate a unqiue target - // TODO query needs to be setup like getItems - $checkTargets = \OC_DB::prepare('SELECT '.$column.' FROM *PREFIX*share WHERE item_type = ? AND share_with = ? AND '.$column.' LIKE ?'); - $result = $checkTargets->execute(array($itemType, $shareWith, '%'.$target.'%')); + if ($userAndGroups) { + $checkTargets = \OC_DB::prepare("SELECT ".$column." FROM *PREFIX*share WHERE item_type = ? AND share_type IN (?,?,?) AND share_with IN ('".implode("','", $userAndGroups)."') AND ".$column." LIKE ?"); + $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique, '%'.$target.'%')); + } else { + $checkTargets = \OC_DB::prepare("SELECT ".$column." FROM *PREFIX*share WHERE item_type = ? AND share_type = ? AND share_with = ? AND ".$column." LIKE ?"); + $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_GROUP, $shareWith, '%'.$target.'%')); + } while ($row = $result->fetchRow()) { $exclude[] = $row[$column]; } @@ -796,7 +862,7 @@ class Share { } } } - $message = 'Backend did not generate a unique target'; + $message = 'Sharing backend registered for '.$itemType.' did not generate a unique target for '.$itemSource; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } @@ -817,12 +883,24 @@ class Share { $query = \OC_DB::prepare('SELECT id FROM *PREFIX*share WHERE parent IN ('.$parents.') AND uid_owner = ?'); $result = $query->execute(array($uidOwner)); } else { - $query = \OC_DB::prepare('SELECT id FROM *PREFIX*share WHERE parent IN ('.$parents.')'); + $query = \OC_DB::prepare('SELECT id, item_type, item_source, parent, uid_owner FROM *PREFIX*share WHERE parent IN ('.$parents.')'); $result = $query->execute(); } // Reset parents array, only go through loop again if items are found $parents = array(); while ($item = $result->fetchRow()) { + // Search for a duplicate parent share, this occurs when an item is shared to the same user through a group and user or the same item is shared by different users + $userAndGroups = array_merge(array($item['uid_owner']), \OC_Group::getUserGroups($item['uid_owner'])); + $query = \OC_DB::prepare("SELECT id, permissions FROM *PREFIX*share WHERE item_type = ? AND item_source = ? AND share_type IN (?,?,?) AND share_with IN ('".implode("','", $userAndGroups)."') AND uid_owner != ? AND id != ?"); + $duplicateParent = $query->execute(array($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique, $item['uid_owner'], $item['parent']))->fetchRow(); + if ($duplicateParent) { + // Change the parent to the other item id if share permission is granted + if ($duplicateParent['permissions'] & self::PERMISSION_SHARE) { + $query = \OC_DB::prepare('UPDATE *PREFIX*share SET parent = ? WHERE id = ?'); + $query->execute(array($duplicateParent['id'], $item['id'])); + continue; + } + } $ids[] = $item['id']; $parents[] = $item['id']; } @@ -858,6 +936,7 @@ class Share { } public static function post_removeFromGroup($arguments) { + // TODO Don't call if user deleted? $query = \OC_DB::prepare('SELECT id, share_type FROM *PREFIX*share WHERE (share_type = ? AND share_with = ?) OR (share_type = ? AND share_with = ?)'); $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid'], self::$shareTypeGroupUserUnique, $arguments['uid'])); while ($item = $result->fetchRow()) { diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index efff2c5522c..4e48ab09c6f 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -36,9 +36,11 @@ class Test_Share extends UnitTestCase { $this->user1 = uniqid('user_'); $this->user2 = uniqid('user_'); $this->user3 = uniqid('user_'); + $this->user4 = uniqid('user_'); OC_User::createUser($this->user1, 'pass'); OC_User::createUser($this->user2, 'pass'); OC_User::createUser($this->user3, 'pass'); + OC_User::createUser($this->user4, 'pass'); OC_User::setUserId($this->user1); OC_Group::clearBackends(); OC_Group::useBackend(new OC_Group_Dummy); @@ -49,6 +51,8 @@ class Test_Share extends UnitTestCase { OC_Group::addToGroup($this->user1, $this->group1); OC_Group::addToGroup($this->user2, $this->group1); OC_Group::addToGroup($this->user3, $this->group1); + OC_Group::addToGroup($this->user2, $this->group2); + OC_Group::addToGroup($this->user4, $this->group2); OCP\Share::registerBackend('test', 'Test_Share_Backend'); } @@ -60,7 +64,6 @@ class Test_Share extends UnitTestCase { public function testShareInvalidShareType() { $this->expectException(new Exception('Share type foobar is not valid for test.txt')); OCP\Share::shareItem('test', 'test.txt', 'foobar', $this->user2, OCP\Share::PERMISSION_READ); - } public function testInvalidItemType() { @@ -131,6 +134,13 @@ class Test_Share extends UnitTestCase { } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); } + $message = 'Sharing foobar failed, because the sharing backend for test could not find its source'; + try { + OCP\Share::shareItem('test', 'foobar', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } // Valid share $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); @@ -148,16 +158,22 @@ class Test_Share extends UnitTestCase { $this->assertEqual($exception->getMessage(), $message); } - // Invalid item - $message = 'Sharing foobar failed, because the sharing backend for test could not find its source'; + // Attempt to share back + OC_User::setUserId($this->user2); + $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer'; try { - OCP\Share::shareItem('test', 'foobar', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); } + // Unshare + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2)); + // Attempt reshare without share permission + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); OC_User::setUserId($this->user2); $message = 'Sharing test.txt failed, because resharing is not allowed'; try { @@ -235,6 +251,9 @@ class Test_Share extends UnitTestCase { $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt')); // Remove user + OC_User::deleteUser($this->user1); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test1.txt')); } public function testShareWithGroup() { @@ -272,18 +291,94 @@ class Test_Share extends UnitTestCase { $this->assertEqual($exception->getMessage(), $message); } + // Attempt to share back to owner of group share + OC_User::setUserId($this->user2); + $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer'; + try { + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Attempt to share back to group + $message = 'Sharing test.txt failed, because the item was orignally shared with the group '.$this->group1; + try { + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + + // Attempt to share back to member of group + $message = 'Sharing test.txt failed, because the user '.$this->user3.' is a member of the original group share'; + try { + OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ); + $this->fail('Exception was expected: '.$message); + } catch (Exception $exception) { + $this->assertEqual($exception->getMessage(), $message); + } + // Unshare + OC_User::setUserId($this->user1); $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1)); - // Attempt user specific target conflict - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ)); + // Valid share with same person - user then group + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE | OCP\Share::PERMISSION_SHARE)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_SHARE)); OC_User::setUserId($this->user2); - $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt')); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE | OCP\Share::PERMISSION_SHARE)); OC_User::setUserId($this->user3); $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_SHARE)); + + // Valid reshare + OC_User::setUserId($this->user2); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ)); + OC_User::setUserId($this->user4); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + + // Unshare from user only + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_SHARE)); + OC_User::setUserId($this->user4); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + + // Valid share with same person - group then user + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE | OCP\Share::PERMISSION_SHARE)); + + // Unshare from group only + OC_User::setUserId($this->user1); + $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE)); + OC_User::setUserId($this->user4); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array()); + + // Attempt user specific target conflict + OC_User::setUserId($this->user3); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt')); + + // Valid reshare + $this->assertTrue(OCP\Share::shareItem('test', 'test1.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); + OC_User::setUserId($this->user4); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test1.txt')); // Remove user from group + OC_Group::removeFromGroup($this->user2, $this->group1); + OC_User::setUserId($this->user2); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + OC_User::setUserId($this->user4); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array()); // Add user to group -- cgit v1.2.3 From 5eca531f99f9615d1a09bbb0b03dda2063901aa7 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 19 Aug 2012 22:14:38 -0400 Subject: Refactor again so we can tell what item is being reshared in case the same source shows up. This is the end of the share_api branch, moving to master. --- core/ajax/share.php | 2 +- lib/public/share.php | 68 ++++++++++++++++++++++++++++--------------- tests/lib/share/share.php | 74 +++++++++++++++++++++-------------------------- 3 files changed, 79 insertions(+), 65 deletions(-) (limited to 'tests') diff --git a/core/ajax/share.php b/core/ajax/share.php index 3eadff431ca..ee9700295ee 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -26,7 +26,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['item'] case 'share': if (isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) { try { - OCP\Share::shareItem($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith'], $_POST['permissions']); + OCP\Share::shareItem($_POST['itemType'], $_POST['item'], $_POST['item'], (int)$_POST['shareType'], $_POST['shareWith'], $_POST['permissions']); // TODO May need to return private link OC_JSON::success(); } catch (Exception $exception) { diff --git a/lib/public/share.php b/lib/public/share.php index d91529d7595..c57016fb984 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -139,7 +139,7 @@ class Share { * @param int CRUDS permissions * @return bool Returns true on success or false on failure */ - public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions) { + public static function shareItem($itemType, $itemName, $itemSource, $shareType, $shareWith, $permissions) { $uidOwner = \OC_User::getUser(); // Verify share type and sharing conditions are met if ($shareType === self::SHARE_TYPE_USER) { @@ -192,7 +192,7 @@ class Share { \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } - return self::shareItem($itemType, $itemSource, self::SHARE_TYPE_EMAIL, $details['EMAIL'], $permissions); + return self::shareItem($itemType, $itemName, $itemSource, self::SHARE_TYPE_EMAIL, $details['EMAIL'], $permissions); } else { // Future share types need to include their own conditions $message = 'Share type '.$shareType.' is not valid for '.$itemSource; @@ -223,7 +223,7 @@ class Share { array_push($files, $children); } else { // Pass on to put() to check if this item should be converted, the item won't be inserted into the database unless it can be converted - self::put('file', $name, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder); + self::put('file', $name, $name, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder); } } return true; @@ -231,7 +231,7 @@ class Share { return false; } else { // Put the item into the database - return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions); + return self::put($itemType, $itemName, $itemSource, $shareType, $shareWith, $uidOwner, $permissions); } } @@ -406,6 +406,7 @@ class Share { $where .= 'WHERE file_target IS NOT NULL'; } $fileDependent = true; + $queryArgs = array(); } else { $fileDependent = false; $root = ''; @@ -481,9 +482,10 @@ class Share { $queryArgs[] = $item; } if ($includeCollections && $collectionTypes = self::getCollectionItemTypes($itemType)) { - $placeholders = join(',', array_fill(0, count($collectionTypes), '?')); - $where .= " OR item_type IN ('".$placeholders."')"; - $queryArgs = array_merge($query_args, $collectionTypes); + // TODO Bart - this doesn't work with only one argument +// $placeholders = join(',', array_fill(0, count($collectionTypes), '?')); +// $where .= " OR item_type IN ('".$placeholders."')"; +// $queryArgs = array_merge($queryArgs, $collectionTypes); } } if ($limit != -1 && !$includeCollections) { @@ -529,26 +531,37 @@ class Share { $query = \OC_DB::prepare('SELECT '.$select.' FROM *PREFIX*share '.$where); $result = $query->execute($queryArgs); $items = array(); - $itemsSources = array(); + $targets = array(); while ($row = $result->fetchRow()) { // Filter out duplicate group shares for users with unique targets - if ($row['share_type'] == self::$shareTypeGroupUserUnique) { + if ($row['share_type'] == self::$shareTypeGroupUserUnique && isset($items[$row['parent']])) { + $row['share_type'] = self::SHARE_TYPE_GROUP; + $row['share_with'] = $items[$row['parent']]['share_with']; // Remove the parent group share - if (isset($items[$row['parent']])) { - unset($items[$row['parent']]); - } + unset($items[$row['parent']]); } else if (!isset($uidOwner)) { - // Check if the same item source already exists - if (isset($itemsSources[$row[$column]])) { + // Check if the same target already exists + if (isset($targets[$row[$column]])) { // Check if the same owner shared with the user twice through a group and user share - this is allowed - $id = $itemsSources[$row[$column]]; + $id = $targets[$row[$column]]; if ($items[$id]['uid_owner'] == $row['uid_owner']) { + // Switch to group share type to ensure resharing conditions aren't bypassed + if ($items[$id]['share_type'] != self::SHARE_TYPE_GROUP) { + $items[$id]['share_type'] = self::SHARE_TYPE_GROUP; + $items[$id]['share_with'] = $row['share_with']; + } + // Switch ids if sharing permission is granted on only one share to ensure correct parent is used if resharing + if (~(int)$items[$id]['permissions'] & self::PERMISSION_SHARE && (int)$row['permissions'] & self::PERMISSION_SHARE) { + $items[$row['id']] = $items[$id]; + unset($items[$id]); + $id = $row['id']; + } // Combine the permissions for the item $items[$id]['permissions'] |= (int)$row['permissions']; continue; } } else { - $itemsSources[$row[$column]] = $row['id']; + $targets[$row[$column]] = $row['id']; } } // Remove root from file source paths if retrieving own shared items @@ -631,7 +644,7 @@ class Share { * @param bool|array Parent folder target (optional) * @return bool Returns true on success or false on failure */ - private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder = null) { + private static function put($itemType, $itemName, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder = null) { // Check file extension for an equivalent item type to convert to if ($itemType == 'file') { $extension = strtolower(substr($itemSource, strrpos($itemSource, '.') + 1)); @@ -648,16 +661,18 @@ class Share { } $backend = self::getBackend($itemType); // Check if this is a reshare - // TODO This query has pretty bad performance if there are large collections, figure out a way to make the collection searching more efficient - if ($checkReshare = self::getItemSharedWithBySource($itemType, $itemSource, self::FORMAT_NONE, null, true)) { + if ($checkReshare = self::getItemSharedWith($itemType, $itemName, self::FORMAT_NONE, null, true)) { + // Check if attempting to share back to owner if ($checkReshare['uid_owner'] == $shareWith && $shareType == self::SHARE_TYPE_USER) { $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is the original sharer'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); + // Check if attempting to share back to group TODO Check unique user target } else if ($shareType == self::SHARE_TYPE_GROUP && $checkReshare['share_with'] == $shareWith['group']) { $message = 'Sharing '.$itemSource.' failed, because the item was orignally shared with the group '.$shareWith['group']; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); + // Check if attempting to share back a group share to a member of the same group } else if (($checkReshare['share_type'] == self::SHARE_TYPE_GROUP || $checkReshare['share_type'] == self::$shareTypeGroupUserUnique) && $shareType == self::SHARE_TYPE_USER) { if ($checkReshare['share_type'] == self::$shareTypeGroupUserUnique) { $query = \OC_DB::prepare('SELECT share_with FROM *PREFIX*share WHERE id = ?'); @@ -670,7 +685,9 @@ class Share { \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } - } else if ((int)$checkReshare['permissions'] & self::PERMISSION_SHARE) { + } + // Check if share permissions is granted + if ((int)$checkReshare['permissions'] & self::PERMISSION_SHARE) { if (~(int)$checkReshare['permissions'] & $permissions) { $message = 'Sharing '.$itemSource.' failed, because the permissions exceed permissions granted to '.$uidOwner; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); @@ -679,6 +696,8 @@ class Share { // TODO Don't check if inside folder $parent = $checkReshare['id']; $itemSource = $checkReshare['item_source']; + // TODO Suggest item/file target + $suggestedItemTarget = $checkReshare['item_target']; $fileSource = $checkReshare['file_source']; $filePath = $checkReshare['file_target']; } @@ -808,6 +827,9 @@ class Share { * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_PRIVATE_LINK * @param string User or group the item is being shared with * @return string Item target + * + * TODO Use a suggested item target by default + * */ private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner) { $backend = self::getBackend($itemType); @@ -883,7 +905,7 @@ class Share { $query = \OC_DB::prepare('SELECT id FROM *PREFIX*share WHERE parent IN ('.$parents.') AND uid_owner = ?'); $result = $query->execute(array($uidOwner)); } else { - $query = \OC_DB::prepare('SELECT id, item_type, item_source, parent, uid_owner FROM *PREFIX*share WHERE parent IN ('.$parents.')'); + $query = \OC_DB::prepare('SELECT id, item_type, item_target, parent, uid_owner FROM *PREFIX*share WHERE parent IN ('.$parents.')'); $result = $query->execute(); } // Reset parents array, only go through loop again if items are found @@ -891,8 +913,8 @@ class Share { while ($item = $result->fetchRow()) { // Search for a duplicate parent share, this occurs when an item is shared to the same user through a group and user or the same item is shared by different users $userAndGroups = array_merge(array($item['uid_owner']), \OC_Group::getUserGroups($item['uid_owner'])); - $query = \OC_DB::prepare("SELECT id, permissions FROM *PREFIX*share WHERE item_type = ? AND item_source = ? AND share_type IN (?,?,?) AND share_with IN ('".implode("','", $userAndGroups)."') AND uid_owner != ? AND id != ?"); - $duplicateParent = $query->execute(array($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique, $item['uid_owner'], $item['parent']))->fetchRow(); + $query = \OC_DB::prepare("SELECT id, permissions FROM *PREFIX*share WHERE item_type = ? AND item_target = ? AND share_type IN (?,?,?) AND share_with IN ('".implode("','", $userAndGroups)."') AND uid_owner != ? AND id != ?"); + $duplicateParent = $query->execute(array($item['item_type'], $item['item_target'], self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique, $item['uid_owner'], $item['parent']))->fetchRow(); if ($duplicateParent) { // Change the parent to the other item id if share permission is granted if ($duplicateParent['permissions'] & self::PERMISSION_SHARE) { diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index 4e48ab09c6f..89f0fbc976c 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -63,19 +63,13 @@ class Test_Share extends UnitTestCase { public function testShareInvalidShareType() { $this->expectException(new Exception('Share type foobar is not valid for test.txt')); - OCP\Share::shareItem('test', 'test.txt', 'foobar', $this->user2, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', 'foobar', $this->user2, OCP\Share::PERMISSION_READ); } public function testInvalidItemType() { $message = 'Sharing backend for foobar not found'; try { - OCP\Share::shareItem('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); - $this->fail('Exception was expected: '.$message); - } catch (Exception $exception) { - $this->assertEqual($exception->getMessage(), $message); - } - try { - OCP\Share::shareItem('foobar', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('foobar', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); @@ -122,28 +116,28 @@ class Test_Share extends UnitTestCase { // Invalid shares $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the item owner'; try { - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); } $message = 'Sharing test.txt failed, because the user foobar does not exist'; try { - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, 'foobar', OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, 'foobar', OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); } $message = 'Sharing foobar failed, because the sharing backend for test could not find its source'; try { - OCP\Share::shareItem('test', 'foobar', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'foobar', 'foobar', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); } // Valid share - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); $this->assertEqual(OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); OC_User::setUserId($this->user2); $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); @@ -152,7 +146,7 @@ class Test_Share extends UnitTestCase { OC_User::setUserId($this->user1); $message = 'Sharing test.txt failed, because this item is already shared with '.$this->user2; try { - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); @@ -162,7 +156,7 @@ class Test_Share extends UnitTestCase { OC_User::setUserId($this->user2); $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer'; try { - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); @@ -173,11 +167,11 @@ class Test_Share extends UnitTestCase { $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2)); // Attempt reshare without share permission - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); OC_User::setUserId($this->user2); $message = 'Sharing test.txt failed, because resharing is not allowed'; try { - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); @@ -191,14 +185,14 @@ class Test_Share extends UnitTestCase { OC_User::setUserId($this->user2); $message = 'Sharing test.txt failed, because the permissions exceed permissions granted to '.$this->user2; try { - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); } // Valid reshare - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE)); $this->assertEqual(OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); OC_User::setUserId($this->user3); $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); @@ -234,7 +228,7 @@ class Test_Share extends UnitTestCase { OC_User::setUserId($this->user1); $this->assertTrue(OCP\Share::setPermissions('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); OC_User::setUserId($this->user2); - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ)); OC_User::setUserId($this->user1); $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2)); OC_User::setUserId($this->user2); @@ -244,9 +238,9 @@ class Test_Share extends UnitTestCase { // Attempt target conflict OC_User::setUserId($this->user1); - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); OC_User::setUserId($this->user3); - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ)); OC_User::setUserId($this->user2); $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt')); @@ -260,21 +254,21 @@ class Test_Share extends UnitTestCase { // Invalid shares $message = 'Sharing test.txt failed, because the group foobar does not exist'; try { - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, 'foobar', OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, 'foobar', OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); } $message = 'Sharing test.txt failed, because '.$this->user1.' is not a member of the group '.$this->group2; try { - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group2, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group2, OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); } // Valid share - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ)); $this->assertEqual(OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); OC_User::setUserId($this->user2); $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE), array('test.txt')); @@ -285,7 +279,7 @@ class Test_Share extends UnitTestCase { OC_User::setUserId($this->user1); $message = 'Sharing test.txt failed, because this item is already shared with '.$this->group1; try { - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); @@ -295,7 +289,7 @@ class Test_Share extends UnitTestCase { OC_User::setUserId($this->user2); $message = 'Sharing test.txt failed, because the user '.$this->user1.' is the original sharer'; try { - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user1, OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); @@ -304,7 +298,7 @@ class Test_Share extends UnitTestCase { // Attempt to share back to group $message = 'Sharing test.txt failed, because the item was orignally shared with the group '.$this->group1; try { - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); @@ -313,7 +307,7 @@ class Test_Share extends UnitTestCase { // Attempt to share back to member of group $message = 'Sharing test.txt failed, because the user '.$this->user3.' is a member of the original group share'; try { - OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ); + OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user3, OCP\Share::PERMISSION_READ); $this->fail('Exception was expected: '.$message); } catch (Exception $exception) { $this->assertEqual($exception->getMessage(), $message); @@ -324,18 +318,18 @@ class Test_Share extends UnitTestCase { $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1)); // Valid share with same person - user then group - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE | OCP\Share::PERMISSION_SHARE)); - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_SHARE)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE | OCP\Share::PERMISSION_SHARE)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE)); OC_User::setUserId($this->user2); $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE | OCP\Share::PERMISSION_SHARE)); OC_User::setUserId($this->user3); $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); - $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_SHARE)); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE)); // Valid reshare OC_User::setUserId($this->user2); - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ)); OC_User::setUserId($this->user4); $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); @@ -343,33 +337,31 @@ class Test_Share extends UnitTestCase { OC_User::setUserId($this->user1); $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2)); OC_User::setUserId($this->user2); - $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_SHARE)); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE)); OC_User::setUserId($this->user4); - $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); + $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array()); // Valid share with same person - group then user OC_User::setUserId($this->user1); - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user2, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE)); OC_User::setUserId($this->user2); $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt')); - $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE | OCP\Share::PERMISSION_SHARE)); + $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE)); // Unshare from group only OC_User::setUserId($this->user1); $this->assertTrue(OCP\Share::unshare('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1)); OC_User::setUserId($this->user2); $this->assertEqual(OCP\Share::getItemSharedWith('test', 'test.txt', Test_Share_Backend::FORMAT_PERMISSIONS), array(OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_DELETE)); - OC_User::setUserId($this->user4); - $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array()); // Attempt user specific target conflict OC_User::setUserId($this->user3); - $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); + $this->assertTrue(OCP\Share::shareItem('test', 'test.txt', 'test.txt', OCP\Share::SHARE_TYPE_GROUP, $this->group1, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); OC_User::setUserId($this->user2); $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt')); - // Valid reshare - $this->assertTrue(OCP\Share::shareItem('test', 'test1.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); + // Valid reshare TODO Broken + $this->assertTrue(OCP\Share::shareItem('test', 'test1.txt', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE)); OC_User::setUserId($this->user4); $this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test1.txt')); -- cgit v1.2.3 From 9699ff03bd1a200fc7f73bb29173169d84009e5d Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 22 Aug 2012 11:35:30 -0400 Subject: Revert using item name, no longer allowing the same item source exist for a user --- core/ajax/share.php | 10 +++--- core/js/share.js | 45 +++++++++++++++---------- lib/public/share.php | 65 +++++++++++++++++++++-------------- tests/lib/share/backend.php | 8 +++-- tests/lib/share/share.php | 82 ++++++++++++++++++++++----------------------- 5 files changed, 118 insertions(+), 92 deletions(-) (limited to 'tests') diff --git a/core/ajax/share.php b/core/ajax/share.php index 9376f18e8ad..04294a36ac0 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -24,9 +24,9 @@ OC_JSON::checkLoggedIn(); if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSource'])) { switch ($_POST['action']) { case 'share': - if (isset($_POST['itemName']) && isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) { + if (isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) { try { - OCP\Share::shareItem($_POST['itemType'], $_POST['itemName'], $_POST['itemSource'], (int)$_POST['shareType'], $_POST['shareWith'], $_POST['permissions']); + OCP\Share::shareItem($_POST['itemType'], $_POST['itemSource'], (int)$_POST['shareType'], $_POST['shareWith'], $_POST['permissions']); // TODO May need to return private link OC_JSON::success(); } catch (Exception $exception) { @@ -56,9 +56,9 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo } break; case 'getItem': - if (isset($_GET['itemType']) && isset($_GET['itemName']) && isset($_GET['itemSource'])) { - $reshare = OCP\Share::getItemSharedWith($_GET['itemType'], $_GET['itemName'], OCP\Share::FORMAT_NONE, null, true); - if ($_GET['itemSource'] !== false) { + if (isset($_GET['itemType']) && isset($_GET['itemSource']) && isset($_GET['checkShares'])) { + $reshare = OCP\Share::getItemSharedWithBySource($_GET['itemType'], $_GET['itemSource'], OCP\Share::FORMAT_NONE, null, true); + if ($_GET['checkShares'] == "true") { $shares = OCP\Share::getItemShared($_GET['itemType'], $_GET['itemSource']); } else { $shares = false; diff --git a/core/js/share.js b/core/js/share.js index 418d18f86b7..c1d66ee9214 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -30,12 +30,14 @@ OC.Share={ } }); }, - loadItem:function(itemType, itemName, itemSource) { + loadItem:function(itemType, itemSource) { var data = ''; - if (typeof OC.Share.statuses[itemName] === 'undefined') { - itemSource = false; + if (typeof OC.Share.statuses[itemSource] === 'undefined') { + checkShares = false; + } else { + checkShares = true; } - $.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { fetch: 'getItem', itemType: itemType, itemName: itemName, itemSource: itemSource }, async: false, success: function(result) { + $.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { fetch: 'getItem', itemType: itemType, itemSource: itemSource, checkShares: checkShares }, async: false, success: function(result) { if (result && result.status === 'success') { data = result.data; } else { @@ -44,8 +46,8 @@ OC.Share={ }}); return data; }, - share:function(itemType, itemName, itemSource, shareType, shareWith, permissions, callback) { - $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'share', itemType: itemType, itemName: itemName, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) { + share:function(itemType, itemSource, shareType, shareWith, permissions, callback) { + $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'share', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) { if (result && result.status === 'success') { if (callback) { callback(result.data); @@ -73,9 +75,9 @@ OC.Share={ } }); }, - showDropDown:function(itemType, itemName, itemSource, appendTo, privateLink, possiblePermissions) { - var data = OC.Share.loadItem(itemType, itemName, itemSource); - var html = '