/**
  * 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;
 }
Exemple #2
0
 /**
  * Verify the password of a public share
  *
  * @param IShare $share
  * @param string $password
  * @return bool
  */
 public function checkPassword(IShare $share, $password)
 {
     if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK) {
         //TODO maybe exception?
         return false;
     }
     if ($password === null || $share->getPassword() === null) {
         return false;
     }
     $newHash = '';
     if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) {
         return false;
     }
     if (!empty($newHash)) {
         //TODO update hash!
     }
     return true;
 }
Exemple #3
0
 /**
  * @param IShare $share
  * @return bool
  */
 protected function canAccessShare(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 || $share->getSharedBy() === $this->currentUser) {
         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) {
         return true;
     }
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && $share->getSharedWith()->inGroup($this->currentUser)) {
         return true;
     }
     return false;
 }
Exemple #4
0
 /**
  * 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;
 }
Exemple #5
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->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;
 }
Exemple #6
0
 /**
  * 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);
 }
Exemple #7
0
 /**
  * Check if the user that is sharing can actually share
  *
  * @param IShare $share
  * @return bool
  */
 protected function canShare(IShare $share)
 {
     if (!$this->shareApiEnabled()) {
         return false;
     }
     if ($this->isSharingDisabledForUser($share->getSharedBy())) {
         return false;
     }
     return true;
 }
 /**
  * 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');
         }
     }
 }
Exemple #9
0
 /**
  * Delete all the children of this share
  *
  * @param IShare $share
  * @return IShare[] List of deleted shares
  */
 protected function deleteChildren(IShare $share)
 {
     $deletedShares = [];
     $provider = $this->factory->getProviderForType($share->getShareType());
     foreach ($provider->getChildren($share) as $child) {
         $deletedChildren = $this->deleteChildren($child);
         $deletedShares = array_merge($deletedShares, $deletedChildren);
         $provider->delete($child);
         $deletedShares[] = $child;
     }
     return $deletedShares;
 }