diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-12-11 12:58:44 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-12-11 12:58:44 +0100 |
commit | 3f21b7b70a5c7edd204af2332417f970af5fab44 (patch) | |
tree | b8a65ee960202d530ea3e6f8b29a9e8cad2cda23 | |
parent | 97deaf85b9d18cabfc345025ef273da24006c6de (diff) | |
download | nextcloud-server-3f21b7b70a5c7edd204af2332417f970af5fab44.tar.gz nextcloud-server-3f21b7b70a5c7edd204af2332417f970af5fab44.zip |
Dismiss transferownership notification cancels transfer
Fixes #18271
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r-- | apps/files/lib/Notification/Notifier.php | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/apps/files/lib/Notification/Notifier.php b/apps/files/lib/Notification/Notifier.php index ab7956a54f9..aa3fa6bfa26 100644 --- a/apps/files/lib/Notification/Notifier.php +++ b/apps/files/lib/Notification/Notifier.php @@ -27,27 +27,47 @@ declare(strict_types=1); namespace OCA\Files\Notification; +use OCA\Files\Db\TransferOwnershipMapper; +use OCP\AppFramework\Db\DoesNotExistException; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\IURLGenerator; use OCP\L10N\IFactory; use OCP\Notification\IAction; +use OCP\Notification\IDismissableNotifier; +use OCP\Notification\IManager; use OCP\Notification\INotification; use OCP\Notification\INotifier; -class Notifier implements INotifier { +class Notifier implements INotifier, IDismissableNotifier { /** @var IFactory */ protected $l10nFactory; /** @var IURLGenerator */ protected $urlGenerator; + /** @var TransferOwnershipMapper */ + private $mapper; + /** @var IManager */ + private $notificationManager; + /** @var ITimeFactory */ + private $timeFactory; /** * @param IFactory $l10nFactory * @param IURLGenerator $urlGenerator */ - public function __construct(IFactory $l10nFactory, IURLGenerator $urlGenerator) { + public function __construct(IFactory $l10nFactory, + IURLGenerator $urlGenerator, + TransferOwnershipMapper $mapper, + IManager $notificationManager, + ITimeFactory $timeFactory) { $this->l10nFactory = $l10nFactory; $this->urlGenerator = $urlGenerator; + $this->mapper = $mapper; + $this->notificationManager = $notificationManager; + $this->timeFactory = $timeFactory; } public function getID(): string { @@ -247,4 +267,31 @@ class Notifier implements INotifier { return $notification; } + + public function dismissNotification(INotification $notification): void { + if ($notification->getApp() !== 'files') { + throw new \InvalidArgumentException('Unhandled app'); + } + + // TODO: This should all be moved to a service that also the transferownershipContoller uses. + try { + $transferOwnership = $this->mapper->getById((int)$notification->getObjectId()); + } catch (DoesNotExistException $e) { + return; + } + + $notification = $this->notificationManager->createNotification(); + $notification->setUser($transferOwnership->getSourceUser()) + ->setApp('files') + ->setDateTime($this->timeFactory->getDateTime()) + ->setSubject('transferownershipRequestDenied', [ + 'sourceUser' => $transferOwnership->getSourceUser(), + 'targetUser' => $transferOwnership->getTargetUser(), + 'nodeName' => $transferOwnership->getNodeName() + ]) + ->setObject('transfer', (string)$transferOwnership->getId()); + $this->notificationManager->notify($notification); + + $this->mapper->delete($transferOwnership); + } } |