Added api endpoint to get revisions of shared items

This commit is contained in:
Marcos Zuriaga 2016-10-03 17:20:57 +02:00
parent 48b621a378
commit b4ed5e9c76
No known key found for this signature in database
GPG key ID: 7D15585354D072FF
7 changed files with 42 additions and 6 deletions

View file

@ -56,7 +56,7 @@ return [
['name' => 'share#getPendingRequests', 'url' => '/api/v2/sharing/pending', 'verb' => 'GET'],
['name' => 'share#deleteShareRequest', 'url' => '/api/v2/sharing/decline/{share_request_id}', 'verb' => 'DELETE'],
['name' => 'share#getVaultItems', 'url' => '/api/v2/sharing/vault/{vault_guid}/get', 'verb' => 'GET'],
['name' => 'share#getRevisions', 'url' => '/api/v2/sharing/revisions/{item_guid}', 'verb' => 'GET'],
//Internal API
['name' => 'internal#remind', 'url' => '/api/internal/notifications/remind/{credential_id}', 'verb' => 'POST'],

View file

@ -221,6 +221,10 @@ class ShareController extends ApiController {
return new JSONResponse($results);
}
public function getRevisions($item_guid){
return new JSONResponse($this->shareService->getItemHistory($this->userId, $item_guid));
}
/**
* Obtains the list of credentials shared with this vault
* @NoAdminRequired

View file

@ -27,10 +27,15 @@ class CredentialRevisionMapper extends Mapper {
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
*/
public function getRevisions($credential_id, $user_id) {
public function getRevisions($credential_id, $user_id = null) {
$sql = 'SELECT * FROM `*PREFIX*passman_revisions` ' .
'WHERE `credential_id` = ? and `user_id` = ? ';
return $this->findEntities($sql, [$credential_id, $user_id]);
'WHERE `credential_id` = ?';
$params = [$credential_id];
if ($user_id !== null) {
$sql.= ' and `user_id` = ? ';
$params[] = $user_id;
}
return $this->findEntities($sql, $params);
}
public function create($credential, $userId, $credential_id) {

View file

@ -4,6 +4,7 @@
* User: wolfi
* Date: 24/09/16
* Time: 14:20
* This file is part of passman, licensed under AGPLv3
*/
namespace OCA\Passman\Db;
@ -49,6 +50,17 @@ class SharingACLMapper extends Mapper {
return $this->findEntities($q, [$user_id, $vault_id]);
}
/**
* Gets the acl for a given item guid
* @param $user_id
* @param $item_guid
* @return SharingACL
*/
public function getItemACL($user_id, $item_guid) {
$q = "SELECT * FROM " . self::TABLE_NAME . " WHERE user_id = ? AND item_guid = ?";
return $this->findEntity($q, [$user_id, $item_guid]);
}
/**
* Gets the currently accepted share requests from the given user for the given vault guid
* @param $user_id

View file

@ -29,7 +29,7 @@ class CredentialRevisionService {
return $this->credentialRevisionMapper->create($credential, $userId, $credential_id);
}
public function getRevisions($credential_id, $user_id){
public function getRevisions($credential_id, $user_id = null){
return $this->credentialRevisionMapper->getRevisions($credential_id, $user_id);
}

View file

@ -20,11 +20,18 @@ class ShareService {
private $sharingACL;
private $shareRequest;
private $credential;
private $revisions;
public function __construct(SharingACLMapper $sharingACL, ShareRequestMapper $shareRequest, CredentialMapper $credentials) {
public function __construct(
SharingACLMapper $sharingACL,
ShareRequestMapper $shareRequest,
CredentialMapper $credentials,
CredentialRevisionService $revisions
) {
$this->sharingACL = $sharingACL;
$this->shareRequest = $shareRequest;
$this->credential = $credentials;
$this->revisions = $revisions;
}
/**
@ -111,6 +118,13 @@ class ShareService {
return $return;
}
public function getItemHistory($user_id, $item_guid) {
$acl = $this->sharingACL->getItemACL($user_id, $item_guid);
if (!$acl->hasPermission(SharingACL::READ | SharingACL::HISTORY)) return [];
return $this->revisions->getRevisions($acl->getItemId());
}
/**
* Deletes an share reuqest by id

View file

@ -4,6 +4,7 @@
* User: wolfi
* Date: 2/10/16
* Time: 13:27
* This file is part of passman, licensed under AGPLv3
*/
namespace OCA\Passman\Utility;