diff --git a/apps/files/img/folder-move.svg b/apps/files/img/folder-move.svg new file mode 100644 index 0000000000000..349106f4cd927 --- /dev/null +++ b/apps/files/img/folder-move.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/apps/files/lib/Controller/TransferOwnershipController.php b/apps/files/lib/Controller/TransferOwnershipController.php index eec654bd678d1..d3256b2c7cc77 100644 --- a/apps/files/lib/Controller/TransferOwnershipController.php +++ b/apps/files/lib/Controller/TransferOwnershipController.php @@ -160,22 +160,15 @@ public function accept(int $id): DataResponse { return new DataResponse([], Http::STATUS_FORBIDDEN); } + $this->jobList->add(TransferOwnership::class, [ + 'id' => $transferOwnership->getId(), + ]); + $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()); - $newTransferOwnership->setSourceUser($transferOwnership->getSourceUser()); - $newTransferOwnership->setTargetUser($transferOwnership->getTargetUser()); - $this->mapper->insert($newTransferOwnership); - - $this->jobList->add(TransferOwnership::class, [ - 'id' => $newTransferOwnership->getId(), - ]); - return new DataResponse([], Http::STATUS_OK); } diff --git a/apps/files/lib/Notification/Notifier.php b/apps/files/lib/Notification/Notifier.php index 10954ac9c6492..d73ab2d69b076 100644 --- a/apps/files/lib/Notification/Notifier.php +++ b/apps/files/lib/Notification/Notifier.php @@ -27,9 +27,11 @@ */ 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; @@ -88,6 +94,10 @@ public function prepare(INotification $notification, string $languageCode): INot throw new \InvalidArgumentException('Unhandled app'); } + $imagePath = $this->urlGenerator->imagePath('files', 'folder-move.svg'); + $iconUrl = $this->urlGenerator->getAbsoluteURL($imagePath); + $notification->setIcon($iconUrl); + return match($notification->getSubject()) { 'transferownershipRequest' => $this->handleTransferownershipRequest($notification, $languageCode), 'transferownershipRequestDenied' => $this->handleTransferOwnershipRequestDenied($notification, $languageCode), @@ -277,6 +287,9 @@ public function dismissNotification(INotification $notification): void { 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 { @@ -285,6 +298,12 @@ public function dismissNotification(INotification $notification): void { return; } + if ($this->jobList->has(TransferOwnership::class, [ + 'id' => $transferOwnership->getId(), + ])) { + return; + } + $notification = $this->notificationManager->createNotification(); $notification->setUser($transferOwnership->getSourceUser()) ->setApp('files')