aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorCôme Chilliet <91878298+come-nc@users.noreply.github.com>2024-06-17 09:42:49 +0200
committerGitHub <noreply@github.com>2024-06-17 09:42:49 +0200
commite01fbff8c374d39beaa9a59835b8b234d0472198 (patch)
tree0401cc44b4ef15c0c69e8c8abc17134f3a9d42e0 /apps/files
parent5baaea70f201054750b3e93db7cf88707ed9d273 (diff)
parent1550af87cd341dfd81c8338b82464123e5cb0510 (diff)
downloadnextcloud-server-e01fbff8c374d39beaa9a59835b8b234d0472198.tar.gz
nextcloud-server-e01fbff8c374d39beaa9a59835b8b234d0472198.zip
Merge pull request #45884 from nextcloud/fix/files-ownership-deny
fix(files): Properly handle denied ownership transfers
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/lib/Controller/TransferOwnershipController.php14
-rw-r--r--apps/files/lib/Notification/Notifier.php49
2 files changed, 34 insertions, 29 deletions
diff --git a/apps/files/lib/Controller/TransferOwnershipController.php b/apps/files/lib/Controller/TransferOwnershipController.php
index e5bce7946e3..924c200f375 100644
--- a/apps/files/lib/Controller/TransferOwnershipController.php
+++ b/apps/files/lib/Controller/TransferOwnershipController.php
@@ -189,20 +189,10 @@ class TransferOwnershipController extends OCSController {
->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);
}
}
diff --git a/apps/files/lib/Notification/Notifier.php b/apps/files/lib/Notification/Notifier.php
index 92a0c4f9090..b9cda6c907a 100644
--- a/apps/files/lib/Notification/Notifier.php
+++ b/apps/files/lib/Notification/Notifier.php
@@ -69,23 +69,15 @@ class Notifier implements INotifier, IDismissableNotifier {
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 {
@@ -144,6 +136,29 @@ class Notifier implements INotifier, IDismissableNotifier {
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();