Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#42647 fix(file settings): Unnecessary 2FA UI message (updated) #44594

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

jadjoud
Copy link
Contributor

@jadjoud jadjoud commented Mar 31, 2024

Summary

Added a conditional statement for the message rendering

image

image

@kesselb this is the fixed PR

TODO

  • ...

Checklist

@jadjoud jadjoud requested a review from skjnldsv as a code owner March 31, 2024 14:40
@jadjoud jadjoud changed the title fix #42647 Unnecessary 2FA UI message updated #42647 fix(file settings): Unnecessary 2FA UI message (updated) Mar 31, 2024
- added an if condition for the message rendering

Signed-off-by: JEEEEEEEEEEEEEEEEEEEEEED <[email protected]>
@kesselb
Copy link
Contributor

kesselb commented Apr 2, 2024

Thank you, always great to see new contributors 👍

Here is a brief explanation of how to set up a local dev environment https://github.com/nextcloud/server?tab=readme-ov-file#join-the-team-

A good start to wrap a v-if template block. To make that actually work, you also need to add the actual variable isTwoFactorEnabled to the data function also gather the information "is 2fa enabled for the given user" from the backend.

The patch below should provide the necessary data from the backend and use it in the vue component.

Index: apps/files/lib/Controller/ViewController.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php
--- a/apps/files/lib/Controller/ViewController.php	(revision 28ee87b4c4cb3f82af1fb2caaa0218b635750e90)
+++ b/apps/files/lib/Controller/ViewController.php	(date 1712064072302)
@@ -35,6 +35,7 @@
  */
 namespace OCA\Files\Controller;
 
+use OC\Authentication\TwoFactorAuth\Registry;
 use OCA\Files\Activity\Helper;
 use OCA\Files\AppInfo\Application;
 use OCA\Files\Event\LoadAdditionalScriptsEvent;
@@ -98,7 +99,8 @@
 		ITemplateManager $templateManager,
 		IManager $shareManager,
 		UserConfig $userConfig,
-		ViewConfig $viewConfig
+		ViewConfig $viewConfig,
+		private Registry $twoFactorRegistry,
 	) {
 		parent::__construct($appName, $request);
 		$this->urlGenerator = $urlGenerator;
@@ -203,7 +205,8 @@
 		\OCP\Util::addStyle('files', 'merged');
 		\OCP\Util::addScript('files', 'main');
 
-		$userId = $this->userSession->getUser()->getUID();
+		$user = $this->userSession->getUser();
+		$userId = $user->getUID();
 
 		// Get all the user favorites to create a submenu
 		try {
@@ -270,6 +273,15 @@
 		$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',
Index: apps/files/src/views/Settings.vue
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/apps/files/src/views/Settings.vue b/apps/files/src/views/Settings.vue
--- a/apps/files/src/views/Settings.vue	(revision 28ee87b4c4cb3f82af1fb2caaa0218b635750e90)
+++ b/apps/files/src/views/Settings.vue	(date 1712064510627)
@@ -152,6 +152,7 @@
 			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))
 		}
 	},
 

@kesselb kesselb added enhancement 2. developing Work in progress labels Apr 2, 2024
@kesselb kesselb removed their request for review April 2, 2024 13:41
@kesselb
Copy link
Contributor

kesselb commented Apr 2, 2024

Removing myself as reviewer because I'm not familiar enough with 2fa and the files settings component.

@kesselb kesselb added this to the Nextcloud 30 milestone Apr 2, 2024
@jadjoud
Copy link
Contributor Author

jadjoud commented Apr 2, 2024

@kesselb
Thank you so much for your help!

I will try to make the necessary changes ASAP

@pboguslawski
Copy link
Contributor

When message is rendered only with 2FA enabled, should not contain If you have enabled 2FA any more probably.

Removing myself as reviewer because we're not using 2FA with nc so cannot test it.

@pboguslawski pboguslawski removed their request for review April 3, 2024 08:24
Copy link
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

This was referenced Jul 30, 2024
This was referenced Aug 5, 2024
@skjnldsv skjnldsv mentioned this pull request Aug 13, 2024
@skjnldsv skjnldsv modified the milestones: Nextcloud 30, Nextcloud 31 Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unnecessary 2FA UI message in Files settings
4 participants