From a9040be47ca2341eb6305ced4d367fd1e98dc24d Mon Sep 17 00:00:00 2001
From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com>
Date: Thu, 6 Jul 2023 16:44:40 -0500
Subject: [PATCH] FIX: Don't redirect when manually adding 2fa (#22474)
No changes in styling, the adding of classes was to give targets for testing
---
.../app/components/modal/second-factor-add-totp.hbs | 12 ++++++++----
.../app/components/modal/second-factor-add-totp.js | 4 +++-
.../user-preferences-second-factor-test.js | 7 ++++++-
3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.hbs b/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.hbs
index 5f9e4f025c5..9e709d1ed2d 100644
--- a/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.hbs
+++ b/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.hbs
@@ -26,11 +26,15 @@
{{#if this.showSecondFactorKey}}
- {{this.secondFactorKey}}
+
+ {{this.secondFactorKey}}
+
{{else}}
- {{i18n
- "user.second_factor.show_key_description"
- }}
+ {{i18n "user.second_factor.show_key_description"}}
{{/if}}
diff --git a/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.js b/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.js
index 0a254e8c4e0..5a7281c6d40 100644
--- a/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.js
+++ b/app/assets/javascripts/discourse/app/components/modal/second-factor-add-totp.js
@@ -33,7 +33,9 @@ export default class SecondFactorAddTotp extends Component {
}
@action
- enableShowSecondFactorKey() {
+ enableShowSecondFactorKey(e) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
this.showSecondFactorKey = true;
}
diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-second-factor-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-second-factor-test.js
index 16aa5b2cdbf..603cb13eefb 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-second-factor-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-second-factor-test.js
@@ -66,8 +66,13 @@ acceptance("User Preferences - Second Factor", function (needs) {
await click(".new-totp");
assert.ok(exists(".qr-code img"), "shows qr code image");
- await click(".add-totp");
+ await click(".modal a.show-second-factor-key");
+ assert.ok(
+ exists(".modal .second-factor-key"),
+ "displays second factor key"
+ );
+ await click(".add-totp");
assert.ok(
query(".alert-error").innerHTML.includes("provide a name and the code"),
"shows name/token missing error message"