Skip to content

Commit

Permalink
fix: translate mount move error messages
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Dec 4, 2024
1 parent 5a95ee0 commit e1aca6e
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\ReservedWordException;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\Server;
Expand Down Expand Up @@ -60,6 +62,7 @@ class View {
private bool $updaterEnabled = true;
private UserManager $userManager;
private LoggerInterface $logger;
private IL10N $l10n;

/**
* @throws \Exception If $root contains an invalid path
Expand All @@ -74,6 +77,7 @@ public function __construct(string $root = '') {
$this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider);
$this->userManager = \OC::$server->getUserManager();
$this->logger = \OC::$server->get(LoggerInterface::class);
$this->l10n = \OC::$server->get(IFactory::class)->get('files');
}

/**
Expand Down Expand Up @@ -840,30 +844,41 @@ public function rename($source, $target) {
return $result;
}

/**
* @throws ForbiddenException
*/
private function validateMountMove(array $mounts, IMountPoint $sourceMount, IMountPoint $targetMount, bool $targetIsShared): void {
$targetType = 'storage';
if ($targetMount instanceof SharedMount) {
$targetType = 'share';
}
$targetPath = rtrim($targetMount->getMountPoint(), '/');
$targetPath = trim($this->getRelativePath($targetMount->getMountPoint()), '/');

foreach ($mounts as $mount) {
$sourcePath = rtrim($mount->getMountPoint(), '/');
$sourceType = 'storage';
if ($mount instanceof SharedMount) {
$sourceType = 'share';
}
$sourcePath = trim($this->getRelativePath($mount->getMountPoint()), '/');

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

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

if ($sourceMount !== $targetMount) {
throw new ForbiddenException("Moving a $sourceType ($sourcePath) into another $targetType ($targetPath) is not allowed", false);
if ($sourceMount instanceof SharedMount) {
if ($targetMount instanceof SharedMount) {
throw new ForbiddenException($this->l10n->t('Moving a share (%s) into another share (%s) is not allowed', [$sourcePath, $targetPath]), false);
} else {
throw new ForbiddenException($this->l10n->t('Moving a share (%s) into another storage (%s) is not allowed', [$sourcePath, $targetPath]), false);
}
} else {
if ($targetMount instanceof SharedMount) {
throw new ForbiddenException($this->l10n->t('Moving a storage (%s) into a share (%s) is not allowed', [$sourcePath, $targetPath]), false);
} else {
throw new ForbiddenException($this->l10n->t('Moving a storage (%s) into another storage (%s) is not allowed', [$sourcePath, $targetPath]), false);
}
}
}
}
}
Expand Down

0 comments on commit e1aca6e

Please sign in to comment.