Add route to update revisions

This commit is contained in:
brantje 2016-10-05 14:30:28 +02:00
parent c62a0a8d7c
commit f80263dff0
No known key found for this signature in database
GPG key ID: 5FF1D117F918687F
4 changed files with 42 additions and 0 deletions

View file

@ -41,6 +41,7 @@ return [
//Revisions
['name' => 'credential#getRevision', 'url' => '/api/v2/credentials/{credential_id}/revision', 'verb' => 'GET'],
['name' => 'credential#deleteRevision', 'url' => '/api/v2/credentials/{credential_id}/revision/{revision_id}', 'verb' => 'DELETE'],
['name' => 'credential#updateRevision', 'url' => '/api/v2/credentials/{credential_id}/revision/{revision_id}', 'verb' => 'PATCH'],
//File stuff
['name' => 'file#uploadFile', 'url' => '/api/v2/file', 'verb' => 'POST'],

View file

@ -13,6 +13,7 @@ namespace OCA\Passman\Controller;
use OCA\Files_External\NotFoundException;
use OCA\Passman\Db\SharingACL;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
@ -256,4 +257,19 @@ class CredentialController extends ApiController {
$result = $this->credentialRevisionService->deleteRevision($revision_id, $this->userId);
return new JSONResponse($result);
}
/**
* @NoAdminRequired
*/
public function updateRevision($credential_id, $revision_id, $credential_data){
$revision = null;
try{
$revision = $this->credentialRevisionService->getRevision($revision_id);
} catch(DoesNotExistException $exception){
return new NotFoundResponse();
}
$revision->setCredentialData($credential_data);
$this->credentialRevisionService->updateRevision($revision);
}
}

View file

@ -38,6 +38,22 @@ class CredentialRevisionMapper extends Mapper {
return $this->findEntities($sql, $params);
}
/**
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return CredentialRevision
*/
public function getRevision($revision_id, $user_id = null) {
$sql = 'SELECT * FROM `*PREFIX*passman_revisions` ' .
'WHERE `id` = ?';
$params = [$revision_id];
if ($user_id !== null) {
$sql.= ' and `user_id` = ? ';
$params[] = $user_id;
}
return $this->findEntity($sql, $params);
}
public function create($credential, $userId, $credential_id, $edited_by) {
$revision = new CredentialRevision();
$revision->setGuid($this->utils->GUID());

View file

@ -11,6 +11,7 @@
namespace OCA\Passman\Service;
use OCA\Passman\Db\CredentialRevision;
use OCP\IConfig;
use OCP\AppFramework\Db\DoesNotExistException;
@ -33,7 +34,15 @@ class CredentialRevisionService {
return $this->credentialRevisionMapper->getRevisions($credential_id, $user_id);
}
public function getRevision($credential_id, $user_id = null){
return $this->credentialRevisionMapper->getRevision($credential_id, $user_id);
}
public function deleteRevision($revision_id, $user_id){
return $this->credentialRevisionMapper->deleteRevision($revision_id, $user_id);
}
public function updateRevision(CredentialRevision $credentialRevision){
return $this->credentialRevisionMapper->update($credentialRevision);
}
}