From 173222971f181fb3ab53f18597eafcc38253cc1b Mon Sep 17 00:00:00 2001 From: brantje Date: Sun, 2 Oct 2016 18:22:12 +0200 Subject: [PATCH] Send a notification when a user declines sharing --- controller/sharecontroller.php | 14 +++++++++++++- lib/Notifier.php | 6 ++++++ lib/Service/NotificationService.php | 11 +++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/controller/sharecontroller.php b/controller/sharecontroller.php index 28455902..036da2e0 100644 --- a/controller/sharecontroller.php +++ b/controller/sharecontroller.php @@ -194,6 +194,18 @@ class ShareController extends ApiController { } public function deleteShareRequest($share_request_id){ + $sr = $this->shareService->getShareRequestById($share_request_id); + $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->credentialDeclinedSharedNotification( + $notification + ); + + $manager = \OC::$server->getNotificationManager(); $notification = $manager->createNotification(); $notification->setApp('passman') @@ -201,7 +213,7 @@ class ShareController extends ApiController { ->setUser($this->userId->getUID()); $manager->markProcessed($notification); //@TODO load other requests and delete them by item id. - $sr = $this->shareService->getShareRequestById($share_request_id); + $this->shareService->cleanItemRequestsForUser($sr); return new JSONResponse(array('result'=> true)); } diff --git a/lib/Notifier.php b/lib/Notifier.php index 63dbe030..fc4f8a45 100644 --- a/lib/Notifier.php +++ b/lib/Notifier.php @@ -81,6 +81,12 @@ 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; default: // Unknown subject => Unknown notification => throw throw new \InvalidArgumentException(); diff --git a/lib/Service/NotificationService.php b/lib/Service/NotificationService.php index e124d3f0..4d8e0e1b 100644 --- a/lib/Service/NotificationService.php +++ b/lib/Service/NotificationService.php @@ -72,4 +72,15 @@ class NotificationService { $this->manager->notify($notification); } + + function credentialDeclinedSharedNotification($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_denied', [$data['from_user'], $data['credential_label']]); // $subject and $parameters + $this->manager->notify($notification); + } + } \ No newline at end of file