Skip to content
Merged
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
15 changes: 12 additions & 3 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,12 @@ public function showFile($fileId) {
$params = [];

if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) {
$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
$files = $baseFolder->getById($fileId);
$params['view'] = 'trashbin';
// Access files_trashbin if it exists
if ( $this->rootFolder->nodeExists($uid . '/files_trashbin/files/')) {
$baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/');
$files = $baseFolder->getById($fileId);
$params['view'] = 'trashbin';
}
}

if (!empty($files)) {
Expand All @@ -299,6 +302,12 @@ public function showFile($fileId) {
}
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
}

if ( $this->userSession->isLoggedIn() and empty($files)) {
$param["error"] = $this->l10n->t("You don't have permissions to access this file/folder - Please contact the owner to share it with you.");
return new TemplateResponse("core", 'error', ["errors" => [$param]], 'guest');
}

throw new \OCP\Files\NotFoundException();
}
}
7 changes: 6 additions & 1 deletion apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ public function testShowFileRouteWithTrashedFile($useShowFile) {
->with('files_trashbin')
->will($this->returnValue(true));

$this->rootFolder->expects($this->once())
->method('nodeExists')
->will($this->returnValue(true));

$parentNode = $this->createMock('\OCP\Files\Folder');
$parentNode->expects($this->once())
->method('getPath')
Expand All @@ -440,7 +444,8 @@ public function testShowFileRouteWithTrashedFile($useShowFile) {
->method('get')
->with('testuser1/files/')
->will($this->returnValue($baseFolderFiles));
$this->rootFolder->expects($this->at(1))
//The index is pointing to 2, because nodeExists internally calls get method.
$this->rootFolder->expects($this->at(2))
->method('get')
->with('testuser1/files_trashbin/files/')
->will($this->returnValue($baseFolderTrash));
Expand Down
15 changes: 15 additions & 0 deletions core/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ public function showLoginForm($user, $redirect_url, $remember_login) {
$parameters['user_autofocus'] = true;
}

/**
* If redirect_url is not empty and remember_login is null and
* user not logged in and check if the string
* webroot+"/index.php/f/" is in redirect_url then
* user is trying to access files for which he needs to login.
*/

if ((!empty($redirect_url)) and ($remember_login === null) and
($this->userSession->isLoggedIn() === false) and
(strpos($this->urlGenerator->getAbsoluteURL(urldecode($redirect_url)),
$this->urlGenerator->getAbsoluteURL('/index.php/f/')) !== false)) {

$parameters['accessLink'] = true;
}

return new TemplateResponse(
$this->appName, 'login', $parameters, 'guest'
);
Expand Down
5 changes: 5 additions & 0 deletions core/templates/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
<?php p($l->t('Wrong password.')); ?>
</p>
<?php } ?>
<?php if (!empty($_['accessLink'])) { ?>
<p class="warning">
<?php p($l->t("You are trying to access a private link. Please log in first.")) ?>
</p>
<?php } ?>
<?php if ($_['rememberLoginAllowed'] === true) : ?>
<div class="remember-login-container">
<?php if ($_['rememberLoginState'] === 0) { ?>
Expand Down
17 changes: 17 additions & 0 deletions tests/Core/Controller/LoginControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ public function testShowLoginFormForLoggedInUsers() {
$this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', '', ''));
}

public function testResponseForNotLoggedinUser() {
$params = [
'messages' => Array (),
'loginName' => '',
'user_autofocus' => true,
'redirect_url' => '%2Findex.php%2Ff%2F17',
'canResetPassword' => true,
'resetPasswordLink' => null,
'alt_login' => Array (),
'rememberLoginAllowed' => false,
'rememberLoginState' => 0
];

$expectedResponse = new TemplateResponse('core', 'login', $params, 'guest');
$this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', '%2Findex.php%2Ff%2F17', ''));
}

public function testShowLoginFormWithErrorsInSession() {
$this->userSession
->expects($this->once())
Expand Down