diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6b28399c3..25a49b396 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -95,10 +95,6 @@ module ApplicationHelper end end - def invite_only_mode? - Settings::Authentication.invite_only_mode? - end - def any_enabled_auth_providers? authentication_enabled_providers.any? end diff --git a/app/helpers/authentication_helper.rb b/app/helpers/authentication_helper.rb index e4ede6f6a..472658589 100644 --- a/app/helpers/authentication_helper.rb +++ b/app/helpers/authentication_helper.rb @@ -45,22 +45,22 @@ module AuthenticationHelper Settings::General.waiting_on_first_user end - def invite_only_mode_or_no_enabled_auth_options - Settings::Authentication.invite_only_mode || + def private_forem_or_no_enabled_auth_options + ForemInstance.private? || (authentication_enabled_providers.none? && !Settings::Authentication.allow_email_password_registration) end def tooltip_class_on_auth_provider_enablebtn - invite_only_mode_or_no_enabled_auth_options ? "crayons-tooltip" : "" + private_forem_or_no_enabled_auth_options ? "crayons-tooltip" : "" end def disabled_attr_on_auth_provider_enable_btn - invite_only_mode_or_no_enabled_auth_options ? "disabled" : "" + private_forem_or_no_enabled_auth_options ? "disabled" : "" end def tooltip_text_email_or_auth_provider_btns - if invite_only_mode_or_no_enabled_auth_options + if private_forem_or_no_enabled_auth_options "You cannot do this until you disable Invite Only Mode" else "" diff --git a/app/services/authentication/providers.rb b/app/services/authentication/providers.rb index 77550b89b..330fa16f4 100644 --- a/app/services/authentication/providers.rb +++ b/app/services/authentication/providers.rb @@ -44,7 +44,7 @@ module Authentication # TODO: [@forem/oss] ideally this should be "available - disabled" # we can get there once we have feature flags def self.enabled - return [] if Settings::Authentication.invite_only_mode + return [] if ForemInstance.private? Settings::Authentication.providers.map(&:to_sym).sort end diff --git a/app/views/admin/settings/forms/_authentication.html.erb b/app/views/admin/settings/forms/_authentication.html.erb index 073ac74bf..84eb05d1b 100644 --- a/app/views/admin/settings/forms/_authentication.html.erb +++ b/app/views/admin/settings/forms/_authentication.html.erb @@ -13,10 +13,10 @@ General settings
" + class="crayons-field crayons-field--checkbox <%= private_forem_or_no_enabled_auth_options ? "crayons-tooltip" : "" %>" data-tooltip="Unchecking this will enable Email Registration"> <%= f.check_box :invite_only_mode, - checked: invite_only_mode_or_no_enabled_auth_options, + checked: private_forem_or_no_enabled_auth_options, data: { action: "config#adjustAuthenticationOptions", "config-target": "inviteOnlyMode" }, class: "crayons-checkbox" %>
diff --git a/app/views/devise/registrations/_registration_form.html.erb b/app/views/devise/registrations/_registration_form.html.erb index 3ffd2dcb0..fd1f9f4e3 100644 --- a/app/views/devise/registrations/_registration_form.html.erb +++ b/app/views/devise/registrations/_registration_form.html.erb @@ -2,7 +2,7 @@

