diff --git a/appinfo/routes.php b/appinfo/routes.php index 11e1e846..2d032f91 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -46,5 +46,10 @@ return [ //Sharing stuff ['name' => 'share#search', 'url' => '/api/v2/sharing/search', 'verb' => 'POST'], + + //Internal API + ['name' => 'internal#remind', 'url' => '/api/internal/notifications/remind/{credential_id}', 'verb' => 'POST'], + ['name' => 'internal#read', 'url' => '/api/internal/notifications/read/{credential_id}', 'verb' => 'DELETE'], + ] ]; \ No newline at end of file diff --git a/controller/credentialcontroller.php b/controller/credentialcontroller.php index 56406b10..9519cb3d 100644 --- a/controller/credentialcontroller.php +++ b/controller/credentialcontroller.php @@ -79,8 +79,7 @@ class CredentialController extends ApiController { * @NoAdminRequired */ public function getCredential($credential_id) { - //@TODO check user - return new JSONResponse($this->credentialService->getCredentialById($credential_id)); + return new JSONResponse($this->credentialService->getCredentialById($credential_id, $this->userId)); } /** diff --git a/controller/internalcontroller.php b/controller/internalcontroller.php new file mode 100644 index 00000000..c8ad8451 --- /dev/null +++ b/controller/internalcontroller.php @@ -0,0 +1,57 @@ + + * @copyright Sander Brand 2016 + */ + +namespace OCA\Passman\Controller; + +use OCP\IRequest; +use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\ApiController; +use OCA\Passman\Service\CredentialService; + +class InternalController extends ApiController { + private $userId; + private $credentialService; + public function __construct($AppName, + IRequest $request, + $UserId, + CredentialService $credentialService){ + parent::__construct($AppName, $request); + $this->userId = $UserId; + $this->credentialService = $credentialService; + } + + function remind($credential_id){ + $credential = $this->credentialService->getCredentialById($credential_id, $this->userId); + $credential->setExpireTime(time()+ (24 * 60 * 60)); + $this->credentialService->upd($credential); + + $manager = \OC::$server->getNotificationManager(); + $notification = $manager->createNotification(); + $notification->setApp('passman') + ->setObject('credential', $credential_id) + ->setUser($this->userId); + $manager->markProcessed($notification); + } + + function read($credential_id){ + + $credential = $this->credentialService->getCredentialById($credential_id, $this->userId); + $credential->setExpireTime(0); + $this->credentialService->upd($credential); + + $manager = \OC::$server->getNotificationManager(); + $notification = $manager->createNotification(); + $notification->setApp('passman') + ->setObject('credential', $credential_id) + ->setUser($this->userId); + $manager->markProcessed($notification); + } +} \ No newline at end of file diff --git a/js/app/controllers/edit_credential.js b/js/app/controllers/edit_credential.js index b49e483b..cf08a249 100644 --- a/js/app/controllers/edit_credential.js +++ b/js/app/controllers/edit_credential.js @@ -196,6 +196,7 @@ angular.module('passmanApp') $scope.saveCredential = function () { //@TODO validation + //@TODO When credential is expired and has renew interval set, calc new expire time. delete $scope.storedCredential.password_repeat; if (!$scope.storedCredential.credential_id) { diff --git a/lib/Db/CredentialMapper.php b/lib/Db/CredentialMapper.php index 99845d18..cc8ae533 100644 --- a/lib/Db/CredentialMapper.php +++ b/lib/Db/CredentialMapper.php @@ -38,10 +38,10 @@ class CredentialMapper extends Mapper { return $this->findEntities($sql, [$timestamp]); } - public function getCredentialById($credential_id){ + public function getCredentialById($credential_id, $user_id){ $sql = 'SELECT * FROM `*PREFIX*passman_credentials` ' . - 'WHERE `id` = ?'; - return $this->findEntity($sql,[$credential_id]); + 'WHERE `id` = ? and `user_id` = ? '; + return $this->findEntity($sql,[$credential_id, $user_id]); } public function create($raw_credential){ @@ -70,7 +70,7 @@ class CredentialMapper extends Mapper { return parent::insert($credential); } - public function update($raw_credential){ + public function updateCredential($raw_credential){ if(!$raw_credential['guid']){ $raw_credential['guid'] = $this->utils->GUID(); } @@ -102,4 +102,7 @@ class CredentialMapper extends Mapper { return parent::update($credential); } + public function upd(Credential $credential){ + $this->update($credential); + } } \ No newline at end of file diff --git a/lib/Notifier.php b/lib/Notifier.php index 90a7d3be..ce63d76e 100644 --- a/lib/Notifier.php +++ b/lib/Notifier.php @@ -44,9 +44,9 @@ class Notifier implements INotifier { // Deal with the actions for a known subject foreach ($notification->getActions() as $action) { switch ($action->getLabel()) { - case 'change': + case 'remind': $action->setParsedLabel( - (string) $l->t('Change') + (string) $l->t('Remind me later') ); break; diff --git a/lib/Service/CredentialService.php b/lib/Service/CredentialService.php index 035e4101..5ba2bad9 100644 --- a/lib/Service/CredentialService.php +++ b/lib/Service/CredentialService.php @@ -30,7 +30,10 @@ class CredentialService { } public function updateCredential($credential) { - return $this->credentialMapper->update($credential); + return $this->credentialMapper->updateCredential($credential); + } + public function upd($credential) { + return $this->credentialMapper->upd($credential); } public function getCredentialsByVaultId($vault_id, $user_id) { @@ -41,7 +44,7 @@ class CredentialService { return $this->credentialMapper->getExpiredCredentials($timestamp); } - public function getCredentialById($credential_id){ - return $this->credentialMapper->getCredentialById($credential_id); + public function getCredentialById($credential_id, $user_id){ + return $this->credentialMapper->getCredentialById($credential_id, $user_id); } } \ No newline at end of file diff --git a/lib/Service/NotificationService.php b/lib/Service/NotificationService.php index 1d9a1248..089c312d 100644 --- a/lib/Service/NotificationService.php +++ b/lib/Service/NotificationService.php @@ -28,14 +28,15 @@ class NotificationService { function credentialExpiredNotification($credential){ $urlGenerator = \OC::$server->getURLGenerator(); $link = $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('','index.php/apps/passman/#/vault/'. $credential->getVaultId() .'/edit/'. $credential->getId())); + $api = $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'index.php/apps/passman')); $notification = $this->manager->createNotification(); - $acceptAction = $notification->createAction(); - $acceptAction->setLabel('change') - ->setLink('/apps/passman/api/v1/', 'POST'); + $remindAction = $notification->createAction(); + $remindAction->setLabel('remind') + ->setLink($api. '/api/internal/notifications/remind/'. $credential->getId() , 'POST'); $declineAction = $notification->createAction(); $declineAction->setLabel('ignore') - ->setLink('/apps/passman/internal/notifications/read', 'DELETE'); + ->setLink($api . '/api/internal/notifications/read/'. $credential->getId(), 'DELETE'); $notification->setApp('passman') ->setUser($credential->getUserId()) @@ -43,8 +44,8 @@ class NotificationService { ->setObject('credential', $credential->getId()) // $type and $id ->setSubject('credential_expired', [$credential->getLabel()]) // $subject and $parameters ->setLink($link) - ->addAction($acceptAction) - ->addAction($declineAction); + ->addAction($declineAction) + ->addAction($remindAction); $this->manager->notify($notification); }