mirror of
https://github.com/nextcloud/passman.git
synced 2026-01-05 23:27:04 +08:00
Send a notification when a user declines sharing
This commit is contained in:
parent
14c2ec26fb
commit
173222971f
3 changed files with 30 additions and 1 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue