コード例 #1
0
 /**
  * Get all children of this share
  *
  * @param IShare $parent
  * @return IShare[]
  */
 public function getChildren(IShare $parent)
 {
     $children = [];
     $qb = $this->dbConn->getQueryBuilder();
     $qb->select('*')->from('share')->where($qb->expr()->eq('parent', $qb->createParameter('parent')))->setParameter(':parent', $parent->getId())->orderBy('id');
     $cursor = $qb->execute();
     while ($data = $cursor->fetch()) {
         $children[] = $this->createShare($data);
     }
     $cursor->closeCursor();
     return $children;
 }
コード例 #2
0
ファイル: share20ocs.php プロジェクト: reverserob/core
 /**
  * Convert an IShare to an array for OCS output
  *
  * @param IShare $share
  * @return array
  */
 protected function formatShare($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(), 'parent' => $share->getParent(), 'expiration' => null, 'token' => null];
     $path = $share->getPath();
     $result['path'] = $this->userFolder->getRelativePath($path->getPath());
     if ($path instanceof \OCP\Files\Folder) {
         $result['item_type'] = 'folder';
     } else {
         $result['item_type'] = 'file';
     }
     $result['storage_id'] = $path->getStorage()->getId();
     $result['storage'] = \OC\Files\Cache\Storage::getNumericStorageId($path->getStorage()->getId());
     $result['item_source'] = $path->getId();
     $result['file_source'] = $path->getId();
     $result['file_parent'] = $path->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;
 }
コード例 #3
0
ファイル: manager.php プロジェクト: Juraganet/core
 /**
  * Unshare a file as the recipient.
  * This can be different from a regular delete for example when one of
  * the users in a groups deletes that share. But the provider should
  * handle this.
  *
  * @param IShare $share
  * @param IUser $recipient
  */
 public function deleteFromSelf(IShare $share, IUser $recipient)
 {
     list($providerId, $id) = $this->splitFullId($share->getId());
     $provider = $this->factory->getProvider($providerId);
     $provider->deleteFromSelf($share, $recipient);
 }
コード例 #4
0
ファイル: defaultshareprovider.php プロジェクト: kenwi/core
 /**
  * Get all children of this share
  *
  * @param IShare $parent
  * @return IShare[]
  */
 public function getChildren(IShare $parent)
 {
     $children = [];
     $qb = $this->dbConn->getQueryBuilder();
     $qb->select('*')->from('share')->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))->andWhere($qb->expr()->in('share_type', [$qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP), $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK), $qb->expr()->literal(self::SHARE_TYPE_USERGROUP)]))->orderBy('id');
     $cursor = $qb->execute();
     while ($data = $cursor->fetch()) {
         $children[] = $this->createShare($data);
     }
     $cursor->closeCursor();
     return $children;
 }
コード例 #5
0
ファイル: manager.php プロジェクト: rajeshpillai/core
 /**
  * Delete a share
  *
  * @param Share $share
  * @throws ShareNotFound
  * @throws \OC\Share20\Exception\BackendError
  */
 public function deleteShare(IShare $share)
 {
     if ($share->getId() === null) {
         throw new ShareNotFound();
     }
     $this->defaultProvider->delete($share);
 }
コード例 #6
0
ファイル: defaultshareprovider.php プロジェクト: matt407/core
 /**
  * Unshare a share from the recipient. If this is a group share
  * this means we need a special entry in the share db.
  *
  * @param IShare $share
  * @param IUser $recipient
  * @throws BackendError
  * @throws ProviderException
  */
 public function deleteFromSelf(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->getPath() 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->getPath()->getId()), 'file_source' => $qb->createNamedParameter($share->getPath()->getId()), 'file_target' => $qb->createNamedParameter($share->getTarget()), 'permissions' => $qb->createNamedParameter(0), 'stime' => $qb->createNamedParameter($share->getSharetime())])->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');
         }
     }
 }