Merge pull request #48734 from nextcloud/fix/45884/accept-notification

fix: get rid of denied notification when accept
This commit is contained in:
Joas Schilling 2024-10-17 08:39:21 +02:00 committed by GitHub
commit 681ee75ab9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 12 deletions

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" id="mdi-folder-move" viewBox="0 0 24 24"><path d="M14,18V15H10V11H14V8L19,13M20,6H12L10,4H4C2.89,4 2,4.89 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V8C22,6.89 21.1,6 20,6Z" /></svg>

After

Width:  |  Height:  |  Size: 219 B

View file

@ -140,22 +140,15 @@ class TransferOwnershipController extends OCSController {
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);
}

View file

@ -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;
@ -70,6 +76,10 @@ class Notifier implements INotifier, IDismissableNotifier {
throw new UnknownNotificationException('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),
@ -259,6 +269,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 +280,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')