Skip to content

Commit

Permalink
fix(files): Properly handle denied ownership transfers
Browse files Browse the repository at this point in the history
When the receiver denies the transfer the notification handler was missing,
so no notification was created for the transfer owner.

But also the internal notification was created two times:
1. When rejecting the transfer
2. By the reject function when dismissing the notification

This is fixed by only relying on the dismiss function.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux authored and backportbot[bot] committed Jun 17, 2024
1 parent 323162f commit 90b85f3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
14 changes: 2 additions & 12 deletions apps/files/lib/Controller/TransferOwnershipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,10 @@ public function reject(int $id): DataResponse {
->setObject('transfer', (string)$id);
$this->notificationManager->markProcessed($notification);

$notification = $this->notificationManager->createNotification();
$notification->setUser($transferOwnership->getSourceUser())
->setApp($this->appName)
->setDateTime($this->timeFactory->getDateTime())
->setSubject('transferownershipRequestDenied', [
'sourceUser' => $transferOwnership->getSourceUser(),
'targetUser' => $transferOwnership->getTargetUser(),
'nodeName' => $transferOwnership->getNodeName()
])
->setObject('transfer', (string)$transferOwnership->getId());
$this->notificationManager->notify($notification);

$this->mapper->delete($transferOwnership);

// A "request denied" notification will be created by Notifier::dismissNotification

return new DataResponse([], Http::STATUS_OK);
}
}
49 changes: 32 additions & 17 deletions apps/files/lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,15 @@ public function prepare(INotification $notification, string $languageCode): INot
throw new \InvalidArgumentException('Unhandled app');
}

if ($notification->getSubject() === 'transferownershipRequest') {
return $this->handleTransferownershipRequest($notification, $languageCode);
}
if ($notification->getSubject() === 'transferOwnershipFailedSource') {
return $this->handleTransferOwnershipFailedSource($notification, $languageCode);
}
if ($notification->getSubject() === 'transferOwnershipFailedTarget') {
return $this->handleTransferOwnershipFailedTarget($notification, $languageCode);
}
if ($notification->getSubject() === 'transferOwnershipDoneSource') {
return $this->handleTransferOwnershipDoneSource($notification, $languageCode);
}
if ($notification->getSubject() === 'transferOwnershipDoneTarget') {
return $this->handleTransferOwnershipDoneTarget($notification, $languageCode);
}

throw new \InvalidArgumentException('Unhandled subject');
return match($notification->getSubject()) {
'transferownershipRequest' => $this->handleTransferownershipRequest($notification, $languageCode),
'transferownershipRequestDenied' => $this->handleTransferOwnershipRequestDenied($notification, $languageCode),
'transferOwnershipFailedSource' => $this->handleTransferOwnershipFailedSource($notification, $languageCode),
'transferOwnershipFailedTarget' => $this->handleTransferOwnershipFailedTarget($notification, $languageCode),
'transferOwnershipDoneSource' => $this->handleTransferOwnershipDoneSource($notification, $languageCode),
'transferOwnershipDoneTarget' => $this->handleTransferOwnershipDoneTarget($notification, $languageCode),
default => throw new \InvalidArgumentException('Unhandled subject')
};
}

public function handleTransferownershipRequest(INotification $notification, string $languageCode): INotification {
Expand Down Expand Up @@ -163,6 +155,29 @@ public function handleTransferownershipRequest(INotification $notification, stri
return $notification;
}

public function handleTransferOwnershipRequestDenied(INotification $notification, string $languageCode): INotification {
$l = $this->l10nFactory->get('files', $languageCode);
$param = $notification->getSubjectParameters();

$targetUser = $this->getUser($param['targetUser']);
$notification->setRichSubject($l->t('Ownership transfer denied'))
->setRichMessage(
$l->t('Your ownership transfer of {path} was denied by {user}.'),
[
'path' => [
'type' => 'highlight',
'id' => $param['targetUser'] . '::' . $param['nodeName'],
'name' => $param['nodeName'],
],
'user' => [
'type' => 'user',
'id' => $targetUser->getUID(),
'name' => $targetUser->getDisplayName(),
],
]);
return $notification;
}

public function handleTransferOwnershipFailedSource(INotification $notification, string $languageCode): INotification {
$l = $this->l10nFactory->get('files', $languageCode);
$param = $notification->getSubjectParameters();
Expand Down

0 comments on commit 90b85f3

Please sign in to comment.