- <% if params[:state] == "new-user" && invite_only_mode? %> + <% if params[:state] == "new-user" && ForemInstance.private? %> <%= community_name %> is invite only. <% else %> Welcome to <%= community_name %> diff --git a/app/views/shared/authentication/_providers_registration_form.html.erb b/app/views/shared/authentication/_providers_registration_form.html.erb index bdb99cba2..2a3404eca 100644 --- a/app/views/shared/authentication/_providers_registration_form.html.erb +++ b/app/views/shared/authentication/_providers_registration_form.html.erb @@ -8,7 +8,7 @@ <% end %> <% end %> <% end %> - <% if params[:state] == "new-user" && Settings::Authentication.allow_email_password_registration && !Settings::Authentication.invite_only_mode %> + <% if params[:state] == "new-user" && Settings::Authentication.allow_email_password_registration && !ForemInstance.private? %> <%= link_to "#{inline_svg_tag('email.svg', aria_hidden: true, class: 'crayons-icon', title: 'email')}Sign up with Email".html_safe, request.params.merge(state: "email_signup").except("i"), class: "crayons-btn crayons-btn--l crayons-btn--brand-email crayons-btn--icon-left whitespace-nowrap", diff --git a/spec/helpers/authentication_helper_spec.rb b/spec/helpers/authentication_helper_spec.rb index f2d883043..bc858a717 100644 --- a/spec/helpers/authentication_helper_spec.rb +++ b/spec/helpers/authentication_helper_spec.rb @@ -58,7 +58,7 @@ RSpec.describe AuthenticationHelper, type: :helper do describe "#authentication_provider_enabled?" do before do - allow(Settings::Authentication).to receive(:invite_only_mode).and_return(false) + allow(ForemInstance).to receive(:private?).and_return(false) allow(Settings::Authentication).to receive(:providers).and_return(%i[twitter github]) end @@ -76,7 +76,7 @@ RSpec.describe AuthenticationHelper, type: :helper do describe "tooltip classes, attributes and content" do context "when invite-only-mode enabled and no enabled registration options" do before do - allow(Settings::Authentication).to receive(:invite_only_mode).and_return(true) + allow(ForemInstance).to receive(:private?).and_return(true) allow(Settings::Authentication).to receive(:providers).and_return([]) allow(Settings::Authentication).to receive(:allow_email_password_registration).and_return(false) end diff --git a/spec/system/authentication/creator_config_edit_spec.rb b/spec/system/authentication/creator_config_edit_spec.rb index b16856ade..2f948dd9d 100644 --- a/spec/system/authentication/creator_config_edit_spec.rb +++ b/spec/system/authentication/creator_config_edit_spec.rb @@ -9,7 +9,7 @@ RSpec.describe "Creator config edit", type: :system, js: true do context "when a creator browses /admin/customization/config" do before do sign_in admin - allow(Settings::Authentication).to receive(:invite_only_mode).and_return(false) + allow(ForemInstance).to receive(:private?).and_return(false) end it "presents all available OAuth providers" do diff --git a/spec/system/authentication/user_logs_in_with_email_spec.rb b/spec/system/authentication/user_logs_in_with_email_spec.rb index cbdca524a..29d952e88 100644 --- a/spec/system/authentication/user_logs_in_with_email_spec.rb +++ b/spec/system/authentication/user_logs_in_with_email_spec.rb @@ -116,7 +116,7 @@ RSpec.describe "Authenticating with Email" do context "when community is in invite only mode" do before do - allow(Settings::Authentication).to receive(:invite_only_mode).and_return(true) + allow(ForemInstance).to receive(:private?).and_return(true) end it "doesn't present the authentication option" do diff --git a/spec/system/authentication/user_logs_in_with_facebook_spec.rb b/spec/system/authentication/user_logs_in_with_facebook_spec.rb index 473cbece2..15615f842 100644 --- a/spec/system/authentication/user_logs_in_with_facebook_spec.rb +++ b/spec/system/authentication/user_logs_in_with_facebook_spec.rb @@ -234,7 +234,7 @@ RSpec.describe "Authenticating with Facebook" do context "when community is in invite only mode" do before do - allow(Settings::Authentication).to receive(:invite_only_mode).and_return(true) + allow(ForemInstance).to receive(:private?).and_return(true) end it "doesn't present the authentication option" do diff --git a/spec/system/authentication/user_logs_in_with_github_spec.rb b/spec/system/authentication/user_logs_in_with_github_spec.rb index c6e1c12ad..407390cbc 100644 --- a/spec/system/authentication/user_logs_in_with_github_spec.rb +++ b/spec/system/authentication/user_logs_in_with_github_spec.rb @@ -200,7 +200,7 @@ RSpec.describe "Authenticating with GitHub" do context "when community is in invite only mode" do before do - allow(Settings::Authentication).to receive(:invite_only_mode).and_return(true) + allow(ForemInstance).to receive(:private?).and_return(true) end it "doesn't present the authentication option" do diff --git a/spec/system/authentication/user_logs_in_with_twitter_spec.rb b/spec/system/authentication/user_logs_in_with_twitter_spec.rb index 1589eeed0..63d842152 100644 --- a/spec/system/authentication/user_logs_in_with_twitter_spec.rb +++ b/spec/system/authentication/user_logs_in_with_twitter_spec.rb @@ -192,7 +192,7 @@ RSpec.describe "Authenticating with Twitter" do context "when community is in invite only mode" do before do - allow(Settings::Authentication).to receive(:invite_only_mode).and_return(true) + allow(ForemInstance).to receive(:private?).and_return(true) end it "doesn't present the authentication option" do