예제 #1
0
 /**
  * Delete a share
  *
  * @param IShare $share
  */
 public function delete(IShare $share)
 {
     $qb = $this->dbConnection->getQueryBuilder();
     $qb->delete('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
     $qb->execute();
     list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith());
     $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken());
 }
예제 #2
0
 /**
  * Unshare a share from the recipient. If this is a group share
  * this means we need a special entry in the share db.
  *
  * @param \OCP\Share\IShare $share
  * @param string $recipient UserId of recipient
  * @throws BackendError
  * @throws ProviderException
  */
 public function deleteFromSelf(\OCP\Share\IShare $share, $recipient)
 {
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
         $group = $this->groupManager->get($share->getSharedWith());
         $user = $this->userManager->get($recipient);
         if (!$group->inGroup($user)) {
             throw new ProviderException('Recipient not in receiving group');
         }
         // Try to fetch user specific share
         $qb = $this->dbConn->getQueryBuilder();
         $stmt = $qb->select('*')->from('share')->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))->execute();
         $data = $stmt->fetch();
         /*
          * Check if there already is a user specific group share.
          * If there is update it (if required).
          */
         if ($data === false) {
             $qb = $this->dbConn->getQueryBuilder();
             $type = $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder';
             //Insert new share
             $qb->insert('share')->values(['share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), 'share_with' => $qb->createNamedParameter($recipient), 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), 'parent' => $qb->createNamedParameter($share->getId()), 'item_type' => $qb->createNamedParameter($type), 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), 'file_source' => $qb->createNamedParameter($share->getNode()->getId()), 'file_target' => $qb->createNamedParameter($share->getTarget()), 'permissions' => $qb->createNamedParameter(0), 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp())])->execute();
         } else {
             if ($data['permissions'] !== 0) {
                 // Update existing usergroup share
                 $qb = $this->dbConn->getQueryBuilder();
                 $qb->update('share')->set('permissions', $qb->createNamedParameter(0))->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))->execute();
             }
         }
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
             if ($share->getSharedWith() !== $recipient) {
                 throw new ProviderException('Recipient does not match');
             }
             // We can just delete user and link shares
             $this->delete($share);
         } else {
             throw new ProviderException('Invalid shareType');
         }
     }
 }
예제 #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->getId());
     $provider = $this->factory->getProvider($providerId);
     $provider->move($share, $recipientId);
 }
예제 #4
0
파일: share20ocs.php 프로젝트: gvde/core
 /**
  * @param \OCP\Share\IShare $share
  * @return bool
  */
 protected function canAccessShare(\OCP\Share\IShare $share)
 {
     // A file with permissions 0 can't be accessed by us. So Don't show it
     if ($share->getPermissions() === 0) {
         return false;
     }
     // Owner of the file and the sharer of the file can always get share
     if ($share->getShareOwner() === $this->currentUser->getUID() || $share->getSharedBy() === $this->currentUser->getUID()) {
         return true;
     }
     // If the share is shared with you (or a group you are a member of)
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() === $this->currentUser->getUID()) {
         return true;
     }
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
         $sharedWith = $this->groupManager->get($share->getSharedWith());
         if ($sharedWith->inGroup($this->currentUser)) {
             return true;
         }
     }
     return false;
 }
 /**
  * Delete a share (owner unShares the file)
  *
  * @param IShare $share
  */
 public function delete(IShare $share)
 {
     list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith());
     $isOwner = false;
     // if the local user is the owner we can send the unShare request directly...
     if ($this->userManager->userExists($share->getShareOwner())) {
         $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken());
         $this->revokeShare($share, true);
         $isOwner = true;
     } else {
         // ... if not we need to correct ID for the unShare request
         $remoteId = $this->getRemoteId($share);
         $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken());
         $this->revokeShare($share, false);
     }
     // send revoke notification to the other user, if initiator and owner are not the same user
     if ($share->getShareOwner() !== $share->getSharedBy()) {
         $remoteId = $this->getRemoteId($share);
         if ($isOwner) {
             list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
         } else {
             list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner());
         }
         $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken());
     }
     $this->removeShareFromTable($share);
 }
예제 #6
0
파일: manager.php 프로젝트: Pookay/core
 /**
  * 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()) {
         if (!$share->getSharedWith()->inGroup($share->getSharedBy())) {
             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');
         }
     }
 }