/**
  * Create a share object from an database row
  *
  * @param array $data
  * @return IShare
  * @throws InvalidShare
  * @throws ShareNotFound
  */
 private function createShare($data)
 {
     $share = new Share($this->rootFolder);
     $share->setId((int) $data['id'])->setShareType((int) $data['share_type'])->setPermissions((int) $data['permissions'])->setTarget($data['file_target'])->setMailSend((bool) $data['mail_send'])->setToken($data['token']);
     $shareTime = new \DateTime();
     $shareTime->setTimestamp((int) $data['stime']);
     $share->setShareTime($shareTime);
     $share->setSharedWith($data['share_with']);
     if ($data['uid_initiator'] !== null) {
         $share->setShareOwner($data['uid_owner']);
         $share->setSharedBy($data['uid_initiator']);
     } else {
         //OLD SHARE
         $share->setSharedBy($data['uid_owner']);
         $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']);
         $owner = $path->getOwner();
         $share->setShareOwner($owner->getUID());
     }
     $share->setNodeId((int) $data['file_source']);
     $share->setNodeType($data['item_type']);
     $share->setProviderId($this->identifier());
     return $share;
 }
 public function testUpdateShareLink()
 {
     $manager = $this->createManagerMock()->setMethods(['canShare', 'getShareById', 'generalCreateChecks', 'linkCreateChecks', 'pathCreateChecks', 'verifyPassword', 'validateExpirationDate'])->getMock();
     $user = $this->getMock('\\OCP\\IUser');
     $user->method('getUID')->willReturn('owner');
     $originalShare = new \OC\Share20\Share();
     $originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK);
     $tomorrow = new \DateTime();
     $tomorrow->setTime(0, 0, 0);
     $tomorrow->add(new \DateInterval('P1D'));
     $file = $this->getMock('OCP\\Files\\File', [], [], 'File');
     $file->method('getId')->willReturn(100);
     $share = $this->manager->newShare();
     $share->setProviderId('foo')->setId('42')->setShareType(\OCP\Share::SHARE_TYPE_LINK)->setSharedBy($user)->setShareOwner($user)->setPassword('password')->setExpirationDate($tomorrow)->setNode($file);
     $manager->expects($this->once())->method('canShare')->willReturn(true);
     $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
     $manager->expects($this->once())->method('validateExpirationDate')->with($share);
     $this->defaultProvider->expects($this->once())->method('update')->with($share)->willReturn($share);
     $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
     \OCP\Util::connectHook('OCP\\Share', 'post_set_expiration_date', $hookListner, 'post');
     $hookListner->expects($this->once())->method('post')->with(['itemType' => 'file', 'itemSource' => 100, 'date' => $tomorrow, 'uidOwner' => 'owner']);
     $manager->updateShare($share);
 }
Example #3
0
 /**
  * Create a share object from an database row
  *
  * @param mixed[] $data
  * @return \OCP\Share\IShare
  * @throws InvalidShare
  */
 private function createShare($data)
 {
     $share = new Share($this->rootFolder);
     $share->setId((int) $data['id'])->setShareType((int) $data['share_type'])->setPermissions((int) $data['permissions'])->setTarget($data['file_target'])->setMailSend((bool) $data['mail_send']);
     $shareTime = new \DateTime();
     $shareTime->setTimestamp((int) $data['stime']);
     $share->setShareTime($shareTime);
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         $share->setSharedWith($data['share_with']);
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $share->setSharedWith($data['share_with']);
         } 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
         $share->setSharedBy($data['uid_owner']);
         $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']);
         $owner = $path->getOwner();
         $share->setShareOwner($owner->getUID());
     } else {
         //New share!
         $share->setSharedBy($data['uid_initiator']);
         $share->setShareOwner($data['uid_owner']);
     }
     $share->setNodeId((int) $data['file_source']);
     $share->setNodeType($data['item_type']);
     if ($data['expiration'] !== null) {
         $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
         $share->setExpirationDate($expiration);
     }
     $share->setProviderId($this->identifier());
     return $share;
 }
Example #4
0
 /**
  * Resolve a group share to a user specific share
  * Thus if the user moved their group share make sure this is properly reflected here.
  *
  * @param Share $share
  * @param IUser $user
  * @return Share Returns the updated share if one was found else return the original share.
  */
 private function resolveGroupShare(Share $share, IUser $user)
 {
     $qb = $this->dbConn->getQueryBuilder();
     $stmt = $qb->select('*')->from('share')->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($user->getUID())))->setMaxResults(1)->execute();
     $data = $stmt->fetch();
     $stmt->closeCursor();
     if ($data !== false) {
         $share->setPermissions((int) $data['permissions']);
         $share->setTarget($data['file_target']);
     }
     return $share;
 }
Example #5
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;
 }
 /**
  * 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;
 }