Notification buttons working

This commit is contained in:
brantje 2016-09-23 18:17:47 +02:00
parent cbd8406854
commit 188b5129fa
8 changed files with 86 additions and 17 deletions

View file

@ -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'],
]
];

View file

@ -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));
}
/**

View file

@ -0,0 +1,57 @@
<?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\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);
}
}

View file

@ -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) {

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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);
}