diff options
author | Michael Gapczynski <mtgap@owncloud.com> | 2012-07-24 17:42:07 -0400 |
---|---|---|
committer | Michael Gapczynski <mtgap@owncloud.com> | 2012-07-24 20:10:28 -0400 |
commit | f7b89f047504740224f664917d6588c1fe203877 (patch) | |
tree | 5cce4d672681a025466dce8b7237cf17b652eab9 | |
parent | c60c6024a7f02fc9548bc8b8f45f02efa1f9346f (diff) | |
download | nextcloud-server-f7b89f047504740224f664917d6588c1fe203877.tar.gz nextcloud-server-f7b89f047504740224f664917d6588c1fe203877.zip |
Add CRUDS permissions calls to filesystem, deprecate is_readable() and is_writable()
-rw-r--r-- | apps/files_archive/lib/storage.php | 4 | ||||
-rw-r--r-- | apps/files_external/lib/amazons3.php | 4 | ||||
-rwxr-xr-x | apps/files_external/lib/dropbox.php | 4 | ||||
-rw-r--r-- | apps/files_external/lib/google.php | 4 | ||||
-rw-r--r-- | apps/files_external/lib/streamwrapper.php | 4 | ||||
-rw-r--r-- | apps/files_external/lib/swift.php | 4 | ||||
-rw-r--r-- | apps/files_external/lib/webdav.php | 4 | ||||
-rw-r--r-- | apps/files_sharing/sharedstorage.php | 47 | ||||
-rw-r--r-- | lib/filestorage.php | 7 | ||||
-rw-r--r-- | lib/filestorage/common.php | 13 | ||||
-rw-r--r-- | lib/filestorage/local.php | 4 | ||||
-rw-r--r-- | lib/filesystem.php | 21 | ||||
-rw-r--r-- | lib/filesystemview.php | 25 |
13 files changed, 99 insertions, 46 deletions
diff --git a/apps/files_archive/lib/storage.php b/apps/files_archive/lib/storage.php index 86761663611..0723ae08ccf 100644 --- a/apps/files_archive/lib/storage.php +++ b/apps/files_archive/lib/storage.php @@ -78,10 +78,10 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{ return $this->archive->fileExists($path.'/')?'dir':'file'; } } - public function is_readable($path){ + public function isReadable($path){ return is_readable($this->path); } - public function is_writable($path){ + public function isUpdatable($path){ return is_writable($this->path); } public function file_exists($path){ diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php index 9feb490dac0..3c2e3330175 100644 --- a/apps/files_external/lib/amazons3.php +++ b/apps/files_external/lib/amazons3.php @@ -134,12 +134,12 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common { return false; } - public function is_readable($path) { + public function isReadable($path) { // TODO Check acl and determine who grantee is return true; } - public function is_writable($path) { + public function isUpdatable($path) { // TODO Check acl and determine who grantee is return true; } diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php index 35663d431f8..5d726feddc5 100755 --- a/apps/files_external/lib/dropbox.php +++ b/apps/files_external/lib/dropbox.php @@ -118,11 +118,11 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { return false; } - public function is_readable($path) { + public function isReadable($path) { return $this->file_exists($path); } - public function is_writable($path) { + public function isUpdatable($path) { return $this->file_exists($path); } diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index 41b560ae84e..1346d899269 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -280,11 +280,11 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { return false; } - public function is_readable($path) { + public function isReadable($path) { return true; } - public function is_writable($path) { + public function isUpdatable($path) { if ($path == '' || $path == '/') { return true; } else if ($entry = $this->getResource($path)) { diff --git a/apps/files_external/lib/streamwrapper.php b/apps/files_external/lib/streamwrapper.php index 7d56445361e..467c5a5b845 100644 --- a/apps/files_external/lib/streamwrapper.php +++ b/apps/files_external/lib/streamwrapper.php @@ -32,11 +32,11 @@ abstract class OC_FileStorage_StreamWrapper extends OC_Filestorage_Common{ return filetype($this->constructUrl($path)); } - public function is_readable($path){ + public function isReadable($path){ return true;//not properly supported } - public function is_writable($path){ + public function isUpdatable($path){ return true;//not properly supported } diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index 58b95a6ae01..94ccde1ff8f 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -353,11 +353,11 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{ } } - public function is_readable($path){ + public function isReadable($path){ return true; } - public function is_writable($path){ + public function isUpdatable($path){ return true; } diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index 3d13518f57b..675fb9518b1 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -109,11 +109,11 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{ } } - public function is_readable($path){ + public function isReadable($path){ return true;//not properly supported } - public function is_writable($path){ + public function isUpdatable($path){ return true;//not properly supported } diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index e3519306e02..a4510f2e77c 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -107,7 +107,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { } public function mkdir($path) { - if ($path == '' || $path == '/' || !$this->is_writable(dirname($path))) { + if ($path == '' || $path == '/' || !$this->isCreatable(dirname($path))) { return false; } else if ($source = $this->getSourcePath($path)) { $storage = OC_Filesystem::getStorage($source); @@ -117,7 +117,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { } public function rmdir($path) { - if (($source = $this->getSourcePath($path)) && ($this->getPermissions($path) & OCP\Share::PERMISSION_DELETE)) { + if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) { $storage = OC_Filesystem::getStorage($source); return $storage->rmdir($this->getInternalPath($source)); } @@ -187,25 +187,26 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { return false; } - public function is_readable($path) { + public function isCreatable($path) { + return ($this->getPermissions($path) & OCP\Share::PERMISSION_CREATE); + } + + public function isReadable($path) { return $this->file_exists($path); } - - public function is_writable($path) { - if ($path == '' || $path == '/') { - return false; - // Folders need CREATE permission to be writable - } else if ($this->is_dir($path)) { - if ($this->getPermissions($path) & OCP\Share::PERMISSION_CREATE) { - return true; - } - // Files need UPDATE permission to be writable - } else if ($this->getPermissions($path) & OCP\Share::PERMISSION_UPDATE) { - return true; - } - return false; + + public function isUpdatable($path) { + return ($this->getPermissions($path) & OCP\Share::PERMISSION_UPDATE); } - + + public function isDeletable($path) { + return ($this->getPermissions($path) & OCP\Share::PERMISSION_DELETE); + } + + public function isSharable($path) { + return ($this->getPermissions($path) & OCP\Share::PERMISSION_SHARE); + } + public function file_exists($path) { if ($path == '' || $path == '/') { return true; @@ -292,7 +293,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { public function unlink($path) { // Delete the file if DELETE permission is granted - if (($source = $this->getSourcePath($path)) && ($this->getPermissions($path) & OCP\Share::PERMISSION_DELETE)) { + if (($source = $this->getSourcePath($path)) && $this->isDeletable($path)) { $storage = OC_Filesystem::getStorage($source); return $storage->unlink($this->getInternalPath($source)); } @@ -305,17 +306,15 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { $root2 = substr($path2, 0, strpos($path2, '/')); // Moving/renaming is only allowed within the same shared folder if ($root1 == $root2) { - $permissions1 = $this->getPermissions($path1); - $permissions2 = $this->getPermissions(dirname($path2)); $storage = OC_Filesystem::getStorage($oldSource); $newSource = substr($oldSource, 0, strpos($oldSource, $root1)).$path2; if (dirname($path1) == dirname($path2)) { // Rename the file if UPDATE permission is granted - if ($permissions1 & OCP\Share::PERMISSION_UPDATE) { + if ($this->isUpdatable($path1)) { return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource)); } // Move the file if DELETE and CREATE permissions are granted - } else if (($permissions1 & OCP\Share::PERMISSION_DELETE) && ($permissions2 & OCP\Share::PERMISSION_CREATE)) { + } else if ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) { return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource)); } } @@ -325,7 +324,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { public function copy($path1, $path2) { // Copy the file if CREATE permission is granted - if (($source = $this->getSourcePath($path1)) && ($this->getPermissions(dirname($path2)) & OCP\Share::PERMISSION_CREATE)) { + if (($source = $this->getSourcePath($path1)) && $this->isCreatable(dirname($path2))) { $source = $this->fopen($path1, 'r'); $target = $this->fopen($path2, 'w'); return OC_Helper::streamCopy($source, $target); diff --git a/lib/filestorage.php b/lib/filestorage.php index 71ef4aed00b..c104fca87fe 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -33,8 +33,11 @@ abstract class OC_Filestorage{ abstract public function stat($path); abstract public function filetype($path); abstract public function filesize($path); - abstract public function is_readable($path); - abstract public function is_writable($path); + abstract public function isCreatable($path); + abstract public function isReadable($path); + abstract public function isUpdatable($path); + abstract public function isDeletable($path); + abstract public function isSharable($path); abstract public function file_exists($path); abstract public function filectime($path); abstract public function filemtime($path); diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index ba78fca80e5..633c2fdfc76 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -54,8 +54,17 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { return $stat['size']; } } -// abstract public function is_readable($path); -// abstract public function is_writable($path); + public function isCreatable($path) { + return $this->isUpdatable($path); + } +// abstract public function isReadable($path); +// abstract public function isUpdatable($path); + public function isDeletable($path) { + return $this->isUpdatable($path); + } + public function isSharable($path) { + return $this->isReadable($path); + } // abstract public function file_exists($path); public function filectime($path) { $stat = $this->stat($path); diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index b2eba051515..b8b9cd0812c 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -46,10 +46,10 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{ return filesize($this->datadir.$path); } } - public function is_readable($path){ + public function isReadable($path){ return is_readable($this->datadir.$path); } - public function is_writable($path){ + public function isUpdatable($path){ return is_writable($this->datadir.$path); } public function file_exists($path){ diff --git a/lib/filesystem.php b/lib/filesystem.php index 65318fa3ab6..5dfcaa107b8 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -421,12 +421,33 @@ class OC_Filesystem{ static public function readfile($path){ return self::$defaultInstance->readfile($path); } + /** + * @deprecated Replaced by isReadable() as part of CRUDS + */ static public function is_readable($path){ return self::$defaultInstance->is_readable($path); } + /** + * @deprecated Replaced by isCreatable(), isUpdatable(), isDeletable() as part of CRUDS + */ static public function is_writable($path){ return self::$defaultInstance->is_writable($path); } + static public function isCreatable($path) { + return self::$defaultInstance->isCreatable($path); + } + static public function isReadable($path) { + return self::$defaultInstance->isReadable($path); + } + static public function isUpdatable($path) { + return self::$defaultInstance->isUpdatable($path); + } + static public function isDeletable($path) { + return self::$defaultInstance->isDeletable($path); + } + static public function isSharable($path) { + return self::$defaultInstance->isSharable($path); + } static public function file_exists($path){ return self::$defaultInstance->file_exists($path); } diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 448663bb081..05731299467 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -197,11 +197,32 @@ class OC_FilesystemView { } return false; } + /** + * @deprecated Replaced by isReadable() as part of CRUDS + */ public function is_readable($path){ - return $this->basicOperation('is_readable',$path); + return $this->basicOperation('isReadable',$path); } + /** + * @deprecated Replaced by isCreatable(), isUpdatable(), isDeletable() as part of CRUDS + */ public function is_writable($path){ - return $this->basicOperation('is_writable',$path); + return $this->basicOperation('isUpdatable',$path); + } + public function isCreatable($path) { + return $this->basicOperation('isCreatable', $path); + } + public function isReadable($path) { + return $this->basicOperation('isReadable', $path); + } + public function isUpdatable($path) { + return $this->basicOperation('isUpdatable', $path); + } + public function isDeletable($path) { + return $this->basicOperation('isDeletable', $path); + } + public function isSharable($path) { + return $this->basicOperation('isSharable', $path); } public function file_exists($path){ if($path=='/'){ |