Ejemplo n.º 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());
 }
Ejemplo n.º 2
0
 /**
  * Update a share
  *
  * @param \OCP\Share\IShare $share
  * @return \OCP\Share\IShare The share object
  */
 public function update(\OCP\Share\IShare $share)
 {
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         /*
          * We allow updating the recipient on user shares.
          */
         $qb = $this->dbConn->getQueryBuilder();
         $qb->update('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))->set('share_with', $qb->createNamedParameter($share->getSharedWith()))->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))->set('permissions', $qb->createNamedParameter($share->getPermissions()))->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))->execute();
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $qb = $this->dbConn->getQueryBuilder();
             $qb->update('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))->set('permissions', $qb->createNamedParameter($share->getPermissions()))->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))->execute();
             /*
              * Update all user defined group shares
              */
             $qb = $this->dbConn->getQueryBuilder();
             $qb->update('share')->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))->execute();
             /*
              * Now update the permissions for all children that have not set it to 0
              */
             $qb = $this->dbConn->getQueryBuilder();
             $qb->update('share')->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0)))->set('permissions', $qb->createNamedParameter($share->getPermissions()))->execute();
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 $qb = $this->dbConn->getQueryBuilder();
                 $qb->update('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))->set('share_with', $qb->createNamedParameter($share->getPassword()))->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))->set('permissions', $qb->createNamedParameter($share->getPermissions()))->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))->set('token', $qb->createNamedParameter($share->getToken()))->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))->execute();
             }
         }
     }
     return $share;
 }
Ejemplo n.º 3
0
 /**
  * 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;
     }
 }
Ejemplo n.º 4
0
 /**
  * Convert an IShare to an array for OCS output
  *
  * @param \OCP\Share\IShare $share
  * @return array
  * @throws NotFoundException In case the node can't be resolved.
  */
 protected function formatShare(\OCP\Share\IShare $share)
 {
     $sharedBy = $this->userManager->get($share->getSharedBy());
     $shareOwner = $this->userManager->get($share->getShareOwner());
     $result = ['id' => $share->getId(), 'share_type' => $share->getShareType(), 'uid_owner' => $share->getSharedBy(), 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), 'permissions' => $share->getPermissions(), 'stime' => $share->getShareTime()->getTimestamp(), 'parent' => null, 'expiration' => null, 'token' => null, 'uid_file_owner' => $share->getShareOwner(), 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner()];
     $node = $share->getNode();
     $result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner())->getRelativePath($node->getPath());
     if ($node instanceof \OCP\Files\Folder) {
         $result['item_type'] = 'folder';
     } else {
         $result['item_type'] = 'file';
     }
     $result['storage_id'] = $node->getStorage()->getId();
     $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
     $result['item_source'] = $node->getId();
     $result['file_source'] = $node->getId();
     $result['file_parent'] = $node->getParent()->getId();
     $result['file_target'] = $share->getTarget();
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         $sharedWith = $this->userManager->get($share->getSharedWith());
         $result['share_with'] = $share->getSharedWith();
         $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $result['share_with'] = $share->getSharedWith();
             $result['share_with_displayname'] = $share->getSharedWith();
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 $result['share_with'] = $share->getPassword();
                 $result['share_with_displayname'] = $share->getPassword();
                 $result['token'] = $share->getToken();
                 $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
                 $expiration = $share->getExpirationDate();
                 if ($expiration !== null) {
                     $result['expiration'] = $expiration->format('Y-m-d 00:00:00');
                 }
             } else {
                 if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
                     $result['share_with'] = $share->getSharedWith();
                     $result['share_with_displayname'] = $share->getSharedWith();
                     $result['token'] = $share->getToken();
                 }
             }
         }
     }
     $result['mail_send'] = $share->getMailSend() ? 1 : 0;
     return $result;
 }
 /**
  * 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);
 }
Ejemplo n.º 6
0
 /**
  * check if we got the right share
  *
  * @param Share\IShare $share
  * @param string $token
  * @return bool
  */
 protected function verifyShare(Share\IShare $share, $token)
 {
     if ($share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && $share->getToken() === $token) {
         return true;
     }
     return false;
 }