diff --git a/app/assets/javascripts/discourse/app/components/modal/create-account.js b/app/assets/javascripts/discourse/app/components/modal/create-account.js index 475d47514d7..1efd081b796 100644 --- a/app/assets/javascripts/discourse/app/components/modal/create-account.js +++ b/app/assets/javascripts/discourse/app/components/modal/create-account.js @@ -134,9 +134,7 @@ export default class CreateAccount extends Component.extend( @discourseComputed showFullname() { - return ( - this.siteSettings.enable_names && this.site.full_name_visible_in_signup - ); + return this.site.full_name_visible_in_signup; } @discourseComputed diff --git a/app/assets/javascripts/discourse/app/controllers/invites-show.js b/app/assets/javascripts/discourse/app/controllers/invites-show.js index d4f919a9131..6a98e19b7da 100644 --- a/app/assets/javascripts/discourse/app/controllers/invites-show.js +++ b/app/assets/javascripts/discourse/app/controllers/invites-show.js @@ -157,9 +157,7 @@ export default class InvitesShowController extends Controller.extend( @discourseComputed showFullname() { - return ( - this.siteSettings.enable_names && this.site.full_name_visible_in_signup - ); + return this.site.full_name_visible_in_signup; } @discourseComputed diff --git a/app/assets/javascripts/discourse/app/controllers/signup.js b/app/assets/javascripts/discourse/app/controllers/signup.js index 4c2a0f18482..69aeebf39df 100644 --- a/app/assets/javascripts/discourse/app/controllers/signup.js +++ b/app/assets/javascripts/discourse/app/controllers/signup.js @@ -117,9 +117,7 @@ export default class SignupPageController extends Controller.extend( @discourseComputed showFullname() { - return ( - this.siteSettings.enable_names && this.site.full_name_visible_in_signup - ); + return this.site.full_name_visible_in_signup; } @discourseComputed diff --git a/app/serializers/site_serializer.rb b/app/serializers/site_serializer.rb index dbfc60c5715..d145dcf001e 100644 --- a/app/serializers/site_serializer.rb +++ b/app/serializers/site_serializer.rb @@ -384,11 +384,11 @@ class SiteSerializer < ApplicationSerializer end def full_name_required_for_signup - SiteSetting.full_name_requirement == "required_at_signup" + SiteSetting.enable_names && SiteSetting.full_name_requirement == "required_at_signup" end def full_name_visible_in_signup - SiteSetting.full_name_requirement != "hidden_at_signup" + SiteSetting.enable_names && SiteSetting.full_name_requirement != "hidden_at_signup" end private diff --git a/spec/serializers/site_serializer_spec.rb b/spec/serializers/site_serializer_spec.rb index fc73e12c19e..3aa2dbd5da1 100644 --- a/spec/serializers/site_serializer_spec.rb +++ b/spec/serializers/site_serializer_spec.rb @@ -425,4 +425,76 @@ RSpec.describe SiteSerializer do expect(serialized[:whispers_allowed_groups_names]).to eq(nil) end end + + describe "#full_name_required_for_signup" do + let(:site_json) do + described_class.new(Site.new(guardian), scope: guardian, root: false).as_json + end + + it "is false when enable_names setting is false" do + SiteSetting.full_name_requirement = "required_at_signup" + SiteSetting.enable_names = false + expect(site_json[:full_name_required_for_signup]).to eq(false) + end + + it "is false when full_name_requirement setting is optional_at_signup" do + SiteSetting.full_name_requirement = "optional_at_signup" + SiteSetting.enable_names = true + expect(site_json[:full_name_required_for_signup]).to eq(false) + end + + it "is false when full_name_requirement setting is hidden_at_signup" do + SiteSetting.full_name_requirement = "hidden_at_signup" + SiteSetting.enable_names = true + expect(site_json[:full_name_required_for_signup]).to eq(false) + end + + it "is true when full_name_requirement setting is required_at_signup and enable_names is true" do + SiteSetting.full_name_requirement = "required_at_signup" + SiteSetting.enable_names = true + expect(site_json[:full_name_required_for_signup]).to eq(true) + end + end + + describe "#full_name_visible_in_signup" do + let(:site_json) do + described_class.new(Site.new(guardian), scope: guardian, root: false).as_json + end + + it "is false when enable_names setting is false and full_name_requirement is hidden_at_signup" do + SiteSetting.full_name_requirement = "hidden_at_signup" + SiteSetting.enable_names = false + expect(site_json[:full_name_visible_in_signup]).to eq(false) + end + + it "is false when enable_names setting is false and full_name_requirement is required_at_signup" do + SiteSetting.full_name_requirement = "required_at_signup" + SiteSetting.enable_names = false + expect(site_json[:full_name_visible_in_signup]).to eq(false) + end + + it "is false when enable_names setting is false and full_name_requirement is optional_at_signup" do + SiteSetting.full_name_requirement = "optional_at_signup" + SiteSetting.enable_names = false + expect(site_json[:full_name_visible_in_signup]).to eq(false) + end + + it "is true when enable_names setting is true and full_name_requirement is optional_at_signup" do + SiteSetting.full_name_requirement = "optional_at_signup" + SiteSetting.enable_names = true + expect(site_json[:full_name_visible_in_signup]).to eq(true) + end + + it "is true when enable_names setting is true and full_name_requirement is required_at_signup" do + SiteSetting.full_name_requirement = "required_at_signup" + SiteSetting.enable_names = true + expect(site_json[:full_name_visible_in_signup]).to eq(true) + end + + it "is false when enable_names setting is true and full_name_requirement is hidden_at_signup" do + SiteSetting.full_name_requirement = "hidden_at_signup" + SiteSetting.enable_names = true + expect(site_json[:full_name_visible_in_signup]).to eq(false) + end + end end