Send a notification when a user declines sharing

This commit is contained in:
brantje 2016-10-02 18:22:12 +02:00
parent 14c2ec26fb
commit 173222971f
No known key found for this signature in database
GPG key ID: 5FF1D117F918687F
3 changed files with 30 additions and 1 deletions

View file

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

View file

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

View file

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