diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2019-12-13 15:28:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-13 15:28:25 +0100 |
commit | c96aa7e1a820ede326d8820d27610f27f9b8481d (patch) | |
tree | e36587dab6f45d2bed33a0b2d2fb6ef96086769f | |
parent | ae6460c259dc5295c5b35e500ad4a270ca89051a (diff) | |
parent | 3f21b7b70a5c7edd204af2332417f970af5fab44 (diff) | |
download | nextcloud-server-c96aa7e1a820ede326d8820d27610f27f9b8481d.tar.gz nextcloud-server-c96aa7e1a820ede326d8820d27610f27f9b8481d.zip |
Merge pull request #18359 from nextcloud/fix/18271/dismiss_transfer_ownership_notification
Dismiss transferownership notification cancels transfer
-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); + } } |