]> source.dussan.org Git - nextcloud-server.git/commitdiff
[Share 2.0] Add missing post_update_permissions hook
authorRoeland Jago Douma <rullzer@owncloud.com>
Thu, 4 Feb 2016 08:53:47 +0000 (09:53 +0100)
committerRoeland Jago Douma <rullzer@owncloud.com>
Thu, 4 Feb 2016 18:18:25 +0000 (19:18 +0100)
lib/private/share20/manager.php
lib/private/share20/share.php
tests/lib/share20/managertest.php

index 6ea638b84e690942425ddb5710fff51b9649739f..2a350f02d6a2f1408ab65042e15218f0fea41bd0 100644 (file)
@@ -613,6 +613,18 @@ class Manager implements IManager {
                        ]);
                }
 
+               if ($share->getPermissions() !== $originalShare->getPermissions()) {
+                       \OC_Hook::emit('OCP\Share', 'post_update_permissions', array(
+                               'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
+                               'itemSource' => $share->getNode()->getId(),
+                               'shareType' => $share->getShareType(),
+                               'shareWith' => $share->getSharedWith(),
+                               'uidOwner' => $share->getSharedBy(),
+                               'permissions' => $share->getPermissions(),
+                               'path' => $share->getNode()->getPath(),
+                       ));
+               }
+
                return $share;
        }
 
index 448b05d20a3a1d026bf41c7d03cad0b753b5f4c1..cd30f24c42e230f7d1f5b98ad308c9ced07a9611 100644 (file)
@@ -105,6 +105,8 @@ class Share implements \OCP\Share\IShare {
         * @inheritdoc
         */
        public function setNode(Node $node) {
+               $this->fileId = null;
+               $this->nodeType = null;
                $this->node = $node;
                return $this;
        }
index 270f5da33cd61feaa0f6d79b2f0a34c708ada9ac..1cdf63aa7e5d336077784687cec0c67f1ca90ebf 100644 (file)
@@ -1870,19 +1870,24 @@ class ManagerTest extends \Test\TestCase {
 
                $originalShare = $this->manager->newShare();
                $originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)
-                       ->setSharedWith('origUser');
+                       ->setSharedWith('origUser')
+                       ->setPermissions(1);
+
+               $node = $this->getMock('\OCP\Files\File');
+               $node->method('getId')->willReturn(100);
+               $node->method('getPath')->willReturn('myPath');
 
                $manager->expects($this->once())->method('canShare')->willReturn(true);
                $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
 
-               $node = $this->getMock('\OCP\Files\File');
-
                $share = $this->manager->newShare();
                $share->setProviderId('foo')
                        ->setId('42')
                        ->setShareType(\OCP\Share::SHARE_TYPE_USER)
                        ->setSharedWith('origUser')
                        ->setShareOwner('newUser')
+                       ->setSharedBy('sharer')
+                       ->setPermissions(31)
                        ->setNode($node);
 
                $this->defaultProvider->expects($this->once())
@@ -1894,6 +1899,17 @@ class ManagerTest extends \Test\TestCase {
                \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post');
                $hookListner->expects($this->never())->method('post');
 
+               $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+               \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post');
+               $hookListner2->expects($this->once())->method('post')->with([
+                       'itemType' => 'file',
+                       'itemSource' => 100,
+                       'shareType' => \OCP\Share::SHARE_TYPE_USER,
+                       'shareWith' => 'origUser',
+                       'uidOwner' => 'sharer',
+                       'permissions' => 31,
+                       'path' => 'myPath',
+               ]);
 
                $manager->updateShare($share);
        }
@@ -1911,7 +1927,8 @@ class ManagerTest extends \Test\TestCase {
 
                $originalShare = $this->manager->newShare();
                $originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
-                       ->setSharedWith('origUser');
+                       ->setSharedWith('origUser')
+                       ->setPermissions(31);
 
                $manager->expects($this->once())->method('canShare')->willReturn(true);
                $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
@@ -1924,7 +1941,8 @@ class ManagerTest extends \Test\TestCase {
                        ->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
                        ->setSharedWith('origUser')
                        ->setShareOwner('owner')
-                       ->setNode($node);
+                       ->setNode($node)
+                       ->setPermissions(31);
 
                $this->defaultProvider->expects($this->once())
                        ->method('update')
@@ -1935,6 +1953,9 @@ class ManagerTest extends \Test\TestCase {
                \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post');
                $hookListner->expects($this->never())->method('post');
 
+               $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+               \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post');
+               $hookListner2->expects($this->never())->method('post');
 
                $manager->updateShare($share);
        }
@@ -1953,7 +1974,8 @@ class ManagerTest extends \Test\TestCase {
                        ->getMock();
 
                $originalShare = $this->manager->newShare();
-               $originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK);
+               $originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+                       ->setPermissions(15);
 
                $tomorrow = new \DateTime();
                $tomorrow->setTime(0,0,0);
@@ -1970,7 +1992,8 @@ class ManagerTest extends \Test\TestCase {
                        ->setShareOwner('owner')
                        ->setPassword('password')
                        ->setExpirationDate($tomorrow)
-                       ->setNode($file);
+                       ->setNode($file)
+                       ->setPermissions(15);
 
                $manager->expects($this->once())->method('canShare')->willReturn(true);
                $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
@@ -1990,6 +2013,10 @@ class ManagerTest extends \Test\TestCase {
                        'uidOwner' => 'owner',
                ]);
 
+               $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+               \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post');
+               $hookListner2->expects($this->never())->method('post');
+
 
                $manager->updateShare($share);
        }