Skip to content

Commit 5c977ac

Browse files
committed
fix: translate mount move error messages
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent d700c13 commit 5c977ac

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

lib/private/Files/View.php

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
use OCP\Files\NotFoundException;
6969
use OCP\Files\ReservedWordException;
7070
use OCP\Files\Storage\IStorage;
71+
use OCP\IL10N;
7172
use OCP\IUser;
73+
use OCP\L10N\IFactory;
7274
use OCP\Lock\ILockingProvider;
7375
use OCP\Lock\LockedException;
7476
use Psr\Log\LoggerInterface;
@@ -96,6 +98,7 @@ class View {
9698
private bool $updaterEnabled = true;
9799
private UserManager $userManager;
98100
private LoggerInterface $logger;
101+
private IL10N $l10n;
99102

100103
/**
101104
* @throws \Exception If $root contains an invalid path
@@ -110,6 +113,7 @@ public function __construct(string $root = '') {
110113
$this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider);
111114
$this->userManager = \OC::$server->getUserManager();
112115
$this->logger = \OC::$server->get(LoggerInterface::class);
116+
$this->l10n = \OC::$server->get(IFactory::class)->get('files');
113117
}
114118

115119
/**
@@ -872,30 +876,51 @@ public function rename($source, $target) {
872876
return $result;
873877
}
874878

879+
/**
880+
* @throws ForbiddenException
881+
*/
875882
private function validateMountMove(array $mounts, IMountPoint $sourceMount, IMountPoint $targetMount, bool $targetIsShared): void {
876-
$targetType = 'storage';
877-
if ($targetMount instanceof SharedMount) {
878-
$targetType = 'share';
883+
$targetPath = $this->getRelativePath($targetMount->getMountPoint());
884+
if ($targetPath) {
885+
$targetPath = trim($targetPath, '/');
886+
} else {
887+
$targetPath = $targetMount->getMountPoint();
879888
}
880-
$targetPath = rtrim($targetMount->getMountPoint(), '/');
881889

882890
foreach ($mounts as $mount) {
883-
$sourcePath = rtrim($mount->getMountPoint(), '/');
884-
$sourceType = 'storage';
885-
if ($mount instanceof SharedMount) {
886-
$sourceType = 'share';
891+
$sourcePath = $this->getRelativePath($mount->getMountPoint());
892+
if ($sourcePath) {
893+
$sourcePath = trim($sourcePath, '/');
894+
} else {
895+
$sourcePath = $mount->getMountPoint();
887896
}
888897

889898
if (!$mount instanceof MoveableMount) {
890-
throw new ForbiddenException("Storage {$sourcePath} cannot be moved", false);
899+
throw new ForbiddenException($this->l10n->t('Storage %s cannot be moved', [$sourcePath]), false);
891900
}
892901

893902
if ($targetIsShared) {
894-
throw new ForbiddenException("Moving a $sourceType ($sourcePath) into shared folder is not allowed", false);
903+
if ($sourceMount instanceof SharedMount) {
904+
throw new ForbiddenException($this->l10n->t('Moving a share (%s) into a shared folder is not allowed', [$sourcePath]), false);
905+
} else {
906+
throw new ForbiddenException($this->l10n->t('Moving a storage (%s) into a shared folder is not allowed', [$sourcePath]), false);
907+
}
895908
}
896909

897910
if ($sourceMount !== $targetMount) {
898-
throw new ForbiddenException("Moving a $sourceType ($sourcePath) into another $targetType ($targetPath) is not allowed", false);
911+
if ($sourceMount instanceof SharedMount) {
912+
if ($targetMount instanceof SharedMount) {
913+
throw new ForbiddenException($this->l10n->t('Moving a share (%s) into another share (%s) is not allowed', [$sourcePath, $targetPath]), false);
914+
} else {
915+
throw new ForbiddenException($this->l10n->t('Moving a share (%s) into another storage (%s) is not allowed', [$sourcePath, $targetPath]), false);
916+
}
917+
} else {
918+
if ($targetMount instanceof SharedMount) {
919+
throw new ForbiddenException($this->l10n->t('Moving a storage (%s) into a share (%s) is not allowed', [$sourcePath, $targetPath]), false);
920+
} else {
921+
throw new ForbiddenException($this->l10n->t('Moving a storage (%s) into another storage (%s) is not allowed', [$sourcePath, $targetPath]), false);
922+
}
923+
}
899924
}
900925
}
901926
}

0 commit comments

Comments
 (0)