feat(files): Use receiving users language for the ownership transfer target folder

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2024-04-17 23:50:18 +02:00
parent 92fc15e75f
commit dffe9d5567
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
2 changed files with 14 additions and 9 deletions

View File

@ -47,6 +47,7 @@ use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use Symfony\Component\Console\Helper\ProgressBar;
@ -69,6 +70,7 @@ class OwnershipTransferService {
private IMountManager $mountManager,
private IUserMountCache $userMountCache,
private IUserManager $userManager,
private IFactory $l10nFactory,
) {
$this->encryptionManager = $encryptionManager;
}
@ -117,19 +119,15 @@ class OwnershipTransferService {
if ($move) {
$finalTarget = "$destinationUid/files/";
} else {
$l = $this->l10nFactory->get('files', $this->l10nFactory->getUserLanguage($destinationUser));
$date = date('Y-m-d H-i-s');
// Remove some characters which are prone to cause errors
$cleanUserName = str_replace(['\\', '/', ':', '.', '?', '#', '\'', '"'], '-', $sourceUser->getDisplayName());
// Replace multiple dashes with one dash
$cleanUserName = preg_replace('/-{2,}/s', '-', $cleanUserName);
$cleanUserName = $cleanUserName ?: $sourceUid;
$finalTarget = "$destinationUid/files/transferred from $cleanUserName on $date";
$cleanUserName = $this->sanitizeFolderName($sourceUser->getDisplayName()) ?: $sourceUid;
$finalTarget = "$destinationUid/files/" . $this->sanitizeFolderName($l->t('Transferred from %1$s on %2$s', [$cleanUserName, $date]));
try {
$view->verifyPath(dirname($finalTarget), basename($finalTarget));
} catch (InvalidPathException $e) {
$finalTarget = "$destinationUid/files/transferred from $sourceUid on $date";
$finalTarget = "$destinationUid/files/" . $this->sanitizeFolderName($l->t('Transferred from %1$s on %2$s', [$sourceUid, $date]));
}
}
@ -209,6 +207,13 @@ class OwnershipTransferService {
}
}
private function sanitizeFolderName(string $name): string {
// Remove some characters which are prone to cause errors
$name = str_replace(['\\', '/', ':', '.', '?', '#', '\'', '"'], '-', $name);
// Replace multiple dashes with one dash
return preg_replace('/-{2,}/s', '-', $name);
}
private function walkFiles(View $view, $path, Closure $callBack) {
foreach ($view->getDirectoryContent($path) as $fileInfo) {
if (!$callBack($fileInfo)) {

View File

@ -71,7 +71,7 @@ class CommandLineContext implements \Behat\Behat\Context\Context {
foreach ($results as $path => $data) {
$path = rawurldecode($path);
$parts = explode(' ', $path);
if (basename($parts[0]) !== 'transferred') {
if (basename($parts[0]) !== 'Transferred') {
continue;
}
if (isset($parts[2]) && $parts[2] === $sourceUser) {