Skip to content

Commit 1e26ea2

Browse files
JED-Bkesselb
andcommitted
feat(files): hide note about app passwords when 2FA not enabled
Signed-off-by: JEEEEEEEEEEEEEEEEEEEEEED <[email protected]> Co-authored-by: Daniel Kesselberg <[email protected]>
1 parent a1f4b59 commit 1e26ea2

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

apps/files/lib/Controller/ViewController.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use OCP\AppFramework\Http\Response;
2727
use OCP\AppFramework\Http\TemplateResponse;
2828
use OCP\AppFramework\Services\IInitialState;
29+
use OCP\Authentication\TwoFactorAuth\IRegistry;
2930
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
3031
use OCP\EventDispatcher\IEventDispatcher;
3132
use OCP\Files\Folder;
@@ -60,6 +61,7 @@ public function __construct(
6061
private UserConfig $userConfig,
6162
private ViewConfig $viewConfig,
6263
private FilenameValidator $filenameValidator,
64+
private IRegistry $twoFactorRegistry,
6365
) {
6466
parent::__construct($appName, $request);
6567
}
@@ -142,7 +144,8 @@ public function index($dir = '', $view = '', $fileid = null) {
142144
Util::addInitScript('files', 'init');
143145
Util::addScript('files', 'main');
144146

145-
$userId = $this->userSession->getUser()->getUID();
147+
$user = $this->userSession->getUser();
148+
$userId = $user->getUID();
146149

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

201+
$isTwoFactorEnabled = false;
202+
foreach ($this->twoFactorRegistry->getProviderStates($user) as $providerId => $providerState) {
203+
if ($providerId !== 'backup_codes' && $providerState === true) {
204+
$isTwoFactorEnabled = true;
205+
}
206+
}
207+
208+
$this->initialState->provideInitialState('isTwoFactorEnabled', $isTwoFactorEnabled);
209+
198210
$response = new TemplateResponse(
199211
Application::APP_ID,
200212
'index',

apps/files/src/views/Settings.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@
9696
</a>
9797
</em>
9898
<br>
99-
<em>
99+
<em v-if="isTwoFactorEnabled">
100100
<a class="setting-link" :href="appPasswordUrl">
101-
{{ t('files', 'If you have enabled 2FA, you must create and use a new app password by clicking here.') }} ↗
101+
{{ 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.') }} ↗
102102
</a>
103103
</em>
104104
</NcAppSettingsSection>
@@ -333,6 +333,7 @@ export default {
333333
appPasswordUrl: generateUrl('/settings/user/security#generate-app-token-section'),
334334
webdavUrlCopied: false,
335335
enableGridView: (loadState('core', 'config', [])['enable_non-accessible_features'] ?? true),
336+
isTwoFactorEnabled: (loadState('files', 'isTwoFactorEnabled', false))
336337
}
337338
},
338339

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)