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
14 changes: 13 additions & 1 deletion apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Authentication\TwoFactorAuth\IRegistry;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Folder;
Expand Down Expand Up @@ -60,6 +61,7 @@ public function __construct(
private UserConfig $userConfig,
private ViewConfig $viewConfig,
private FilenameValidator $filenameValidator,
private IRegistry $twoFactorRegistry,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -142,7 +144,8 @@ public function index($dir = '', $view = '', $fileid = null) {
Util::addInitScript('files', 'init');
Util::addScript('files', 'main');

$userId = $this->userSession->getUser()->getUID();
$user = $this->userSession->getUser();
$userId = $user->getUID();

// If the file doesn't exists in the folder and
// exists in only one occurrence, redirect to that file
Expand Down Expand Up @@ -195,6 +198,15 @@ public function index($dir = '', $view = '', $fileid = null) {
$this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false);
$this->initialState->provideInitialState('templates', $this->templateManager->listCreators());

$isTwoFactorEnabled = false;
foreach ($this->twoFactorRegistry->getProviderStates($user) as $providerId => $providerState) {
if ($providerId !== 'backup_codes' && $providerState === true) {
$isTwoFactorEnabled = true;
}
}

$this->initialState->provideInitialState('isTwoFactorEnabled', $isTwoFactorEnabled);

$response = new TemplateResponse(
Application::APP_ID,
'index',
Expand Down
7 changes: 4 additions & 3 deletions apps/files/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@
:href="webdavDocs"
target="_blank"
rel="noreferrer noopener">
{{ t('files', 'Use this address to access your Files via WebDAV') }} ↗
{{ t('files', 'Use this address to access your Files via WebDAV.') }} ↗
</a>
</em>
<br>
<em>
<em v-if="isTwoFactorEnabled">
<a class="setting-link" :href="appPasswordUrl">
{{ t('files', 'If you have enabled 2FA, you must create and use a new app password by clicking here.') }} ↗
{{ t('files', 'Two-Factor Authentication is enabled for your account, and therefore you need to use an app password to connect an external WebDAV client.') }} ↗
</a>
</em>
</NcAppSettingsSection>
Expand Down Expand Up @@ -334,6 +334,7 @@ export default {
appPasswordUrl: generateUrl('/settings/user/security#generate-app-token-section'),
webdavUrlCopied: false,
enableGridView: (loadState('core', 'config', [])['enable_non-accessible_features'] ?? true),
isTwoFactorEnabled: (loadState('files', 'isTwoFactorEnabled', false)),
}
},

Expand Down
24 changes: 24 additions & 0 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Authentication\TwoFactorAuth\IRegistry;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
Expand Down Expand Up @@ -63,6 +64,7 @@ class ViewControllerTest extends TestCase {
private UserConfig&MockObject $userConfig;
private ViewConfig&MockObject $viewConfig;
private Router $router;
private IRegistry&MockObject $twoFactorRegistry;

private ViewController&MockObject $viewController;

Expand All @@ -79,6 +81,7 @@ protected function setUp(): void {
$this->userConfig = $this->createMock(UserConfig::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->viewConfig = $this->createMock(ViewConfig::class);
$this->twoFactorRegistry = $this->createMock(IRegistry::class);

$this->user = $this->getMockBuilder(IUser::class)->getMock();
$this->user->expects($this->any())
Expand Down Expand Up @@ -138,6 +141,7 @@ protected function setUp(): void {
$this->userConfig,
$this->viewConfig,
$filenameValidator,
$this->twoFactorRegistry,
])
->onlyMethods([
'getStorageInfo',
Expand Down Expand Up @@ -286,4 +290,24 @@ public function testShowFileRouteWithTrashedFile(): void {
$expected = new RedirectResponse('/index.php/apps/files/trashbin/123?dir=/test.d1462861890/sub');
$this->assertEquals($expected, $this->viewController->index('', '', '123'));
}

public function testTwoFactorAuthEnabled(): void {
$this->twoFactorRegistry->method('getProviderStates')
->willReturn([
'totp' => true,
'backup_codes' => true,
]);

$invokedCountProvideInitialState = $this->exactly(9);
$this->initialState->expects($invokedCountProvideInitialState)
->method('provideInitialState')
->willReturnCallback(function ($key, $data) use ($invokedCountProvideInitialState) {
if ($invokedCountProvideInitialState->numberOfInvocations() === 9) {
$this->assertEquals('isTwoFactorEnabled', $key);
$this->assertTrue($data);
}
});

$this->viewController->index('', '', null);
}
}
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

Loading