Skip to content

Commit

Permalink
Expire link shared credential after x views
Browse files Browse the repository at this point in the history
  • Loading branch information
brantje committed Oct 4, 2016
1 parent e71a822 commit dbbe383
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions controller/sharecontroller.php
Expand Up @@ -301,6 +301,16 @@ public function deleteShareRequest($share_request_id){
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);
Expand Down
10 changes: 10 additions & 0 deletions lib/Db/SharingACLMapper.php
Expand Up @@ -69,6 +69,16 @@ public function getItemACL($user_id, $item_guid) {
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
Expand Down
23 changes: 22 additions & 1 deletion lib/Service/ShareService.php
Expand Up @@ -107,6 +107,12 @@ public function getUserPendingRequests($user_id){
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);

Expand All @@ -125,6 +131,16 @@ public function getSharedItems($user_id, $vault_guid){
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);

Expand Down Expand Up @@ -219,12 +235,17 @@ public function deleteShareRequest(ShareRequest $request) {
}

/**
* Get pending share requests by guid
* Delete ACL
*
* @param ShareRequest $request
* @return \OCA\Passman\Db\ShareRequest[]
*/
public function deleteShareACL(SharingACL $ACL) {
return $this->sharingACL->deleteShareACL($ACL);
}


public function updateCredentialACL(SharingACL $sharingACL){
return $this->sharingACL->updateCredentialACL($sharingACL);
}
}

0 comments on commit dbbe383

Please sign in to comment.