Exemplo n.º 1
0
 /**
  * Get all mountpoints applicable for the user and check for shares where we need to update the etags
  *
  * @param \OCP\IUser $user
  * @param \OCP\Files\Storage\IStorageFactory $storageFactory
  * @return \OCP\Files\Mount\IMountPoint[]
  */
 public function getMountsForUser(IUser $user, IStorageFactory $storageFactory)
 {
     $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1);
     $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1));
     $shares = array_filter($shares, function (\OCP\Share\IShare $share) {
         return $share->getPermissions() > 0;
     });
     $mounts = [];
     foreach ($shares as $share) {
         $mounts[] = new SharedMount('\\OC\\Files\\Storage\\Shared', $mounts, ['user' => $user->getUID(), 'newShare' => $share], $storageFactory);
     }
     // array_filter removes the null values from the array
     return array_filter($mounts);
 }
Exemplo n.º 2
0
 /**
  * Get all mountpoints applicable for the user and check for shares where we need to update the etags
  *
  * @param \OCP\IUser $user
  * @param \OCP\Files\Storage\IStorageFactory $storageFactory
  * @return \OCP\Files\Mount\IMountPoint[]
  */
 public function getMountsForUser(IUser $user, IStorageFactory $storageFactory)
 {
     $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1);
     $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1));
     // filter out excluded shares and group shares that includes self
     $shares = array_filter($shares, function (\OCP\Share\IShare $share) use($user) {
         return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID();
     });
     $mounts = [];
     foreach ($shares as $share) {
         try {
             $mounts[] = new SharedMount('\\OC\\Files\\Storage\\Shared', $mounts, ['user' => $user->getUID(), 'newShare' => $share], $storageFactory);
         } catch (\Exception $e) {
             $this->logger->logException($e);
             $this->logger->error('Error while trying to create shared mount');
         }
     }
     // array_filter removes the null values from the array
     return array_filter($mounts);
 }
Exemplo n.º 3
0
 /**
  * @param \OCP\Files\File|\OCP\Files\Folder $node
  * @return \OC_OCS_Result
  */
 private function getSharedWithMe($node = null)
 {
     $userShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $node, -1, 0);
     $groupShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);
     $shares = array_merge($userShares, $groupShares);
     $formatted = [];
     foreach ($shares as $share) {
         if ($this->canAccessShare($share)) {
             $formatted[] = $this->formatShare($share);
         }
     }
     return new \OC_OCS_Result($formatted);
 }
Exemplo n.º 4
0
 /**
  * @param int $id
  * @return \OC_OCS_Result
  */
 public function updateShare($id)
 {
     try {
         $share = $this->getShareById($id);
     } catch (ShareNotFound $e) {
         return new \OC_OCS_Result(null, 404, 'wrong share ID, share doesn\'t exist.');
     }
     if (!$this->canAccessShare($share)) {
         return new \OC_OCS_Result(null, 404, 'wrong share Id, share doesn\'t exist.');
     }
     $permissions = $this->request->getParam('permissions', null);
     $password = $this->request->getParam('password', null);
     $publicUpload = $this->request->getParam('publicUpload', null);
     $expireDate = $this->request->getParam('expireDate', null);
     /*
      * expirationdate, password and publicUpload only make sense for link shares
      */
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
         if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
             return new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given');
         }
         $newPermissions = null;
         if ($publicUpload === 'true') {
             $newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE;
         } else {
             if ($publicUpload === 'false') {
                 $newPermissions = \OCP\Constants::PERMISSION_READ;
             }
         }
         if ($permissions !== null) {
             $newPermissions = (int) $permissions;
         }
         if ($newPermissions !== null && $newPermissions !== \OCP\Constants::PERMISSION_READ && $newPermissions !== (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)) {
             return new \OC_OCS_Result(null, 400, 'can\'t change permission for public link share');
         }
         if ($newPermissions === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)) {
             if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
                 return new \OC_OCS_Result(null, 403, 'public upload disabled by the administrator');
             }
             if (!$share->getNode() instanceof \OCP\Files\Folder) {
                 return new \OC_OCS_Result(null, 400, "public upload is only possible for public shared folders");
             }
         }
         if ($newPermissions !== null) {
             $share->setPermissions($newPermissions);
         }
         if ($expireDate === '') {
             $share->setExpirationDate(null);
         } else {
             if ($expireDate !== null) {
                 try {
                     $expireDate = $this->parseDate($expireDate);
                 } catch (\Exception $e) {
                     return new \OC_OCS_Result(null, 400, $e->getMessage());
                 }
                 $share->setExpirationDate($expireDate);
             }
         }
         if ($password === '') {
             $share->setPassword(null);
         } else {
             if ($password !== null) {
                 $share->setPassword($password);
             }
         }
     } else {
         // For other shares only permissions is valid.
         if ($permissions === null) {
             return new \OC_OCS_Result(null, 400, 'Wrong or no update parameter given');
         } else {
             $permissions = (int) $permissions;
             $share->setPermissions($permissions);
         }
     }
     if ($permissions !== null) {
         /* Check if this is an incomming share */
         $incomingShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0);
         $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0));
         if (!empty($incomingShares)) {
             $maxPermissions = 0;
             foreach ($incomingShares as $incomingShare) {
                 $maxPermissions |= $incomingShare->getPermissions();
             }
             if ($share->getPermissions() & ~$maxPermissions) {
                 return new \OC_OCS_Result(null, 404, 'Cannot increase permissions');
             }
         }
     }
     try {
         $share = $this->shareManager->updateShare($share);
     } catch (\Exception $e) {
         return new \OC_OCS_Result(null, 400, $e->getMessage());
     }
     return new \OC_OCS_Result($this->formatShare($share));
 }