FEATURE: Allow invite only and Discourse connect (#20961)

Invite only and Discourse connect could not be enabled at the same time
because of some legacy reason. This is a follow up commit to ce04db8,
355d51a and 40f6ceb.
This commit is contained in:
Bianca Nenciu 2023-04-04 19:52:11 +03:00 committed by GitHub
parent 73325c6c35
commit 9ff105973f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 2 additions and 40 deletions

View File

@ -2438,7 +2438,6 @@ en:
staged_users_disabled: "You must first enable 'staged users' before enabling this setting."
reply_by_email_disabled: "You must first enable 'reply by email' before enabling this setting."
discourse_connect_url_is_empty: "You must set a 'discourse connect url' before enabling this setting."
discourse_connect_invite_only: "You cannot enable DiscourseConnect and invite only at the same time."
enable_local_logins_disabled: "You must first enable 'enable local logins' before enabling this setting."
min_username_length_exists: "You cannot set the minimum username length above the shortest username (%{username})."
min_username_length_range: "You cannot set the minimum above the maximum."

View File

@ -391,7 +391,6 @@ login:
refresh: true
client: true
default: false
validator: "EnableInviteOnlyValidator"
login_required:
refresh: true
client: true

View File

@ -1,16 +0,0 @@
# frozen_string_literal: true
class EnableInviteOnlyValidator
def initialize(opts = {})
@opts = opts
end
def valid_value?(val)
return true if val == "f"
!SiteSetting.enable_discourse_connect?
end
def error_message
I18n.t("site_settings.errors.discourse_connect_invite_only")
end
end

View File

@ -7,9 +7,7 @@ class EnableSsoValidator
def valid_value?(val)
return true if val == "f"
if SiteSetting.discourse_connect_url.blank? || SiteSetting.invite_only? || is_2fa_enforced?
return false
end
return false if SiteSetting.discourse_connect_url.blank? || is_2fa_enforced?
true
end
@ -17,7 +15,7 @@ class EnableSsoValidator
if SiteSetting.discourse_connect_url.blank?
return I18n.t("site_settings.errors.discourse_connect_url_is_empty")
end
return I18n.t("site_settings.errors.discourse_connect_invite_only") if SiteSetting.invite_only?
if is_2fa_enforced?
I18n.t("site_settings.errors.discourse_connect_cannot_be_enabled_if_second_factor_enforced")
end

View File

@ -24,24 +24,6 @@ RSpec.describe EnableSsoValidator do
end
end
describe "when invite_only is set" do
before do
SiteSetting.invite_only = true
SiteSetting.discourse_connect_url = "https://example.com/sso"
end
it "allows a false value" do
expect(subject.valid_value?("f")).to eq(true)
end
it "doesn't allow true" do
expect(subject.valid_value?("t")).to eq(false)
expect(subject.error_message).to eq(
I18n.t("site_settings.errors.discourse_connect_invite_only"),
)
end
end
describe "when 'sso url' is present" do
before { SiteSetting.discourse_connect_url = "https://www.example.com/sso" }