Expire link shared credential after x views

This commit is contained in:
brantje 2016-10-04 13:11:37 +02:00
parent e71a82218e
commit dbbe383bf9
No known key found for this signature in database
GPG key ID: 5FF1D117F918687F
3 changed files with 42 additions and 1 deletions

View file

@ -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);

View file

@ -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

View file

@ -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);
}
}