Пример #1
0
 /**
  * Check for pre share requirements for group shares
  *
  * @param \OCP\Share\IShare $share
  * @throws \Exception
  */
 protected function groupCreateChecks(\OCP\Share\IShare $share)
 {
     // Verify if the user can share with this group
     if ($this->shareWithGroupMembersOnly()) {
         $sharedBy = $this->userManager->get($share->getSharedBy());
         $sharedWith = $this->groupManager->get($share->getSharedWith());
         if (!$sharedWith->inGroup($sharedBy)) {
             throw new \Exception('Only sharing within your own groups is allowed');
         }
     }
     /*
      * TODO: Could be costly, fix
      *
      * Also this is not what we want in the future.. then we want to squash identical shares.
      */
     $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
     $existingShares = $provider->getSharesByPath($share->getNode());
     foreach ($existingShares as $existingShare) {
         if ($existingShare->getFullId() === $share->getFullId()) {
             continue;
         }
         if ($existingShare->getSharedWith() === $share->getSharedWith()) {
             throw new \Exception('Path already shared with this group');
         }
     }
 }
Пример #2
0
 /**
  * Delete a share
  *
  * @param \OCP\Share\IShare $share
  * @throws ShareNotFound
  * @throws \InvalidArgumentException
  */
 public function deleteShare(\OCP\Share\IShare $share)
 {
     try {
         $share->getFullId();
     } catch (\UnexpectedValueException $e) {
         throw new \InvalidArgumentException('Share does not have a full id');
     }
     $formatHookParams = function (\OCP\Share\IShare $share) {
         // Prepare hook
         $shareType = $share->getShareType();
         $sharedWith = '';
         if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
             $sharedWith = $share->getSharedWith();
         } else {
             if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
                 $sharedWith = $share->getSharedWith();
             } else {
                 if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
                     $sharedWith = $share->getSharedWith();
                 }
             }
         }
         $hookParams = ['id' => $share->getId(), 'itemType' => $share->getNodeType(), 'itemSource' => $share->getNodeId(), 'shareType' => $shareType, 'shareWith' => $sharedWith, 'itemparent' => method_exists($share, 'getParent') ? $share->getParent() : '', 'uidOwner' => $share->getSharedBy(), 'fileSource' => $share->getNodeId(), 'fileTarget' => $share->getTarget()];
         return $hookParams;
     };
     $hookParams = $formatHookParams($share);
     // Emit pre-hook
     \OC_Hook::emit('OCP\\Share', 'pre_unshare', $hookParams);
     // Get all children and delete them as well
     $deletedShares = $this->deleteChildren($share);
     // Do the actual delete
     $provider = $this->factory->getProviderForType($share->getShareType());
     $provider->delete($share);
     // All the deleted shares caused by this delete
     $deletedShares[] = $share;
     //Format hook info
     $formattedDeletedShares = array_map(function ($share) use($formatHookParams) {
         return $formatHookParams($share);
     }, $deletedShares);
     $hookParams['deletedShares'] = $formattedDeletedShares;
     // Emit post hook
     \OC_Hook::emit('OCP\\Share', 'post_unshare', $hookParams);
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 public function moveShare(\OCP\Share\IShare $share, $recipientId)
 {
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
         throw new \InvalidArgumentException('Can\'t change target of link share');
     }
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) {
         throw new \InvalidArgumentException('Invalid recipient');
     }
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
         $sharedWith = $this->groupManager->get($share->getSharedWith());
         $recipient = $this->userManager->get($recipientId);
         if (!$sharedWith->inGroup($recipient)) {
             throw new \InvalidArgumentException('Invalid recipient');
         }
     }
     list($providerId, ) = $this->splitFullId($share->getFullId());
     $provider = $this->factory->getProvider($providerId);
     $provider->move($share, $recipientId);
 }
Пример #4
0
 public function testSetProviderIdString()
 {
     $this->share->setProviderId('foo');
     $this->share->setId('bar');
     $this->assertEquals('foo:bar', $this->share->getFullId());
 }