diff --git a/controller/sharecontroller.php b/controller/sharecontroller.php index b8d08b3b..14c96f0c 100644 --- a/controller/sharecontroller.php +++ b/controller/sharecontroller.php @@ -301,6 +301,16 @@ class ShareController extends ApiController { public function getPublicCredentialData($credential_guid) { //@TODO if ExpireViews --, if 0 delete //@TODO Check expire date + $acl = $this->shareService->getACL(null, $credential_guid); + $views = $acl->getExpireViews(); + if($views === 0){ + return new NotFoundResponse(); + } else { + $views--; + $acl->setExpireViews($views); + $this->shareService->updateCredentialACL($acl); + } + try { $credential = $this->shareService->getSharedItem(null, $credential_guid); return new JSONResponse($credential); diff --git a/lib/Db/SharingACLMapper.php b/lib/Db/SharingACLMapper.php index 3ded3fc8..c1ed043e 100644 --- a/lib/Db/SharingACLMapper.php +++ b/lib/Db/SharingACLMapper.php @@ -69,6 +69,16 @@ class SharingACLMapper extends Mapper { return $this->findEntity($q, $filter); } + /** + * Update the acl for a given item guid + * @param $user_id + * @param $item_guid + * @return SharingACL + */ + public function updateCredentialACL(SharingACL $sharingACL) { + return $this->update($sharingACL); + } + /** * Gets the currently accepted share requests from the given user for the given vault guid * @param $user_id diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 7517ce76..88a68dbc 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -107,6 +107,12 @@ class ShareService { return $this->shareRequest->getUserPendingRequests($user_id); } + /** + * Get shared credentials from a user + * @param $user_id + * @param $vault_guid + * @return \OCA\Passman\Db\SharingACL[] + */ public function getSharedItems($user_id, $vault_guid){ $entries = $this->sharingACL->getVaultEntries($user_id, $vault_guid); @@ -125,6 +131,16 @@ class ShareService { return $return; } + /* + * Gets the acl for a given item guid + * @param $user_id + * @param $item_guid + * @return SharingACL + */ + public function getACL($user_id, $item_guid){ + return $this->sharingACL->getItemACL($user_id, $item_guid); + } + public function getSharedItem($user_id, $item_guid){ $acl = $this->sharingACL->getItemACL($user_id, $item_guid); @@ -219,7 +235,7 @@ class ShareService { } /** - * Get pending share requests by guid + * Delete ACL * * @param ShareRequest $request * @return \OCA\Passman\Db\ShareRequest[] @@ -227,4 +243,9 @@ class ShareService { public function deleteShareACL(SharingACL $ACL) { return $this->sharingACL->deleteShareACL($ACL); } + + + public function updateCredentialACL(SharingACL $sharingACL){ + return $this->sharingACL->updateCredentialACL($sharingACL); + } } \ No newline at end of file