Skip to content

Commit

Permalink
fix: dismiss notification only after transfer bg job created
Browse files Browse the repository at this point in the history
- do not create 'denied' notification if bg job exists

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Oct 17, 2024
1 parent fca5e23 commit 4435052
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 5 additions & 5 deletions apps/files/lib/Controller/TransferOwnershipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ public function accept(int $id): DataResponse {
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());
Expand All @@ -176,6 +171,11 @@ public function accept(int $id): DataResponse {
'id' => $newTransferOwnership->getId(),
]);

$notification = $this->notificationManager->createNotification();
$notification->setApp('files')
->setObject('transfer', (string)$id);
$this->notificationManager->markProcessed($notification);

return new DataResponse([], Http::STATUS_OK);
}

Expand Down
15 changes: 15 additions & 0 deletions apps/files/lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -281,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 {
Expand All @@ -289,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')
Expand Down

0 comments on commit 4435052

Please sign in to comment.