Exemplo n.º 1
0
 public function testGroupCreateChecksPathAlreadySharedWithDifferentGroup()
 {
     $share = new \OC\Share20\Share();
     $sharedWith = $this->getMock('\\OCP\\IGroup');
     $share->setSharedWith($sharedWith);
     $path = $this->getMock('\\OCP\\Files\\Node');
     $share->setPath($path);
     $share2 = new \OC\Share20\Share();
     $sharedWith2 = $this->getMock('\\OCP\\IGroup');
     $share2->setSharedWith($sharedWith2);
     $this->defaultProvider->method('getSharesByPath')->with($path)->willReturn([$share2]);
     $this->invokePrivate($this->manager, 'groupCreateChecks', [$share]);
 }
Exemplo n.º 2
0
 /**
  * Create a share object from an database row
  *
  * @param mixed[] $data
  * @return Share
  */
 private function createShare($data)
 {
     $share = new Share();
     $share->setId((int) $data['id'])->setShareType((int) $data['share_type'])->setPermissions((int) $data['permissions'])->setTarget($data['file_target']);
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         $share->setSharedWith($this->userManager->get($data['share_with']));
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $share->setSharedWith($this->groupManager->get($data['share_with']));
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 /*
                  * TODO: Clean this up, this should be set as password not sharedWith
                  */
                 $share->setSharedWith($data['share_with']);
                 $share->setToken($data['token']);
             } else {
                 $share->setSharedWith($data['share_with']);
             }
         }
     }
     $share->setSharedBy($this->userManager->get($data['uid_owner']));
     // TODO: getById can return an array. How to handle this properly??
     $path = $this->userFolder->getById($data['file_source']);
     $path = $path[0];
     $share->setPath($path);
     $owner = $path->getStorage()->getOwner('.');
     if ($owner !== false) {
         $share->setShareOwner($this->userManager->get($owner));
     }
     if ($data['expiration'] !== null) {
         $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
         $share->setExpirationDate($expiration);
     }
     return $share;
 }
Exemplo n.º 3
0
 /**
  * Create a share object from an database row
  *
  * @param mixed[] $data
  * @return Share
  */
 private function createShare($data)
 {
     $share = new Share();
     $share->setId((int) $data['id'])->setShareType((int) $data['share_type'])->setPermissions((int) $data['permissions'])->setTarget($data['file_target'])->setShareTime((int) $data['stime'])->setMailSend((bool) $data['mail_send']);
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         $share->setSharedWith($this->userManager->get($data['share_with']));
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $share->setSharedWith($this->groupManager->get($data['share_with']));
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 $share->setPassword($data['share_with']);
                 $share->setToken($data['token']);
             } else {
                 $share->setSharedWith($data['share_with']);
             }
         }
     }
     $share->setSharedBy($this->userManager->get($data['uid_owner']));
     // TODO: getById can return an array. How to handle this properly??
     $folder = $this->rootFolder->getUserFolder($share->getSharedBy()->getUID());
     $path = $folder->getById((int) $data['file_source'])[0];
     $owner = $path->getOwner();
     $share->setShareOwner($owner);
     $path = $this->rootFolder->getUserFolder($owner->getUID())->getById((int) $data['file_source'])[0];
     $share->setPath($path);
     if ($data['expiration'] !== null) {
         $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
         $share->setExpirationDate($expiration);
     }
     return $share;
 }
Exemplo n.º 4
0
 /**
  * Create a share object from an database row
  *
  * @param mixed[] $data
  * @return Share
  * @throws InvalidShare
  */
 private function createShare($data)
 {
     $share = new Share();
     $share->setId((int) $data['id'])->setShareType((int) $data['share_type'])->setPermissions((int) $data['permissions'])->setTarget($data['file_target'])->setShareTime((int) $data['stime'])->setMailSend((bool) $data['mail_send']);
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         $sharedWith = $this->userManager->get($data['share_with']);
         if ($sharedWith === null) {
             throw new InvalidShare();
         }
         $share->setSharedWith($sharedWith);
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $sharedWith = $this->groupManager->get($data['share_with']);
             if ($sharedWith === null) {
                 throw new InvalidShare();
             }
             $share->setSharedWith($sharedWith);
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 $share->setPassword($data['share_with']);
                 $share->setToken($data['token']);
             }
         }
     }
     if ($data['uid_initiator'] === null) {
         //OLD SHARE
         $sharedBy = $this->userManager->get($data['uid_owner']);
         if ($sharedBy === null) {
             throw new InvalidShare();
         }
         $share->setSharedBy($sharedBy);
         $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']);
         $owner = $path->getOwner();
         $share->setShareOwner($owner);
     } else {
         //New share!
         $sharedBy = $this->userManager->get($data['uid_initiator']);
         $shareOwner = $this->userManager->get($data['uid_owner']);
         if ($sharedBy === null || $shareOwner === null) {
             throw new InvalidShare();
         }
         $share->setSharedBy($sharedBy);
         $share->setShareOwner($shareOwner);
     }
     $path = $this->getNode($share->getShareOwner(), (int) $data['file_source']);
     $share->setPath($path);
     if ($data['expiration'] !== null) {
         $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
         $share->setExpirationDate($expiration);
     }
     $share->setProviderId($this->identifier());
     return $share;
 }