]> source.dussan.org Git - nextcloud-server.git/commitdiff
Also add type (file/folder) to IShare object
authorRoeland Jago Douma <rullzer@owncloud.com>
Thu, 4 Feb 2016 13:28:09 +0000 (14:28 +0100)
committerRoeland Jago Douma <rullzer@owncloud.com>
Thu, 4 Feb 2016 13:28:09 +0000 (14:28 +0100)
We need this for the hooks :(

lib/private/share20/defaultshareprovider.php
lib/private/share20/manager.php
lib/private/share20/share.php
lib/public/share/ishare.php
tests/lib/share20/managertest.php

index 48164a5d419cdc582eb3c0bdf41b7a3c26513b53..0ab0dc81fa7af85adcb7bd3de062e41a37b82c0b 100644 (file)
@@ -745,6 +745,7 @@ class DefaultShareProvider implements IShareProvider {
                }
 
                $share->setNodeId((int)$data['file_source']);
+               $share->setNodeType($data['item_type']);
 
                if ($data['expiration'] !== null) {
                        $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
index 3db76d92ac7ec79553e09c5b8cc5a2dd48e67fa5..6ea638b84e690942425ddb5710fff51b9649739f 100644 (file)
@@ -663,13 +663,13 @@ class Manager implements IManager {
 
                        $hookParams = [
                                'id'         => $share->getId(),
-                               'itemType'   => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
-                               'itemSource' => $share->getNode()->getId(),
+                               'itemType'   => $share->getNodeType(),
+                               'itemSource' => $share->getNodeId(),
                                'shareType'  => $shareType,
                                'shareWith'  => $sharedWith,
                                'itemparent' => $share->getParent(),
                                'uidOwner'   => $share->getSharedBy(),
-                               'fileSource' => $share->getNode()->getId(),
+                               'fileSource' => $share->getNodeId(),
                                'fileTarget' => $share->getTarget()
                        ];
                        return $hookParams;
index 5b7945b1da8b04ef12fabad94ffceeec03b21462..448b05d20a3a1d026bf41c7d03cad0b753b5f4c1 100644 (file)
@@ -20,6 +20,7 @@
  */
 namespace OC\Share20;
 
+use OCP\Files\File;
 use OCP\Files\IRootFolder;
 use OCP\Files\Node;
 use OCP\Files\NotFoundException;
@@ -36,6 +37,8 @@ class Share implements \OCP\Share\IShare {
        private $node;
        /** @var int */
        private $fileId;
+       /** @var string */
+       private $nodeType;
        /** @var int */
        private $shareType;
        /** @var string */
@@ -138,6 +141,40 @@ class Share implements \OCP\Share\IShare {
                return $this;
        }
 
+       /**
+        * @inheritdoc
+        */
+       public function getNodeId() {
+               if ($this->fileId === null) {
+                       $this->fileId = $this->getNode()->getId();
+               }
+
+               return $this->fileId;
+       }
+
+       /**
+        * @inheritdoc
+        */
+       public function setNodeType($type) {
+               if ($type !== 'file' && $type !== 'folder') {
+                       throw new \InvalidArgumentException();
+               }
+
+               $this->nodeType = $type;
+       }
+
+       /**
+        * @inheritdoc
+        */
+       public function getNodeType() {
+               if ($this->nodeType === null) {
+                       $node = $this->getNode();
+                       $this->nodeType = $node instanceof File ? 'file' : 'folder';
+               }
+
+               return $this->nodeType;
+       }
+
        /**
         * @inheritdoc
         */
index 074f411758466903203936a9685a50bf0698cccd..5054a886af59d80583de94901667bf4ba838df5e 100644 (file)
@@ -77,6 +77,32 @@ interface IShare {
         */
        public function setNodeId($fileId);
 
+       /**
+        * Get the fileid of the node of this share
+        * @return int
+        * @since 9.0.0
+        * @throws NotFoundException
+        */
+       public function getNodeId();
+
+       /**
+        * Set the type of node (file/folder)
+        *
+        * @param string $type
+        * @return \OCP\Share\IShare The modified object
+        * @since 9.0.0
+        */
+       public function setNodeType($type);
+
+       /**
+        * Get the type of node (file/folder)
+        *
+        * @return string
+        * @since 9.0.0
+        * @throws NotFoundException
+        */
+       public function getNodeType();
+
        /**
         * Set the shareType
         *
index 01e5283fcf7ee553cc1701f1ff5e369a47f0cdb6..270f5da33cd61feaa0f6d79b2f0a34c708ada9ac 100644 (file)
@@ -242,6 +242,86 @@ class ManagerTest extends \Test\TestCase {
                $manager->deleteShare($share);
        }
 
+       public function testDeleteLazyShare() {
+               $manager = $this->createManagerMock()
+                       ->setMethods(['getShareById', 'deleteChildren'])
+                       ->getMock();
+
+               $share = $this->manager->newShare();
+               $share->setId(42)
+                       ->setProviderId('prov')
+                       ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+                       ->setSharedWith('sharedWith')
+                       ->setSharedBy('sharedBy')
+                       ->setShareOwner('shareOwner')
+                       ->setTarget('myTarget')
+                       ->setNodeId(1)
+                       ->setNodeType('file');
+
+               $this->rootFolder->expects($this->never())->method($this->anything());
+
+               $manager->expects($this->once())->method('getShareById')->with('prov:42')->willReturn($share);
+               $manager->expects($this->once())->method('deleteChildren')->with($share);
+
+               $this->defaultProvider
+                       ->expects($this->once())
+                       ->method('delete')
+                       ->with($share);
+
+               $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock();
+               \OCP\Util::connectHook('OCP\Share', 'pre_unshare', $hookListner, 'pre');
+               \OCP\Util::connectHook('OCP\Share', 'post_unshare', $hookListner, 'post');
+
+               $hookListnerExpectsPre = [
+                       'id' => 42,
+                       'itemType' => 'file',
+                       'itemSource' => 1,
+                       'shareType' => \OCP\Share::SHARE_TYPE_USER,
+                       'shareWith' => 'sharedWith',
+                       'itemparent' => null,
+                       'uidOwner' => 'sharedBy',
+                       'fileSource' => 1,
+                       'fileTarget' => 'myTarget',
+               ];
+
+               $hookListnerExpectsPost = [
+                       'id' => 42,
+                       'itemType' => 'file',
+                       'itemSource' => 1,
+                       'shareType' => \OCP\Share::SHARE_TYPE_USER,
+                       'shareWith' => 'sharedWith',
+                       'itemparent' => null,
+                       'uidOwner' => 'sharedBy',
+                       'fileSource' => 1,
+                       'fileTarget' => 'myTarget',
+                       'deletedShares' => [
+                               [
+                                       'id' => 42,
+                                       'itemType' => 'file',
+                                       'itemSource' => 1,
+                                       'shareType' => \OCP\Share::SHARE_TYPE_USER,
+                                       'shareWith' => 'sharedWith',
+                                       'itemparent' => null,
+                                       'uidOwner' => 'sharedBy',
+                                       'fileSource' => 1,
+                                       'fileTarget' => 'myTarget',
+                               ],
+                       ],
+               ];
+
+
+               $hookListner
+                       ->expects($this->exactly(1))
+                       ->method('pre')
+                       ->with($hookListnerExpectsPre);
+               $hookListner
+                       ->expects($this->exactly(1))
+                       ->method('post')
+                       ->with($hookListnerExpectsPost);
+
+               $manager->deleteShare($share);
+       }
+
        public function testDeleteNested() {
                $manager = $this->createManagerMock()
                        ->setMethods(['getShareById'])