Email login always on (#11307)
* Starting out * Building away... * Hooking buttons up * Hook Auth Provider buttons to Array Field * trying to fix NoNameError * Remains InviteOnlyMode disable and tests * Smashing remaining tasks * Last of tasks * add tests * Complete specs and tests 😅 * Fix bug * Additional guard * pass event to functions * Position Email Auth first * Fix bug in Email Auth Modal * Fix spacing issue * Update docs for adminModal.js * Show/hide Enabled Indicator with Enable/Undo buttons * Complete Auth Providers functionality * Only update `allow_email_password_registration` from admin * Remove duplicated methods * Some refactoring around fact that Email Login is now always on (#11382) * Fix merge (again!) Co-authored-by: Arit Amana <msarit@gmail.com> Co-authored-by: Arit Amana <32520970+msarit@users.noreply.github.com>
This commit is contained in:
parent
178b0a32f0
commit
2223e5468b
8 changed files with 65 additions and 112 deletions
|
|
@ -114,7 +114,7 @@ module Admin
|
|||
facebook_secret
|
||||
auth_providers_to_enable
|
||||
invite_only_mode
|
||||
allow_both_email_signup_and_login
|
||||
allow_email_password_registration
|
||||
require_captcha_for_email_password_registration
|
||||
primary_brand_color_hex
|
||||
spam_trigger_terms
|
||||
|
|
@ -150,8 +150,6 @@ module Admin
|
|||
end
|
||||
end
|
||||
|
||||
toggle_email_password_authentication
|
||||
|
||||
redirect_to admin_config_path, notice: "Site configuration was successfully updated."
|
||||
end
|
||||
|
||||
|
|
@ -210,15 +208,12 @@ module Admin
|
|||
config[:credit_prices_in_cents]&.transform_values!(&:to_i)
|
||||
end
|
||||
|
||||
def toggle_email_password_authentication
|
||||
if SiteConfig.allow_both_email_signup_and_login
|
||||
SiteConfig.allow_email_password_registration = true
|
||||
SiteConfig.allow_email_password_login = true
|
||||
else
|
||||
SiteConfig.allow_email_password_registration = false
|
||||
SiteConfig.allow_email_password_login = false
|
||||
SiteConfig.invite_only_mode = false
|
||||
end
|
||||
def invalid_provider_entry(entry)
|
||||
entry.blank? || helpers.available_providers_array.exclude?(entry)
|
||||
end
|
||||
|
||||
def email_login_disabled_with_one_or_less_auth_providers(enabled_providers)
|
||||
!SiteConfig.allow_email_password_login && enabled_providers.count <= 1
|
||||
end
|
||||
|
||||
def update_enabled_auth_providers(value)
|
||||
|
|
@ -227,15 +222,7 @@ module Admin
|
|||
enabled_providers.push(entry) unless invalid_provider_entry(entry)
|
||||
end
|
||||
SiteConfig.public_send("authentication_providers=", enabled_providers) unless
|
||||
prevent_all_auth_provider_disable?(enabled_providers)
|
||||
end
|
||||
|
||||
def invalid_provider_entry(entry)
|
||||
entry.blank? || helpers.available_providers_array.exclude?(entry)
|
||||
end
|
||||
|
||||
def prevent_all_auth_provider_disable?(value)
|
||||
value.empty? && !SiteConfig.allow_email_password_login
|
||||
email_login_disabled_with_one_or_less_auth_providers(enabled_providers)
|
||||
end
|
||||
|
||||
# Validations
|
||||
|
|
|
|||
|
|
@ -37,43 +37,22 @@ module AuthenticationHelper
|
|||
SiteConfig.waiting_on_first_user
|
||||
end
|
||||
|
||||
def invite_only_mode_or_no_enabled_providers
|
||||
SiteConfig.invite_only_mode || authentication_enabled_providers.none?
|
||||
end
|
||||
|
||||
def email_login_disabled_and_one_auth_provider_enabled
|
||||
!SiteConfig.allow_email_password_login && authentication_enabled_providers.count == 1
|
||||
end
|
||||
|
||||
def tooltip_class_on_email_auth_disablebtn
|
||||
invite_only_mode_or_no_enabled_providers ? "crayons-tooltip" : ""
|
||||
def invite_only_mode_or_no_enabled_auth_options
|
||||
SiteConfig.invite_only_mode ||
|
||||
(authentication_enabled_providers.none? && !SiteConfig.allow_email_password_registration)
|
||||
end
|
||||
|
||||
def tooltip_class_on_auth_provider_enablebtn
|
||||
SiteConfig.invite_only_mode ? "crayons-tooltip" : ""
|
||||
end
|
||||
|
||||
def tooltip_class_on_auth_provider_disablebtn
|
||||
email_login_disabled_and_one_auth_provider_enabled ? "crayons-tooltip" : ""
|
||||
end
|
||||
|
||||
def disabled_attr_on_email_auth_disablebtn
|
||||
invite_only_mode_or_no_enabled_providers ? "disabled" : ""
|
||||
invite_only_mode_or_no_enabled_auth_options ? "crayons-tooltip" : ""
|
||||
end
|
||||
|
||||
def disabled_attr_on_auth_provider_enablebtn
|
||||
SiteConfig.invite_only_mode ? "disabled" : ""
|
||||
end
|
||||
|
||||
def disabled_attr_on_auth_rpovider_disablebtn
|
||||
email_login_disabled_and_one_auth_provider_enabled ? "disabled" : ""
|
||||
invite_only_mode_or_no_enabled_auth_options ? "disabled" : ""
|
||||
end
|
||||
|
||||
def tooltip_text_email_or_auth_provider_btns
|
||||
if SiteConfig.invite_only_mode
|
||||
if invite_only_mode_or_no_enabled_auth_options
|
||||
"You cannot do this until you disable Invite Only Mode"
|
||||
elsif authentication_enabled_providers.none? || email_login_disabled_and_one_auth_provider_enabled
|
||||
"You cannot do this until you enable at least one other registration option"
|
||||
else
|
||||
""
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ import { Controller } from 'stimulus';
|
|||
import adminModal from '../adminModal';
|
||||
|
||||
const recaptchaFields = document.querySelector('#recaptchaContainer');
|
||||
const emailSigninAndLoginCheckbox = document.querySelector(
|
||||
'#email-signup-and-login-checkbox',
|
||||
const emailRegistrationCheckbox = document.querySelector(
|
||||
'#email-registration-checkbox',
|
||||
);
|
||||
const emailAuthSettingsSection = document.querySelector(
|
||||
'#email-auth-settings-section',
|
||||
|
|
@ -73,7 +73,7 @@ export default class ConfigController extends Controller {
|
|||
enableOrEditEmailAuthSettings(event) {
|
||||
event.preventDefault();
|
||||
if (this.emailAuthSettingsBtnTarget.dataset.buttonText === 'enable') {
|
||||
emailSigninAndLoginCheckbox.checked = true;
|
||||
emailRegistrationCheckbox.checked = true;
|
||||
this.emailAuthSettingsBtnTarget.setAttribute('data-button-text', 'edit');
|
||||
this.enabledIndicatorTarget.classList.add('visible');
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ export default class ConfigController extends Controller {
|
|||
|
||||
disableEmailAuth(event) {
|
||||
event.preventDefault();
|
||||
emailSigninAndLoginCheckbox.checked = false;
|
||||
emailRegistrationCheckbox.checked = false;
|
||||
this.emailAuthSettingsBtnTarget.innerHTML = 'Enable';
|
||||
this.emailAuthSettingsBtnTarget.setAttribute('data-button-text', 'enable');
|
||||
this.enabledIndicatorTarget.classList.remove('visible');
|
||||
|
|
@ -233,8 +233,13 @@ export default class ConfigController extends Controller {
|
|||
).value = enabledProviderArray;
|
||||
}
|
||||
|
||||
disableAuthenticationOptions() {
|
||||
document.querySelector('#auth_providers_to_enable').value = '';
|
||||
adjustAuthenticationOptions() {
|
||||
if (this.inviteOnlyModeTarget.checked) {
|
||||
document.querySelector('#auth_providers_to_enable').value = '';
|
||||
emailRegistrationCheckbox.checked = false;
|
||||
} else {
|
||||
emailRegistrationCheckbox.checked = true;
|
||||
}
|
||||
}
|
||||
// AUTH PROVIDERS FUNCTIONS END
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ class SiteConfig < RailsSettings::Base
|
|||
# Authentication
|
||||
field :allow_email_password_registration, type: :boolean, default: false
|
||||
field :allow_email_password_login, type: :boolean, default: true
|
||||
field :allow_both_email_signup_and_login, type: :boolean, default: true
|
||||
field :require_captcha_for_email_password_registration, type: :boolean, default: false
|
||||
field :authentication_providers, type: :array, default: proc { Authentication::Providers.available }
|
||||
field :invite_only_mode, type: :boolean, default: false
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@
|
|||
<div class="flex gap-2">
|
||||
<% if authentication_enabled_providers.include?(provider) %>
|
||||
<button
|
||||
class="crayons-btn crayons-btn--danger <%= tooltip_class_on_auth_provider_disablebtn %>"
|
||||
class="crayons-btn crayons-btn--danger"
|
||||
data-action="click->config#activateAuthProviderModal"
|
||||
data-tooltip="<%= tooltip_text_email_or_auth_provider_btns %>"
|
||||
data-auth-provider="<%= provider.provider_name %>"
|
||||
data-auth-provider-official="<%= provider.official_name %>"
|
||||
<%= disabled_attr_on_auth_rpovider_disablebtn %>>
|
||||
<%= disabled_attr_on_auth_provider_enablebtn %>>
|
||||
Disable
|
||||
</button>
|
||||
<button
|
||||
|
|
|
|||
|
|
@ -139,13 +139,11 @@
|
|||
<h3 class="crayons-subtitle-3 mb-3">
|
||||
General settings
|
||||
</h3>
|
||||
<div class="crayons-field crayons-field--checkbox <%= !SiteConfig.allow_both_email_signup_and_login ? "crayons-tooltip" : "" %>"
|
||||
data-tooltip="<%= !SiteConfig.allow_both_email_signup_and_login ? "To enable this, you must first enable Email Address as a registration option" : "" %>">
|
||||
<div class="crayons-field crayons-field--checkbox <%= invite_only_mode_or_no_enabled_auth_options ? "crayons-tooltip" : "" %>" data-tooltip="Unchecking this will enable Email Registration">
|
||||
<%= f.check_box :invite_only_mode,
|
||||
checked: SiteConfig.invite_only_mode,
|
||||
disabled: !SiteConfig.allow_both_email_signup_and_login,
|
||||
data: { action: "config#disableAuthenticationOptions", target: "config.inviteOnlyMode" },
|
||||
class: "crayons-checkbox #{!SiteConfig.allow_both_email_signup_and_login ? 'crayons-checkbox--disabled' : ''}" %>
|
||||
checked: invite_only_mode_or_no_enabled_auth_options,
|
||||
data: { action: "config#adjustAuthenticationOptions", target: "config.inviteOnlyMode" },
|
||||
class: "crayons-checkbox" %>
|
||||
<div class="mt-0">
|
||||
<%= admin_config_label :invite_only_mode, "Invite-only mode" %>
|
||||
<%= admin_config_description Constants::SiteConfig::DETAILS[:invite_only_mode][:description] %>
|
||||
|
|
@ -167,14 +165,16 @@
|
|||
<%= inline_svg_tag("email.svg", class: "crayons-icon", aria: true, title: "Email icon") %>
|
||||
</figure>
|
||||
<div class="config-authentication__item--container">
|
||||
<div class="config-authentication__item--row flex items-center justify-between">
|
||||
<div
|
||||
class="config-authentication__item--row flex items-center justify-between <%= tooltip_class_on_auth_provider_enablebtn %>"
|
||||
data-tooltip="<%= tooltip_text_email_or_auth_provider_btns %>">
|
||||
|
||||
<div class="config-authentication__item--label">
|
||||
<p class="crayons-field__label <%= SiteConfig.allow_both_email_signup_and_login ? "pb-0" : "" %>">
|
||||
<p class="crayons-field__label <%= SiteConfig.allow_email_password_registration ? "pb-0" : "" %>">
|
||||
Email address
|
||||
</p>
|
||||
<div
|
||||
class="enabled-indicator <%= SiteConfig.allow_both_email_signup_and_login ? "visible" : "" %>"
|
||||
class="enabled-indicator <%= SiteConfig.allow_email_password_registration ? "visible" : "" %>"
|
||||
data-target="config.enabledIndicator">
|
||||
<%= inline_svg_tag("checkmark.svg", aria: true, class: "crayons-icon admin-config-checkmark", title: "Checkmark") %>
|
||||
<small class="crayons-field__description ml-1">Enabled</small>
|
||||
|
|
@ -184,19 +184,20 @@
|
|||
<button
|
||||
class="crayons-btn crayons-btn--secondary"
|
||||
id="email-auth-enable-edit-btn"
|
||||
data-button-text="<%= SiteConfig.allow_both_email_signup_and_login ? "edit" : "enable" %>"
|
||||
data-button-text="<%= SiteConfig.allow_email_password_registration ? "edit" : "enable" %>"
|
||||
data-target="config.emailAuthSettingsBtn"
|
||||
data-action="click->config#enableOrEditEmailAuthSettings">
|
||||
<%= SiteConfig.allow_both_email_signup_and_login ? "Edit" : "Enable" %>
|
||||
data-action="click->config#enableOrEditEmailAuthSettings"
|
||||
<%= disabled_attr_on_auth_provider_enablebtn %>>
|
||||
<%= SiteConfig.allow_email_password_registration ? "Edit" : "Enable" %>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
<div id="email-auth-settings-section" class="config-authentication__item--body hidden">
|
||||
<fieldset class="config-authentication-form">
|
||||
<div class="crayons-field--checkbox hidden">
|
||||
<%= f.check_box :allow_both_email_signup_and_login,
|
||||
checked: SiteConfig.allow_both_email_signup_and_login,
|
||||
id: "email-signup-and-login-checkbox",
|
||||
<%= f.check_box :allow_email_password_registration,
|
||||
checked: SiteConfig.allow_email_password_registration,
|
||||
id: "email-registration-checkbox",
|
||||
class: "crayons-checkbox" %>
|
||||
</div>
|
||||
<div class="crayons-field--checkbox">
|
||||
|
|
@ -228,12 +229,10 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<% if SiteConfig.allow_both_email_signup_and_login %>
|
||||
<% if SiteConfig.allow_email_password_registration %>
|
||||
<button
|
||||
class="crayons-btn crayons-btn--danger <%= tooltip_class_on_email_auth_disablebtn %>"
|
||||
data-action="click->config#activateEmailAuthModal"
|
||||
data-tooltip="<%= tooltip_text_email_or_auth_provider_btns %>"
|
||||
<%= disabled_attr_on_email_auth_disablebtn %>>
|
||||
class="crayons-btn crayons-btn--danger"
|
||||
data-action="click->config#activateEmailAuthModal">
|
||||
Disable
|
||||
</button>
|
||||
<button
|
||||
|
|
|
|||
|
|
@ -66,52 +66,25 @@ RSpec.describe AuthenticationHelper, type: :helper do
|
|||
end
|
||||
|
||||
describe "tooltip classes, attributes and content" do
|
||||
context "when invite-only-mode enabled and no enabled auth providers" do
|
||||
context "when invite-only-mode enabled and no enabled registration options" do
|
||||
before do
|
||||
allow(SiteConfig).to receive(:invite_only_mode).and_return(true)
|
||||
allow(SiteConfig).to receive(:authentication_providers).and_return([])
|
||||
allow(SiteConfig).to receive(:allow_email_password_registration).and_return(false)
|
||||
end
|
||||
|
||||
it "returns 'crayons-tooltip' class for relevant helpers" do
|
||||
expect(tooltip_class_on_auth_provider_enablebtn).to eq("crayons-tooltip")
|
||||
expect(tooltip_class_on_email_auth_disablebtn).to eq("crayons-tooltip")
|
||||
end
|
||||
|
||||
it "returns 'disabled' attribute for relevant helper" do
|
||||
expect(disabled_attr_on_auth_provider_enablebtn).to eq("disabled")
|
||||
expect(disabled_attr_on_email_auth_disablebtn).to eq("disabled")
|
||||
end
|
||||
|
||||
it "returns appropriate text for 'tooltip_text_email_or_auth_provider_btns' helper" do
|
||||
invite_only_mode_warning = "You cannot do this until you disable Invite Only Mode"
|
||||
only_one_auth_method_warning = "You cannot do this until you enable at least one other registration option"
|
||||
tooltip_text = "You cannot do this until you disable Invite Only Mode"
|
||||
|
||||
expect(tooltip_text_email_or_auth_provider_btns).to eq(invite_only_mode_warning)
|
||||
|
||||
allow(SiteConfig).to receive(:invite_only_mode).and_return(false)
|
||||
|
||||
expect(tooltip_text_email_or_auth_provider_btns).to eq(only_one_auth_method_warning)
|
||||
end
|
||||
end
|
||||
|
||||
context "when email login enabled and one enabled auth provider" do
|
||||
before do
|
||||
allow(SiteConfig).to receive(:allow_email_password_login).and_return(false)
|
||||
allow(SiteConfig).to receive(:authentication_providers).and_return(["facebook"])
|
||||
end
|
||||
|
||||
it "returns 'crayons-tooltip' class for relevant helpers" do
|
||||
expect(tooltip_class_on_auth_provider_disablebtn).to eq("crayons-tooltip")
|
||||
end
|
||||
|
||||
it "returns 'disabled' attribute for relevant helper" do
|
||||
expect(disabled_attr_on_auth_rpovider_disablebtn).to eq("disabled")
|
||||
end
|
||||
|
||||
it "returns appropriate text for 'tooltip_text_email_or_auth_provider_btns' helper" do
|
||||
only_one_auth_method_warning = "You cannot do this until you enable at least one other registration option"
|
||||
|
||||
expect(tooltip_text_email_or_auth_provider_btns).to eq(only_one_auth_method_warning)
|
||||
expect(tooltip_text_email_or_auth_provider_btns).to eq(tooltip_text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -89,17 +89,28 @@ RSpec.describe "/admin/config", type: :request do
|
|||
end
|
||||
|
||||
it "enables email authentication" do
|
||||
post "/admin/config", params: { site_config: { allow_both_email_signup_and_login: true },
|
||||
post "/admin/config", params: { site_config: { allow_email_password_registration: true },
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.allow_email_password_registration).to be(true)
|
||||
expect(SiteConfig.allow_email_password_login).to be(true)
|
||||
end
|
||||
|
||||
it "disables email authentication and invite-only mode" do
|
||||
post "/admin/config", params: { site_config: { allow_both_email_signup_and_login: false },
|
||||
it "disables email authentication" do
|
||||
post "/admin/config", params: { site_config: { allow_email_password_registration: false },
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.allow_email_password_registration).to be(false)
|
||||
expect(SiteConfig.allow_email_password_login).to be(false)
|
||||
expect(SiteConfig.allow_email_password_login).to be(true)
|
||||
end
|
||||
|
||||
it "enables invite-only-mode" do
|
||||
post "/admin/config", params: { site_config: { invite_only_mode: true },
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.invite_only_mode).to be(true)
|
||||
end
|
||||
|
||||
it "disables invite-only-mode & enables just email registration" do
|
||||
post "/admin/config", params: { site_config: { invite_only_mode: false },
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.invite_only_mode).to be(false)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue