summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoricewind1991 <icewind1991@gmail.com>2013-05-30 05:54:29 -0700
committericewind1991 <icewind1991@gmail.com>2013-05-30 05:54:29 -0700
commitaa1c5a5d63865fc35783dbbff3af0cc64a1bb4cf (patch)
tree176cc81cf888633c328f2cc67f17af9103431f0e
parent8e1d9261aa7cd9f9855f038feb5a9d8bbcc48a18 (diff)
parent5a47054505bfca3c3ba6e947cac6b963cd45b416 (diff)
downloadnextcloud-server-aa1c5a5d63865fc35783dbbff3af0cc64a1bb4cf.tar.gz
nextcloud-server-aa1c5a5d63865fc35783dbbff3af0cc64a1bb4cf.zip
Merge pull request #3529 from owncloud/folder-permissions
Cache: provide a function to get the permissions of all files in a folder with one query
-rw-r--r--apps/files_sharing/lib/permissions.php25
-rw-r--r--apps/files_sharing/lib/share/file.php7
-rw-r--r--lib/files/cache/permissions.php20
-rw-r--r--lib/files/view.php22
4 files changed, 62 insertions, 12 deletions
diff --git a/apps/files_sharing/lib/permissions.php b/apps/files_sharing/lib/permissions.php
index 6747faa4d43..b6638564cd8 100644
--- a/apps/files_sharing/lib/permissions.php
+++ b/apps/files_sharing/lib/permissions.php
@@ -71,6 +71,28 @@ class Shared_Permissions extends Permissions {
}
/**
+ * get the permissions for all files in a folder
+ *
+ * @param int $parentId
+ * @param string $user
+ * @return int[]
+ */
+ public function getDirectoryPermissions($parentId, $user) {
+ // Root of the Shared folder
+ if ($parentId === -1) {
+ return \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_PERMISSIONS);
+ }
+ $permissions = $this->get($parentId, $user);
+ $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `parent` = ?');
+ $result = $query->execute(array($parentId));
+ $filePermissions = array();
+ while ($row = $result->fetchRow()) {
+ $filePermissions[$row['fileid']] = $permissions;
+ }
+ return $filePermissions;
+ }
+
+ /**
* remove the permissions for a file
*
* @param int $fileId
@@ -83,4 +105,5 @@ class Shared_Permissions extends Permissions {
public function removeMultiple($fileIds, $user) {
// Not a valid action for Shared Permissions
}
-}
+
+} \ No newline at end of file
diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php
index 62948651806..07e7a4ca0c5 100644
--- a/apps/files_sharing/lib/share/file.php
+++ b/apps/files_sharing/lib/share/file.php
@@ -26,6 +26,7 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
const FORMAT_FILE_APP_ROOT = 2;
const FORMAT_OPENDIR = 3;
const FORMAT_GET_ALL = 4;
+ const FORMAT_PERMISSIONS = 5;
private $path;
@@ -125,6 +126,12 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
$ids[] = $item['file_source'];
}
return $ids;
+ } else if ($format === self::FORMAT_PERMISSIONS) {
+ $filePermissions = array();
+ foreach ($items as $item) {
+ $filePermissions[$item['file_source']] = $item['permissions'];
+ }
+ return $filePermissions;
}
return array();
}
diff --git a/lib/files/cache/permissions.php b/lib/files/cache/permissions.php
index faa5ff5eacc..29c30b0f36c 100644
--- a/lib/files/cache/permissions.php
+++ b/lib/files/cache/permissions.php
@@ -86,6 +86,26 @@ class Permissions {
}
/**
+ * get the permissions for all files in a folder
+ *
+ * @param int $parentId
+ * @param string $user
+ * @return int[]
+ */
+ public function getDirectoryPermissions($parentId, $user) {
+ $query = \OC_DB::prepare('SELECT `*PREFIX*permissions`.`fileid`, `permissions`
+ FROM `*PREFIX*permissions` INNER JOIN `*PREFIX*filecache` ON `*PREFIX*permissions`.`fileid` = `*PREFIX*filecache`.`fileid`
+ WHERE `*PREFIX*filecache`.`parent` = ? AND `*PREFIX*permissions`.`user` = ?');
+
+ $result = $query->execute(array($parentId, $user));
+ $filePermissions = array();
+ while ($row = $result->fetchRow()) {
+ $filePermissions[$row['fileid']] = $row['permissions'];
+ }
+ return $filePermissions;
+ }
+
+ /**
* remove the permissions for a file
*
* @param int $fileId
diff --git a/lib/files/view.php b/lib/files/view.php
index 8e7727d335c..ecb0f30400a 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -267,7 +267,7 @@ class View {
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data)
and Filesystem::isValidPath($path)
- and ! Filesystem::isFileBlacklisted($path)
+ and !Filesystem::isFileBlacklisted($path)
) {
$path = $this->getRelativePath($absolutePath);
$exists = $this->file_exists($path);
@@ -344,7 +344,7 @@ class View {
\OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2)
and Filesystem::isValidPath($path2)
and Filesystem::isValidPath($path1)
- and ! Filesystem::isFileBlacklisted($path2)
+ and !Filesystem::isFileBlacklisted($path2)
) {
$path1 = $this->getRelativePath($absolutePath1);
$path2 = $this->getRelativePath($absolutePath2);
@@ -371,7 +371,7 @@ class View {
list(, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2);
if ($storage) {
$result = $storage->rename($internalPath1, $internalPath2);
- \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
+ \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
} else {
$result = false;
}
@@ -418,7 +418,7 @@ class View {
\OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2)
and Filesystem::isValidPath($path2)
and Filesystem::isValidPath($path1)
- and ! Filesystem::isFileBlacklisted($path2)
+ and !Filesystem::isFileBlacklisted($path2)
) {
$path1 = $this->getRelativePath($absolutePath1);
$path2 = $this->getRelativePath($absolutePath2);
@@ -632,7 +632,7 @@ class View {
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam)
and Filesystem::isValidPath($path)
- and ! Filesystem::isFileBlacklisted($path)
+ and !Filesystem::isFileBlacklisted($path)
) {
$path = $this->getRelativePath($absolutePath);
if ($path == null) {
@@ -760,7 +760,7 @@ class View {
}
}
- $data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data);
+ $data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data);
return $data;
}
@@ -797,18 +797,18 @@ class View {
}
$files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter
+ $permissions = $permissionsCache->getDirectoryPermissions($cache->getId($internalPath), $user);
$ids = array();
foreach ($files as $i => $file) {
$files[$i]['type'] = $file['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
$ids[] = $file['fileid'];
- $permissions = $permissionsCache->get($file['fileid'], $user);
- if ($permissions === -1) {
- $permissions = $storage->getPermissions($file['path']);
- $permissionsCache->set($file['fileid'], $user, $permissions);
+ if (!isset($permissions[$file['fileid']])) {
+ $permissions[$file['fileid']] = $storage->getPermissions($file['path']);
+ $permissionsCache->set($file['fileid'], $user, $permissions[$file['fileid']]);
}
- $files[$i]['permissions'] = $permissions;
+ $files[$i]['permissions'] = $permissions[$file['fileid']];
}
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders