diff options
author | Maksim Sukharev <antreesy.web@gmail.com> | 2024-10-16 15:01:00 +0200 |
---|---|---|
committer | Maksim Sukharev <antreesy.web@gmail.com> | 2024-10-17 09:24:50 +0200 |
commit | 443505206ddf1226e3be7ee8ff8c2f736b72f2b3 (patch) | |
tree | 15d1670c0324936a7d1f5c4b81196737cdfe8581 | |
parent | fca5e23375efcc96a2c044bc13a3833a977039a6 (diff) | |
download | nextcloud-server-443505206ddf1226e3be7ee8ff8c2f736b72f2b3.tar.gz nextcloud-server-443505206ddf1226e3be7ee8ff8c2f736b72f2b3.zip |
fix: dismiss notification only after transfer bg job created
- do not create 'denied' notification if bg job exists
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
-rw-r--r-- | apps/files/lib/Controller/TransferOwnershipController.php | 10 | ||||
-rw-r--r-- | 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 eec654bd678..43648528b50 100644 --- a/apps/files/lib/Controller/TransferOwnershipController.php +++ b/apps/files/lib/Controller/TransferOwnershipController.php @@ -160,11 +160,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()); @@ -176,6 +171,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 caf707cc6e3..d73ab2d69b0 100644 --- a/apps/files/lib/Notification/Notifier.php +++ b/apps/files/lib/Notification/Notifier.php @@ -27,9 +27,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; @@ -54,15 +56,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; @@ -281,6 +287,9 @@ class Notifier implements INotifier, IDismissableNotifier { if ($notification->getApp() !== 'files') { throw new \InvalidArgumentException('Unhandled app'); } + if ($notification->getSubject() !== 'transferownershipRequest') { + throw new \InvalidArgumentException('Unhandled notification type'); + } // TODO: This should all be moved to a service that also the transferownershipController uses. try { @@ -289,6 +298,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') |