Replace authentication_enabled_providers.include? with helper method (#12379)

* Replaces authentication_enabled_providers.include? with helper authentication_provider_enabled?

* Fix typo
This commit is contained in:
Fernando Valverde 2021-01-22 07:54:10 -06:00 committed by GitHub
parent a63e7ef367
commit 88bd3a1069
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 8 deletions

View file

@ -15,6 +15,10 @@ module AuthenticationHelper
end
end
def authentication_provider_enabled?(provider_name)
authentication_enabled_providers.include?(provider_name)
end
def authentication_enabled_providers_for_user(user = current_user)
Authentication::Providers.enabled_for_user(user)
end

View file

@ -5,7 +5,7 @@ requires a custom partial
-->
<fieldset class="config-authentication-form">
<div
class="crayons-notice crayons-notice--warning auth-warning <%= authentication_enabled_providers.include?(provider.provider_name) ? "hidden" : "" %>">
class="crayons-notice crayons-notice--warning auth-warning <%= authentication_provider_enabled?(provider) ? "hidden" : "" %>">
<strong>Note:</strong> This authentication provider will <strong>not</strong> be enabled if the key or secret are missing. Please make sure that you enter your key and secret correctly.
</div>
<div class="crayons-field">
@ -49,7 +49,7 @@ requires a custom partial
placeholder: Constants::SiteConfig::DETAILS[:apple_team_id][:placeholder] %>
</div>
<div class="flex gap-2">
<% if authentication_enabled_providers.include?(provider) %>
<% if authentication_provider_enabled?(provider) %>
<button
class="crayons-btn crayons-btn--danger"
data-action="click->config#activateAuthProviderModal"

View file

@ -20,7 +20,7 @@
placeholder: Constants::SiteConfig::DETAILS[:"#{provider.provider_name}_secret"][:placeholder] %>
</div>
<div class="flex gap-2">
<% if authentication_enabled_providers.include?(provider) %>
<% if authentication_provider_enabled?(provider) %>
<button
class="crayons-btn crayons-btn--danger"
data-action="click->config#activateAuthProviderModal"

View file

@ -318,12 +318,12 @@
class="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 <%= authentication_enabled_providers.include?(provider) ? "pb-0" : "" %>">
<p class="crayons-field__label <%= authentication_provider_enabled?(provider) ? "pb-0" : "" %>">
<%= provider.official_name %>
</p>
<div
id="<%= provider.provider_name %>-enabled-indicator"
class="enabled-indicator <%= authentication_enabled_providers.include?(provider) ? "visible" : "" %>">
class="enabled-indicator <%= authentication_provider_enabled?(provider) ? "visible" : "" %>">
<%= inline_svg_tag("checkmark.svg", aria: true, class: "crayons-icon admin-config-checkmark", title: "Checkmark") %>
<small class="crayons-field__description ml-1">Enabled</small>
</div>
@ -331,13 +331,13 @@
<button
class="crayons-btn crayons-btn--secondary"
id="<%= provider.provider_name %>-auth-btn"
data-button-text="<%= authentication_enabled_providers.include?(provider) ? "edit" : "enable" %>"
data-button-text="<%= authentication_provider_enabled?(provider) ? "edit" : "enable" %>"
data-action="click->config#enableOrEditAuthProvider"
data-provider-name="<%= provider.provider_name %>"
data-provider-official-name="<%= provider.official_name %>"
data-enable-auth="<%= authentication_enabled_providers.include?(provider) ? "true" : "false" %>"
data-enable-auth="<%= authentication_provider_enabled?(provider) ? "true" : "false" %>"
<%= disabled_attr_on_auth_provider_enable_btn %>>
<%= authentication_enabled_providers.include?(provider) ? "Edit" : "Enable" %>
<%= authentication_provider_enabled?(provider) ? "Edit" : "Enable" %>
</button>
</div>
<div id="<%= provider.provider_name %>-auth-settings" class="config-authentication__item--body hidden">

View file

@ -38,6 +38,23 @@ RSpec.describe AuthenticationHelper, type: :helper do
end
end
describe "#authentication_provider_enabled?" do
before do
allow(SiteConfig).to receive(:invite_only_mode).and_return(false)
allow(SiteConfig).to receive(:authentication_providers).and_return(%i[twitter github])
end
it "returns true when a provider has been enabled" do
expect(helper.authentication_provider_enabled?(Authentication::Providers::Twitter)).to be true
expect(helper.authentication_provider_enabled?(Authentication::Providers::Github)).to be true
end
it "returns false when a provider has not yet been enabled" do
expect(helper.authentication_provider_enabled?(Authentication::Providers::Facebook)).to be false
expect(helper.authentication_provider_enabled?(Authentication::Providers::Apple)).to be false
end
end
describe "tooltip classes, attributes and content" do
context "when invite-only-mode enabled and no enabled registration options" do
before do