[Pkg-owncloud-commits] [owncloud] 127/223: Properly expose read only public shares as read only
David Prévot
taffit at moszumanska.debian.org
Sun Jun 22 01:54:14 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit e7b58ed2bdfe4bb56866e76b8fdd618946fa3c51
Author: Robin Appelman <icewind at owncloud.com>
Date: Thu Jun 12 17:53:56 2014 +0200
Properly expose read only public shares as read only
---
apps/files_sharing/ajax/shareinfo.php | 7 ++++
apps/files_sharing/lib/external/scanner.php | 4 +++
apps/files_sharing/lib/readonlycache.php | 27 ++++++++++++++
apps/files_sharing/lib/readonlywrapper.php | 56 +++++++++++++++++++++++++++++
apps/files_sharing/publicwebdav.php | 8 +++++
5 files changed, 102 insertions(+)
diff --git a/apps/files_sharing/ajax/shareinfo.php b/apps/files_sharing/ajax/shareinfo.php
index 4aefdbe..c576486 100644
--- a/apps/files_sharing/ajax/shareinfo.php
+++ b/apps/files_sharing/ajax/shareinfo.php
@@ -33,6 +33,13 @@ $linkItem = $data['linkItem'];
// Load the files
$path = $data['realPath'];
+$isWritable = $linkItem['permissions'] & \OCP\PERMISSION_CREATE;
+if (!$isWritable) {
+ \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) {
+ return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage));
+ });
+}
+
$rootInfo = \OC\Files\Filesystem::getFileInfo($path);
$rootView = new \OC\Files\View('');
diff --git a/apps/files_sharing/lib/external/scanner.php b/apps/files_sharing/lib/external/scanner.php
index 1f32d79..8fb8683 100644
--- a/apps/files_sharing/lib/external/scanner.php
+++ b/apps/files_sharing/lib/external/scanner.php
@@ -14,6 +14,10 @@ class Scanner extends \OC\Files\Cache\Scanner {
*/
protected $storage;
+ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1) {
+ $this->scanAll();
+ }
+
public function scanAll() {
$remote = $this->storage->getRemote();
$token = $this->storage->getToken();
diff --git a/apps/files_sharing/lib/readonlycache.php b/apps/files_sharing/lib/readonlycache.php
new file mode 100644
index 0000000..f129ca4
--- /dev/null
+++ b/apps/files_sharing/lib/readonlycache.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind at owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCA\Files_Sharing;
+
+use OC\Files\Cache\Cache;
+
+class ReadOnlyCache extends Cache {
+ public function get($path) {
+ $data = parent::get($path);
+ $data['permissions'] &= (\OCP\PERMISSION_READ | \OCP\PERMISSION_SHARE);
+ return $data;
+ }
+
+ public function getFolderContents($path) {
+ $content = parent::getFolderContents($path);
+ foreach ($content as &$data) {
+ $data['permissions'] &= (\OCP\PERMISSION_READ | \OCP\PERMISSION_SHARE);
+ }
+ return $content;
+ }
+}
diff --git a/apps/files_sharing/lib/readonlywrapper.php b/apps/files_sharing/lib/readonlywrapper.php
new file mode 100644
index 0000000..45ed3fd
--- /dev/null
+++ b/apps/files_sharing/lib/readonlywrapper.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind at owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCA\Files_Sharing;
+
+use OC\Files\Storage\Wrapper\Wrapper;
+
+class ReadOnlyWrapper extends Wrapper {
+ public function isUpdatable($path) {
+ return false;
+ }
+
+ public function isCreatable($path) {
+ return false;
+ }
+
+ public function isDeletable($path) {
+ return false;
+ }
+
+ public function getPermissions($path) {
+ return $this->storage->getPermissions($path) & (\OCP\PERMISSION_READ | \OCP\PERMISSION_SHARE);
+ }
+
+ public function rename($path1, $path2) {
+ return false;
+ }
+
+ public function touch($path, $mtime = null) {
+ return false;
+ }
+
+ public function mkdir($path) {
+ return false;
+ }
+
+ public function rmdir($path) {
+ return false;
+ }
+
+ public function unlink($path) {
+ return false;
+ }
+
+ public function getCache($path = '', $storage = null) {
+ if (!$storage) {
+ $storage = $this;
+ }
+ return new ReadOnlyCache($storage);
+ }
+}
diff --git a/apps/files_sharing/publicwebdav.php b/apps/files_sharing/publicwebdav.php
index b4f56ee..f33b920 100644
--- a/apps/files_sharing/publicwebdav.php
+++ b/apps/files_sharing/publicwebdav.php
@@ -37,7 +37,15 @@ $server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('webdav'));
$server->subscribeEvent('beforeMethod', function () use ($server, $objectTree, $authBackend) {
$share = $authBackend->getShare();
$owner = $share['uid_owner'];
+ $isWritable = $share['permissions'];
$fileId = $share['file_source'];
+
+ if (!$isWritable) {
+ \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) {
+ return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage));
+ });
+ }
+
OC_Util::setupFS($owner);
$ownerView = \OC\Files\Filesystem::getView();
$path = $ownerView->getPath($fileId);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list