// 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('');
*/
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();
--- /dev/null
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@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;
+ }
+}
--- /dev/null
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@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);
+ }
+}
$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);