Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ public function index($dir = '', $view = '', $fileid = null) {

// If the file doesn't exists in the folder and
// exists in only one occurrence, redirect to that file
// in the correct folder
if ($fileid && $dir !== '') {
// in the correct folder. Only where dir is a path in the
// user's files: other views use it for their own ids (tags).
if ($fileid && $dir !== '' && in_array($view, ['', 'files', 'personal'], true)) {
$baseFolder = $this->rootFolder->getUserFolder($userId);
$nodes = $baseFolder->getById((int)$fileid);
if (!empty($nodes)) {
Expand Down
32 changes: 32 additions & 0 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,38 @@ public function testIndexWithRegularBrowser(): void {
$this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
}

public static function dataTestRedirectToFileFolder(): array {
return [
'files view' => ['files', true],
'no view' => ['', true],
'personal files' => ['personal', true],
// The tags view puts the tag id in dir
'tags view' => ['tags', false],
];
}

#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataTestRedirectToFileFolder')]
public function testRedirectToFileFolder(string $view, bool $redirects): void {
$this->viewController->method('getStorageInfo')->willReturn([]);
$this->config->method('getUserValue')->willReturnArgument(3);

$node = $this->createMock(File::class);
$node->method('getPath')->willReturn('/testuser1/files/Folder/photo.jpg');
$node->method('getParent')->willReturn($this->createMock(Folder::class));

$baseFolderFiles = $this->createMock(IUserFolder::class);
$baseFolderFiles->method('getById')->with(123)->willReturn([$node]);
$baseFolderFiles->method('getFirstNodeById')->with(123)->willReturn($node);
$baseFolderFiles->method('getRelativePath')->willReturnMap([
['/testuser1/files/Folder/photo.jpg', '/Folder/photo.jpg'],
['', '/Folder'],
]);
$this->rootFolder->method('getUserFolder')->with('testuser1')->willReturn($baseFolderFiles);

$response = $this->viewController->index('/1', $view, '123');
$this->assertSame($redirects, $response instanceof RedirectResponse);
}

public static function dataTestShortRedirect(): array {
// openfile is true by default
// opendetails is undefined by default
Expand Down
Loading