From 5395566053e19821841dbffc17282f19df798b35 Mon Sep 17 00:00:00 2001 From: brantje Date: Sun, 2 Oct 2016 18:47:02 +0200 Subject: [PATCH] Send a notification on accept share request --- controller/sharecontroller.php | 12 ++++++++++++ lib/Notifier.php | 8 ++++++++ lib/Service/NotificationService.php | 11 +++++++++++ 3 files changed, 31 insertions(+) diff --git a/controller/sharecontroller.php b/controller/sharecontroller.php index 390b8fb6..469ff2e8 100644 --- a/controller/sharecontroller.php +++ b/controller/sharecontroller.php @@ -176,6 +176,18 @@ class ShareController extends ApiController { ->setUser($this->userId->getUID()); $manager->markProcessed($notification); + $notification = array( + 'from_user' => ucfirst($this->userId->getDisplayName()), + 'credential_label' => $this->credentialService->getCredentialLabelById($sr->getItemId())->getLabel(), + 'target_user' => $sr->getFromUserId(), + 'req_id' => $sr->getId() + ); + + $this->notificationService->credentialAcceptedSharedNotification( + $notification + ); + + $this->shareService->applyShare($item_guid, $target_vault_guid, $final_shared_key); } diff --git a/lib/Notifier.php b/lib/Notifier.php index fc4f8a45..0f63bd53 100644 --- a/lib/Notifier.php +++ b/lib/Notifier.php @@ -81,12 +81,20 @@ class Notifier implements INotifier { } return $notification; break; + case 'credential_share_denied': $notification->setParsedSubject( (string) $l->t('%s has declined your share request for "%s".', $notification->getSubjectParameters()) ); return $notification; break; + + case 'credential_share_accepted': + $notification->setParsedSubject( + (string) $l->t('%s has accepted your share request for "%s".', $notification->getSubjectParameters()) + ); + return $notification; + break; default: // Unknown subject => Unknown notification => throw throw new \InvalidArgumentException(); diff --git a/lib/Service/NotificationService.php b/lib/Service/NotificationService.php index 4d8e0e1b..063efb7c 100644 --- a/lib/Service/NotificationService.php +++ b/lib/Service/NotificationService.php @@ -83,4 +83,15 @@ class NotificationService { $this->manager->notify($notification); } + + function credentialAcceptedSharedNotification($data){ + $notification = $this->manager->createNotification(); + $notification->setApp('passman') + ->setUser($data['target_user']) + ->setDateTime(new \DateTime()) + ->setObject('passman_share_request', $data['req_id']) // $type and $id + ->setSubject('credential_share_accepted', [$data['from_user'], $data['credential_label']]); // $subject and $parameters + $this->manager->notify($notification); + } + } \ No newline at end of file