mirror of
https://github.com/nextcloud/spreed.git
synced 2025-12-18 05:20:50 +01:00
Send notification to the sharer that a password has been requested
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
parent
94b4a18505
commit
efc9d95b22
2 changed files with 53 additions and 0 deletions
|
|
@ -33,6 +33,7 @@ use OCP\IL10N;
|
|||
use OCP\IRequest;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Notification\IManager as NotificationManager;
|
||||
use OCP\Share\IManager as ShareManager;
|
||||
use OCP\Share\Exceptions\ShareNotFound;
|
||||
|
||||
|
|
@ -40,6 +41,8 @@ class PublicShareAuthController extends OCSController {
|
|||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var NotificationManager */
|
||||
private $notificationManager;
|
||||
/** @var ShareManager */
|
||||
private $shareManager;
|
||||
/** @var Manager */
|
||||
|
|
@ -51,6 +54,7 @@ class PublicShareAuthController extends OCSController {
|
|||
* @param string $appName
|
||||
* @param IRequest $request
|
||||
* @param IUserManager $userManager
|
||||
* @param NotificationManager $notificationManager
|
||||
* @param ShareManager $shareManager
|
||||
* @param Manager $manager
|
||||
* @param IL10N $l10n
|
||||
|
|
@ -59,12 +63,14 @@ class PublicShareAuthController extends OCSController {
|
|||
string $appName,
|
||||
IRequest $request,
|
||||
IUserManager $userManager,
|
||||
NotificationManager $notificationManager,
|
||||
ShareManager $shareManager,
|
||||
Manager $manager,
|
||||
IL10N $l10n
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->userManager = $userManager;
|
||||
$this->notificationManager = $notificationManager;
|
||||
$this->shareManager = $shareManager;
|
||||
$this->manager = $manager;
|
||||
$this->l10n = $l10n;
|
||||
|
|
@ -130,6 +136,18 @@ class PublicShareAuthController extends OCSController {
|
|||
'participantType' => Participant::OWNER,
|
||||
]);
|
||||
|
||||
// Notify the owner
|
||||
$notification = $this->notificationManager->createNotification();
|
||||
$notification
|
||||
->setApp('spreed')
|
||||
->setObject('room', $room->getToken())
|
||||
->setUser($sharerUser->getUID())
|
||||
->setSubject('share:password', [
|
||||
'sharedWith' => $share->getSharedWith(),
|
||||
])
|
||||
->setDateTime(new \DateTime());
|
||||
$this->notificationManager->notify($notification);
|
||||
|
||||
return new DataResponse([
|
||||
'token' => $room->getToken(),
|
||||
'name' => $room->getName(),
|
||||
|
|
|
|||
|
|
@ -100,6 +100,9 @@ class Notifier implements INotifier {
|
|||
if ($subject === 'mention' || $subject === 'chat') {
|
||||
return $this->parseMention($notification, $room, $l);
|
||||
}
|
||||
if ($subject === 'share:password') {
|
||||
return $this->parsePasswordRequest($notification, $room, $l);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Unknown subject');
|
||||
}
|
||||
|
|
@ -401,4 +404,36 @@ class Notifier implements INotifier {
|
|||
|
||||
return $notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param INotification $notification
|
||||
* @param Room $room
|
||||
* @param IL10N $l
|
||||
* @return INotification
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function parsePasswordRequest(INotification $notification, Room $room, IL10N $l) {
|
||||
if ($notification->getObjectType() !== 'room') {
|
||||
throw new \InvalidArgumentException('Unknown object type');
|
||||
}
|
||||
|
||||
$parameters = $notification->getSubjectParameters();
|
||||
$sharedWith = $parameters['sharedWith'];
|
||||
|
||||
$notification
|
||||
->setParsedSubject(
|
||||
$l->t('Password request by %s', [$sharedWith])
|
||||
)
|
||||
->setRichSubject(
|
||||
$l->t('{email} requested the password to access a share'), [
|
||||
'email' => [
|
||||
'type' => 'email',
|
||||
'id' => $sharedWith,
|
||||
'name' => $sharedWith,
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
return $notification;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue