summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/connector/sabre
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/connector/sabre')
-rw-r--r--apps/dav/lib/connector/sabre/filesplugin.php6
-rw-r--r--apps/dav/lib/connector/sabre/node.php50
2 files changed, 56 insertions, 0 deletions
diff --git a/apps/dav/lib/connector/sabre/filesplugin.php b/apps/dav/lib/connector/sabre/filesplugin.php
index fb2af554c68..8b54291793a 100644
--- a/apps/dav/lib/connector/sabre/filesplugin.php
+++ b/apps/dav/lib/connector/sabre/filesplugin.php
@@ -45,6 +45,7 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
+ const SHARE_PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}share-permissions';
const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
const GETETAG_PROPERTYNAME = '{DAV:}getetag';
@@ -116,6 +117,7 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
$server->protectedProperties[] = self::FILEID_PROPERTYNAME;
$server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
$server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
+ $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
$server->protectedProperties[] = self::SIZE_PROPERTYNAME;
$server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
$server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
@@ -245,6 +247,10 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
return $perms;
});
+ $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node) {
+ return $node->getSharePermissions();
+ });
+
$propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
return $node->getETag();
});
diff --git a/apps/dav/lib/connector/sabre/node.php b/apps/dav/lib/connector/sabre/node.php
index 95a5f0a8749..9867fe66cd3 100644
--- a/apps/dav/lib/connector/sabre/node.php
+++ b/apps/dav/lib/connector/sabre/node.php
@@ -30,6 +30,7 @@
namespace OCA\DAV\Connector\Sabre;
+use OC\Files\Mount\MoveableMount;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
@@ -214,6 +215,55 @@ abstract class Node implements \Sabre\DAV\INode {
}
/**
+ * @return int
+ */
+ public function getSharePermissions() {
+ $storage = $this->info->getStorage();
+
+ $path = $this->info->getInternalPath();
+
+ if ($storage->instanceOfStorage('\OC\Files\Storage\Shared')) {
+ /** @var \OC\Files\Storage\Shared $storage */
+ $permissions = (int)$storage->getShare()['permissions'];
+ } else {
+ $permissions = $storage->getPermissions($path);
+ }
+
+ /*
+ * We can always share non moveable mount points with DELETE and UPDATE
+ * Eventually we need to do this properly
+ */
+ $mountpoint = $this->info->getMountPoint();
+ if (!($mountpoint instanceof MoveableMount)) {
+ $mountpointpath = $mountpoint->getMountPoint();
+ if (substr($mountpointpath, -1) === '/') {
+ $mountpointpath = substr($mountpointpath, 0, -1);
+ }
+
+ if ($mountpointpath === $this->info->getPath()) {
+ $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
+ }
+ }
+
+ /*
+ * Without sharing permissions there are also no other permissions
+ */
+ if (!($permissions & \OCP\Constants::PERMISSION_SHARE) ||
+ !($permissions & \OCP\Constants::PERMISSION_READ)) {
+ return 0;
+ }
+
+ /*
+ * Files can't have create or delete permissions
+ */
+ if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
+ $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE);
+ }
+
+ return $permissions;
+ }
+
+ /**
* @return string
*/
public function getDavPermissions() {