Merge pull request #45905 from nextcloud/backport/45884/stable28

[stable28] fix(files): Properly handle denied ownership transfers
This commit is contained in:
Ferdinand Thiessen 2024-06-25 21:27:48 +02:00 committed by GitHub
commit d126e17741
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 29 deletions

View file

@ -208,20 +208,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);
}
}

View file

@ -88,23 +88,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 {
@ -163,6 +155,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();