Beispiel #1
0
 /**
  * @inheritdoc
  */
 public function move(\OCP\Share\IShare $share, $recipient)
 {
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         // Just update the target
         $qb = $this->dbConn->getQueryBuilder();
         $qb->update('share')->set('file_target', $qb->createNamedParameter($share->getTarget()))->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))->execute();
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             // Check if there is a usergroup share
             $qb = $this->dbConn->getQueryBuilder();
             $stmt = $qb->select('id')->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())))->setMaxResults(1)->execute();
             $data = $stmt->fetch();
             $stmt->closeCursor();
             if ($data === false) {
                 // No usergroup share yet. Create one.
                 $qb = $this->dbConn->getQueryBuilder();
                 $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($share->getNode() instanceof File ? 'file' : 'folder'), 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), 'file_source' => $qb->createNamedParameter($share->getNode()->getId()), 'file_target' => $qb->createNamedParameter($share->getTarget()), 'permissions' => $qb->createNamedParameter($share->getPermissions()), 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp())])->execute();
             } else {
                 // Already a usergroup share. Update it.
                 $qb = $this->dbConn->getQueryBuilder();
                 $qb->update('share')->set('file_target', $qb->createNamedParameter($share->getTarget()))->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))->execute();
             }
         }
     }
     return $share;
 }
 /**
  * Update a share
  *
  * @param IShare $share
  * @return IShare The share object
  */
 public function update(IShare $share)
 {
     /*
      * We allow updating the permissions of federated shares
      */
     $qb = $this->dbConnection->getQueryBuilder();
     $qb->update('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))->set('permissions', $qb->createNamedParameter($share->getPermissions()))->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))->execute();
     return $share;
 }
Beispiel #3
0
 /**
  * Check if the user that is sharing can actually share
  *
  * @param \OCP\Share\IShare $share
  * @throws \Exception
  */
 protected function canShare(\OCP\Share\IShare $share)
 {
     if (!$this->shareApiEnabled()) {
         throw new \Exception('The share API is disabled');
     }
     if ($this->sharingDisabledForUser($share->getSharedBy())) {
         throw new \Exception('You are not allowed to share');
     }
 }
Beispiel #4
0
 /**
  * Check if the user that is sharing can actually share
  *
  * @param \OCP\Share\IShare $share
  * @return bool
  */
 protected function canShare(\OCP\Share\IShare $share)
 {
     if (!$this->shareApiEnabled()) {
         return false;
     }
     if ($this->sharingDisabledForUser($share->getSharedBy())) {
         return false;
     }
     return true;
 }
 /**
  * throws hooks when a share is attempted to be accessed
  *
  * @param \OCP\Share\IShare|string $share the Share instance if available,
  * otherwise token
  * @param int $errorCode
  * @param string $errorMessage
  * @throws OC\HintException
  * @throws OC\ServerNotAvailableException
  */
 protected function emitAccessShareHook($share, $errorCode = 200, $errorMessage = '')
 {
     $itemType = $itemSource = $uidOwner = '';
     $token = $share;
     $exception = null;
     if ($share instanceof \OCP\Share\IShare) {
         try {
             $token = $share->getToken();
             $uidOwner = $share->getSharedBy();
             $itemType = $share->getNodeType();
             $itemSource = $share->getNodeId();
         } catch (\Exception $e) {
             // we log what we know and pass on the exception afterwards
             $exception = $e;
         }
     }
     \OC_Hook::emit('OCP\\Share', 'share_link_access', ['itemType' => $itemType, 'itemSource' => $itemSource, 'uidOwner' => $uidOwner, 'token' => $token, 'errorCode' => $errorCode, 'errorMessage' => $errorMessage]);
     if (!is_null($exception)) {
         throw $exception;
     }
 }
Beispiel #6
0
 /**
  * @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;
 }
 /**
  * in case of a re-share we need to send the other use (initiator or owner)
  * a message that the file was unshared
  *
  * @param IShare $share
  * @param bool $isOwner the user can either be the owner or the user who re-sahred it
  * @throws ShareNotFound
  * @throws \OC\HintException
  */
 protected function revokeShare($share, $isOwner)
 {
     // also send a unShare request to the initiator, if this is a different user than the owner
     if ($share->getShareOwner() !== $share->getSharedBy()) {
         if ($isOwner) {
             list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
         } else {
             list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner());
         }
         $remoteId = $this->getRemoteId($share);
         $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken());
     }
 }
 /**
  * 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 IUser $recipient
  * @throws BackendError
  * @throws ProviderException
  */
 public function deleteFromSelf(\OCP\Share\IShare $share, IUser $recipient)
 {
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
         /** @var IGroup $group */
         $group = $share->getSharedWith();
         if (!$group->inGroup($recipient)) {
             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->getUID())))->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->getUID()), 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()->getUID()), 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()->getUID()), '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');
         }
     }
 }
 /**
  * check if we are the initiator or the owner of a re-share and return the correct UID
  *
  * @param Share\IShare $share
  * @return string
  */
 protected function getCorrectUid(Share\IShare $share)
 {
     if ($this->userManager->userExists($share->getShareOwner())) {
         return $share->getShareOwner();
     }
     return $share->getSharedBy();
 }