From 5be76411fa9cb9b883ae6c0405b44b3b6bc855e7 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Wed, 16 Oct 2024 15:01:00 +0200 Subject: [PATCH] fix: dismiss notification only after transfer bg job created - do not create 'denied' notification if bg job exists Signed-off-by: Maksim Sukharev --- .../Controller/TransferOwnershipController.php | 10 +++++----- apps/files/lib/Notification/Notifier.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/files/lib/Controller/TransferOwnershipController.php b/apps/files/lib/Controller/TransferOwnershipController.php index a71373baae4..3564b08ad6a 100644 --- a/apps/files/lib/Controller/TransferOwnershipController.php +++ b/apps/files/lib/Controller/TransferOwnershipController.php @@ -140,11 +140,6 @@ class TransferOwnershipController extends OCSController { return new DataResponse([], Http::STATUS_FORBIDDEN); } - $notification = $this->notificationManager->createNotification(); - $notification->setApp('files') - ->setObject('transfer', (string)$id); - $this->notificationManager->markProcessed($notification); - $newTransferOwnership = new TransferOwnershipEntity(); $newTransferOwnership->setNodeName($transferOwnership->getNodeName()); $newTransferOwnership->setFileId($transferOwnership->getFileId()); @@ -156,6 +151,11 @@ class TransferOwnershipController extends OCSController { 'id' => $newTransferOwnership->getId(), ]); + $notification = $this->notificationManager->createNotification(); + $notification->setApp('files') + ->setObject('transfer', (string)$id); + $this->notificationManager->markProcessed($notification); + return new DataResponse([], Http::STATUS_OK); } diff --git a/apps/files/lib/Notification/Notifier.php b/apps/files/lib/Notification/Notifier.php index bae3a513df7..5a82499e36e 100644 --- a/apps/files/lib/Notification/Notifier.php +++ b/apps/files/lib/Notification/Notifier.php @@ -8,9 +8,11 @@ declare(strict_types=1); */ namespace OCA\Files\Notification; +use OCA\Files\BackgroundJob\TransferOwnership; use OCA\Files\Db\TransferOwnershipMapper; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\IJobList; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; @@ -36,15 +38,19 @@ class Notifier implements INotifier, IDismissableNotifier { private $userManager; /** @var ITimeFactory */ private $timeFactory; + /** @var IJobList */ + private $jobList; public function __construct(IFactory $l10nFactory, IURLGenerator $urlGenerator, TransferOwnershipMapper $mapper, IManager $notificationManager, IUserManager $userManager, + IJobList $jobList, ITimeFactory $timeFactory) { $this->l10nFactory = $l10nFactory; $this->urlGenerator = $urlGenerator; + $this->jobList = $jobList; $this->mapper = $mapper; $this->notificationManager = $notificationManager; $this->userManager = $userManager; @@ -259,6 +265,9 @@ class Notifier implements INotifier, IDismissableNotifier { if ($notification->getApp() !== 'files') { throw new UnknownNotificationException('Unhandled app'); } + if ($notification->getSubject() !== 'transferownershipRequest') { + throw new UnknownNotificationException('Unhandled notification type'); + } // TODO: This should all be moved to a service that also the transferownershipController uses. try { @@ -267,6 +276,12 @@ class Notifier implements INotifier, IDismissableNotifier { return; } + if ($this->jobList->has(TransferOwnership::class, [ + 'id' => $transferOwnership->getId(), + ])) { + return; + } + $notification = $this->notificationManager->createNotification(); $notification->setUser($transferOwnership->getSourceUser()) ->setApp('files') -- 2.39.5