Ejemplo n.º 1
0
 /**
  * check if the parent folder exists otherwise move the mount point up
  *
  * @param \OCP\Share\IShare $share
  * @param SharedMount[] $mountpoints
  * @return string
  */
 private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints)
 {
     $mountPoint = basename($share->getTarget());
     $parent = dirname($share->getTarget());
     if (!$this->recipientView->is_dir($parent)) {
         $parent = Helper::getShareFolder();
     }
     $newMountPoint = $this->generateUniqueTarget(\OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), $this->recipientView, $mountpoints);
     if ($newMountPoint !== $share->getTarget()) {
         $this->updateFileTarget($newMountPoint, $share);
     }
     return $newMountPoint;
 }
Ejemplo n.º 2
0
 /**
  * Convert an IShare to an array for OCS output
  *
  * @param \OCP\Share\IShare $share
  * @return array
  */
 protected function formatShare(\OCP\Share\IShare $share)
 {
     $result = ['id' => $share->getId(), 'share_type' => $share->getShareType(), 'uid_owner' => $share->getSharedBy()->getUID(), 'displayname_owner' => $share->getSharedBy()->getDisplayName(), 'permissions' => $share->getPermissions(), 'stime' => $share->getShareTime()->getTimestamp(), 'parent' => null, 'expiration' => null, 'token' => null, 'uid_file_owner' => $share->getShareOwner()->getUID(), 'displayname_file_owner' => $share->getShareOwner()->getDisplayName()];
     $node = $share->getNode();
     $result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID())->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 = $share->getSharedWith();
         $result['share_with'] = $sharedWith->getUID();
         $result['share_with_displayname'] = $sharedWith->getDisplayName();
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $sharedWith = $share->getSharedWith();
             $result['share_with'] = $sharedWith->getGID();
             $result['share_with_displayname'] = $sharedWith->getGID();
         } 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;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 /**
  * return mount point of share, relative to data/user/files
  *
  * @return string
  */
 public function getMountPoint()
 {
     return $this->superShare->getTarget();
 }
 /**
  * Makes sure that the token contains all the information that we need
  *
  * @param IShare $share
  * @param string $token
  *
  * @throws CheckException
  */
 private function checkShareIsValid($share, $token)
 {
     if ($share->getShareOwner() === null || $share->getTarget() === null) {
         $message = 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")';
         throw new CheckException($message, Http::STATUS_NOT_FOUND);
     }
 }
 /**
  * get federated share from the share_external table but exclude mounted link shares
  *
  * @param IShare $share
  * @return array
  * @throws ShareNotFound
  */
 protected function getShareFromExternalShareTable(IShare $share)
 {
     $query = $this->dbConnection->getQueryBuilder();
     $query->select('*')->from($this->externalShareTable)->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner())))->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget())));
     $result = $query->execute()->fetchAll();
     if (isset($result[0]) && (int) $result[0]['remote_id'] > 0) {
         return $result[0];
     }
     throw new ShareNotFound('share not found in share_external table');
 }
Ejemplo n.º 7
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 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');
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Creates the environment based on the share the token links to
  *
  * @param IShare $share
  */
 public function setTokenBasedEnv($share)
 {
     $origShareOwnerId = $share->getShareOwner();
     $this->userFolder = $this->rootFolder->getUserFolder($origShareOwnerId);
     $this->sharedNodeId = $share->getNodeId();
     $this->sharedNode = $share->getNode();
     $this->fromRootToFolder = $this->buildFromRootToFolder($this->sharedNodeId);
     $this->folderName = $share->getTarget();
     $this->userId = $origShareOwnerId;
     $this->sharePassword = $share->getPassword();
 }