mirror of
https://github.com/nextcloud/passman.git
synced 2024-09-20 23:06:24 +08:00
Revision backend working
This commit is contained in:
parent
fb0fabfd44
commit
6b6eaaf070
|
@ -126,7 +126,6 @@
|
||||||
<type>clob</type>
|
<type>clob</type>
|
||||||
<notnull>false</notnull>
|
<notnull>false</notnull>
|
||||||
</field>
|
</field>
|
||||||
|
|
||||||
<field>
|
<field>
|
||||||
<name>created</name>
|
<name>created</name>
|
||||||
<type>integer</type>
|
<type>integer</type>
|
||||||
|
@ -332,10 +331,18 @@
|
||||||
<notnull>true</notnull>
|
<notnull>true</notnull>
|
||||||
<length>64</length>
|
<length>64</length>
|
||||||
</field>
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>created</name>
|
||||||
|
<type>integer</type>
|
||||||
|
<length>8</length>
|
||||||
|
<default>0</default>
|
||||||
|
<notnull>false</notnull>
|
||||||
|
<unsigned>true</unsigned>
|
||||||
|
</field>
|
||||||
<field>
|
<field>
|
||||||
<name>credential_data</name>
|
<name>credential_data</name>
|
||||||
<type>clob</type>
|
<type>clob</type>
|
||||||
<notnull>false</notnull>
|
<notnull>true</notnull>
|
||||||
</field>
|
</field>
|
||||||
<index>
|
<index>
|
||||||
<name>passman_revision_id_index</name>
|
<name>passman_revision_id_index</name>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<description>A password manager for Nextcloud</description>
|
<description>A password manager for Nextcloud</description>
|
||||||
<licence>AGPL</licence>
|
<licence>AGPL</licence>
|
||||||
<author>Sander Brand</author>
|
<author>Sander Brand</author>
|
||||||
<version>1.0.2.5</version>
|
<version>1.0.2.6</version>
|
||||||
<namespace>Passman</namespace>
|
<namespace>Passman</namespace>
|
||||||
<category>other</category>
|
<category>other</category>
|
||||||
<website>https://github.com/nextcloud/passman/</website>
|
<website>https://github.com/nextcloud/passman/</website>
|
||||||
|
|
|
@ -17,21 +17,24 @@ use OCP\AppFramework\ApiController;
|
||||||
use OCA\Passman\Service\CredentialService;
|
use OCA\Passman\Service\CredentialService;
|
||||||
use OCA\Passman\Activity;
|
use OCA\Passman\Activity;
|
||||||
use OCA\Passman\Service\ActivityService;
|
use OCA\Passman\Service\ActivityService;
|
||||||
|
use OCA\Passman\Service\CredentialRevisionService;
|
||||||
class CredentialController extends ApiController {
|
class CredentialController extends ApiController {
|
||||||
private $userId;
|
private $userId;
|
||||||
private $credentialService;
|
private $credentialService;
|
||||||
private $activityService;
|
private $activityService;
|
||||||
|
private $credentialRevisionService;
|
||||||
|
|
||||||
public function __construct($AppName,
|
public function __construct($AppName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
$UserId,
|
$UserId,
|
||||||
CredentialService $credentialService,
|
CredentialService $credentialService,
|
||||||
ActivityService $activityService) {
|
ActivityService $activityService,
|
||||||
|
CredentialRevisionService $credentialRevisionService) {
|
||||||
parent::__construct($AppName, $request);
|
parent::__construct($AppName, $request);
|
||||||
$this->userId = $UserId;
|
$this->userId = $UserId;
|
||||||
$this->credentialService = $credentialService;
|
$this->credentialService = $credentialService;
|
||||||
$this->activityService = $activityService;
|
$this->activityService = $activityService;
|
||||||
|
$this->credentialRevisionService = $credentialRevisionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,7 +144,7 @@ class CredentialController extends ApiController {
|
||||||
$link, $this->userId, Activity::TYPE_ITEM_ACTION);
|
$link, $this->userId, Activity::TYPE_ITEM_ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->credentialRevisionService->createRevision($credential, $this->userId, $credential_id);
|
||||||
$credential = $this->credentialService->updateCredential($credential);
|
$credential = $this->credentialService->updateCredential($credential);
|
||||||
|
|
||||||
return new JSONResponse($credential);
|
return new JSONResponse($credential);
|
||||||
|
@ -169,7 +172,8 @@ class CredentialController extends ApiController {
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
public function getRevision($credential_id) {
|
public function getRevision($credential_id) {
|
||||||
return;
|
$result = $this->credentialRevisionService->getRevisions($credential_id, $this->userId);
|
||||||
|
return new JSONResponse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,14 +28,24 @@ angular.module('passmanApp')
|
||||||
}
|
}
|
||||||
var storedCredential = SettingsService.getSetting('edit_credential');
|
var storedCredential = SettingsService.getSetting('edit_credential');
|
||||||
|
|
||||||
|
var getRevisions = function () {
|
||||||
|
CredentialService.getRevisions($scope.storedCredential.credential_id).then(function (revisions) {
|
||||||
|
console.log(revisions)
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
if (!storedCredential) {
|
if (!storedCredential) {
|
||||||
CredentialService.getCredential($routeParams.credential_id).then(function(result){
|
CredentialService.getCredential($routeParams.credential_id).then(function(result){
|
||||||
$scope.storedCredential = CredentialService.decryptCredential(angular.copy(result));
|
$scope.storedCredential = CredentialService.decryptCredential(angular.copy(result));
|
||||||
|
getRevisions();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$scope.storedCredential = CredentialService.decryptCredential(angular.copy(storedCredential));
|
$scope.storedCredential = CredentialService.decryptCredential(angular.copy(storedCredential));
|
||||||
|
getRevisions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$scope.cancel = function () {
|
$scope.cancel = function () {
|
||||||
$location.path('/vault/' + $routeParams.vault_id);
|
$location.path('/vault/' + $routeParams.vault_id);
|
||||||
$scope.storedCredential = null;
|
$scope.storedCredential = null;
|
||||||
|
|
|
@ -115,6 +115,16 @@ angular.module('passmanApp')
|
||||||
|
|
||||||
}
|
}
|
||||||
return credential;
|
return credential;
|
||||||
|
},
|
||||||
|
getRevisions: function(id){
|
||||||
|
var queryUrl = OC.generateUrl('apps/passman/api/v2/credentials/' + id + '/revision');
|
||||||
|
return $http.get(queryUrl).then(function (response) {
|
||||||
|
if (response.data) {
|
||||||
|
return response.data;
|
||||||
|
} else {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
|
|
58
lib/Db/CredentialRevision.php
Normal file
58
lib/Db/CredentialRevision.php
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Nextcloud - passman
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later. See the COPYING file.
|
||||||
|
*
|
||||||
|
* @author Sander Brand <brantje@gmail.com>
|
||||||
|
* @copyright Sander Brand 2016
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Passman\Db;
|
||||||
|
|
||||||
|
use \OCP\AppFramework\Db\Entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method void setId(integer $value)
|
||||||
|
* @method integer getId()
|
||||||
|
* @method void setGuid(string $value)
|
||||||
|
* @method string getGuid()
|
||||||
|
* @method void setCredentialId(integer $value)
|
||||||
|
* @method string getCredentialId()
|
||||||
|
* @method void setUserId(string $value)
|
||||||
|
* @method string getUserid()
|
||||||
|
* @method void setCreated(integer $value)
|
||||||
|
* @method integer getCreated()
|
||||||
|
* @method void setCredentialData(string $value)
|
||||||
|
* @method string getCredentialData()
|
||||||
|
*/
|
||||||
|
class CredentialRevision extends Entity implements \JsonSerializable {
|
||||||
|
|
||||||
|
use EntityJSONSerializer;
|
||||||
|
|
||||||
|
protected $guid;
|
||||||
|
protected $credentialId;
|
||||||
|
protected $userId;
|
||||||
|
protected $created;
|
||||||
|
protected $credentialData;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
// add types in constructor
|
||||||
|
$this->addType('created', 'integer');
|
||||||
|
$this->addType('credentialId', 'integer');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns entity attributes into an array
|
||||||
|
*/
|
||||||
|
public function jsonSerialize() {
|
||||||
|
return [
|
||||||
|
'revision_id' => $this->getId(),
|
||||||
|
'guid' => $this->getGuid(),
|
||||||
|
'created' => $this->getCreated(),
|
||||||
|
'credential_data' => unserialize(base64_decode($this->getCredentialData())),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
52
lib/Db/CredentialRevisionMapper.php
Normal file
52
lib/Db/CredentialRevisionMapper.php
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Nextcloud - passman
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later. See the COPYING file.
|
||||||
|
*
|
||||||
|
* @author Sander Brand <brantje@gmail.com>
|
||||||
|
* @copyright Sander Brand 2016
|
||||||
|
*/
|
||||||
|
namespace OCA\Passman\Db;
|
||||||
|
|
||||||
|
use OCA\Passman\Utility\Utils;
|
||||||
|
use OCP\IDBConnection;
|
||||||
|
use OCP\AppFramework\Db\Mapper;
|
||||||
|
|
||||||
|
class CredentialRevisionMapper extends Mapper {
|
||||||
|
private $utils;
|
||||||
|
|
||||||
|
public function __construct(IDBConnection $db, Utils $utils) {
|
||||||
|
parent::__construct($db, 'passman_revisions');
|
||||||
|
$this->utils = $utils;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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) {
|
||||||
|
$sql = 'SELECT * FROM `*PREFIX*passman_revisions` ' .
|
||||||
|
'WHERE `credential_id` = ? and `user_id` = ? ';
|
||||||
|
return $this->findEntities($sql, [$credential_id, $user_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create($credential, $userId, $credential_id) {
|
||||||
|
$revision = new CredentialRevision();
|
||||||
|
$revision->setGuid($this->utils->GUID());
|
||||||
|
$revision->setUserId($userId);
|
||||||
|
$revision->setCreated($this->utils->getTime());
|
||||||
|
$revision->setCredentialId($credential_id);
|
||||||
|
$revision->setCredentialData(base64_encode(serialize($credential)));
|
||||||
|
return $this->insert($revision);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteFile($revision_id, $user_id) {
|
||||||
|
$file = new CredentialRevision();
|
||||||
|
$file->setId($revision_id);
|
||||||
|
$file->setUserId($user_id);
|
||||||
|
$this->delete($file);
|
||||||
|
}
|
||||||
|
}
|
35
lib/Service/CredentialRevisionService.php
Normal file
35
lib/Service/CredentialRevisionService.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Nextcloud - passman
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later. See the COPYING file.
|
||||||
|
*
|
||||||
|
* @author Sander Brand <brantje@gmail.com>
|
||||||
|
* @copyright Sander Brand 2016
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Passman\Service;
|
||||||
|
|
||||||
|
use OCP\IConfig;
|
||||||
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
|
|
||||||
|
use OCA\Passman\Db\CredentialRevisionMapper;
|
||||||
|
|
||||||
|
|
||||||
|
class CredentialRevisionService {
|
||||||
|
|
||||||
|
private $credentialRevisionMapper;
|
||||||
|
|
||||||
|
public function __construct(CredentialRevisionMapper $credentialRevisionMapper) {
|
||||||
|
$this->credentialRevisionMapper = $credentialRevisionMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createRevision($credential, $userId, $credential_id) {
|
||||||
|
return $this->credentialRevisionMapper->create($credential, $userId, $credential_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRevisions($credential_id, $user_id){
|
||||||
|
return $this->credentialRevisionMapper->getRevisions($credential_id, $user_id);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue