]> source.dussan.org Git - nextcloud-server.git/commitdiff
Disallow to share with the owner of the resource
authorThomas Müller <thomas.mueller@tmit.eu>
Mon, 1 Feb 2016 10:47:41 +0000 (11:47 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Wed, 3 Feb 2016 16:18:22 +0000 (17:18 +0100)
apps/dav/lib/dav/sharing/backend.php

index 2d810a43f9da9137b1e9905c446e77163d65734f..a68e484902c4bdda8099a88461cfa4d15d1021c2 100644 (file)
@@ -58,7 +58,7 @@ class Backend {
                        $this->shareWith($shareable, $element);
                }
                foreach($remove as $element) {
-                       $this->unshare($shareable->getResourceId(), $element);
+                       $this->unshare($shareable, $element);
                }
        }
 
@@ -73,8 +73,13 @@ class Backend {
                        return;
                }
 
+               // don't share with owner
+               if ($shareable->getOwner() === $parts[1]) {
+                       return;
+               }
+
                // remove the share if it already exists
-               $this->unshare($shareable->getResourceId(), $element['href']);
+               $this->unshare($shareable, $element['href']);
                $access = self::ACCESS_READ;
                if (isset($element['readOnly'])) {
                        $access = $element['readOnly'] ? self::ACCESS_READ : self::ACCESS_READ_WRITE;
@@ -92,18 +97,23 @@ class Backend {
        }
 
        /**
-        * @param int $resourceId
+        * @param IShareable $shareable
         * @param string $element
         */
-       private function unshare($resourceId, $element) {
+       private function unshare($shareable, $element) {
                $parts = explode(':', $element, 2);
                if ($parts[0] !== 'principal') {
                        return;
                }
 
+               // don't share with owner
+               if ($shareable->getOwner() === $parts[1]) {
+                       return;
+               }
+
                $query = $this->db->getQueryBuilder();
                $query->delete('dav_shares')
-                       ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId)))
+                       ->where($query->expr()->eq('resourceid', $query->createNamedParameter($shareable->getResourceId())))
                        ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType)))
                        ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($parts[1])))
                ;