Api endpoint logic to gather the ACL of a credential

This commit is contained in:
Marcos Zuriaga 2016-10-04 14:40:48 +02:00
parent af1c38f9c7
commit bca3cefd0c
No known key found for this signature in database
GPG key ID: 7D15585354D072FF
4 changed files with 31 additions and 0 deletions

View file

@ -59,6 +59,7 @@ return [
['name' => 'share#getPublicCredentialData', 'url' => '/api/v2/sharing/credential/{credential_guid}/public', 'verb' => 'GET'],
['name' => 'share#unshareCredential', 'url' => '/api/v2/sharing/credential/{item_guid}', 'verb' => 'DELETE'],
['name' => 'share#getRevisions', 'url' => '/api/v2/sharing/credential/{item_guid}/revisions', 'verb' => 'GET'],
['name' => 'share#getItemAcl', 'url' => '/api/v2/sharing/credential/{item_guid}/acl', 'verb' => 'GET'],
//Internal API
['name' => 'internal#remind', 'url' => '/api/internal/notifications/remind/{credential_id}', 'verb' => 'POST'],

View file

@ -322,4 +322,20 @@ class ShareController extends ApiController {
return new NotFoundResponse();
}
}
public function getItemAcl($item_guid){
$acl = $this->shareService->getCredentialAclList($item_guid);
try {
$credential = $this->credentialService->getCredentialByGUID($item_guid);
if ($credential->getUserId() == $this->userId){
return new JSONResponse($acl);
}
else{
return new NotFoundResponse();
}
}
catch (DoesNotExistException $ex){
return new NotFoundResponse();
}
}
}

View file

@ -134,4 +134,14 @@ class CredentialMapper extends Mapper {
public function upd(Credential $credential){
$this->update($credential);
}
/**
* Finds a credential by the given guid
* @param $credential_guid
* @return Credential
*/
public function getCredentialByGUID($credential_guid){
$q = 'SELECT * FROM `*PREFIX*passman_credentials` WHERE guid = ? ';
return $this->findEntity($q, [$credential_guid]);
}
}

View file

@ -73,4 +73,8 @@ class CredentialService {
public function getCredentialLabelById($credential_id){
return $this->credentialMapper->getCredentialLabelById($credential_id);
}
public function getCredentialByGUID($credential_guid){
return $this->credentialMapper->getCredentialByGUID($credential_guid);
}
}