A platform for community discussion. Free, open, simple.
FEATURE: better wizard privacy controls (#7391)
Arpit Jalana63ef4cfc856
diff --git a/app/assets/javascripts/wizard/templates/components/wizard-field-radio.hbs b/app/assets/javascripts/wizard/templates/components/wizard-field-radio.hbsindex cb65052fc82..8994de0de4e 100644--- a/app/assets/javascripts/wizard/templates/components/wizard-field-radio.hbs+++ b/app/assets/javascripts/wizard/templates/components/wizard-field-radio.hbs@@ -1,5 +1,5 @@{{#each field.choices as |c|}}- <div class="radio-field-choice">+ <div class="radio-field-choice {{fieldClass}}">{{radio-button value=field.valueradioValue=c.idlabel=c.labeldiff --git a/app/assets/stylesheets/wizard.scss b/app/assets/stylesheets/wizard.scssindex 64963458f7f..6d62aa44a88 100644--- a/app/assets/stylesheets/wizard.scss+++ b/app/assets/stylesheets/wizard.scss@@ -73,6 +73,21 @@ body.wizard {font-weight: bold;}+.wizard-step-privacy {+ label[for="privacy_options"] .field-description {+ color: #444;+ margin-bottom: 1em;+ }++ .field-privacy-options {+ margin-bottom: 0.8em;++ .radio-label {+ font-weight: normal;+ }+ }+}+.wizard-step-form {max-height: 500px;}diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex cc4752b0927..239c724b6fd 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -4284,8 +4284,15 @@ en:restricted:label: "Private"description: "Only logged in users can access this community"- invite_only:- placeholder: "People must be explicitly invited. Public registration is disabled."+ privacy_options:+ description: "How do new users sign up for an account?"+ choices:+ open:+ label: "Users can sign up on their own."+ invite_only:+ label: "Users can sign up on their own, but must be approved by staff."+ must_approve:+ label: "Users must be invited by trusted users or staff before they can sign up."contact:title: "Contact"diff --git a/lib/wizard/builder.rb b/lib/wizard/builder.rbindex b0abb21db09..3e896ec9452 100644--- a/lib/wizard/builder.rb+++ b/lib/wizard/builder.rb@@ -83,15 +83,25 @@ class Wizardprivacy.add_choice('open', icon: 'unlock')privacy.add_choice('restricted', icon: 'lock')- invite_only = step.add_field(id: 'invite_only',- type: 'checkbox',- required: false,- placeholder: 'wizard.invites.add_user',- value: SiteSetting.invite_only?)+ unless SiteSetting.invite_only? && SiteSetting.must_approve_users?+ privacy_option_value = "open"+ privacy_option_value = "invite_only" if SiteSetting.invite_only?+ privacy_option_value = "must_approve" if SiteSetting.must_approve_users?+ privacy_options = step.add_field(id: 'privacy_options',+ type: 'radio',+ required: true,+ value: privacy_option_value)+ privacy_options.add_choice('open')+ privacy_options.add_choice('invite_only')+ privacy_options.add_choice('must_approve')+ endstep.on_update do |updater|updater.update_setting(:login_required, updater.fields[:privacy] == 'restricted')- updater.update_setting(:invite_only, updater.fields[:invite_only])+ unless SiteSetting.invite_only? && SiteSetting.must_approve_users?+ updater.update_setting(:invite_only, updater.fields[:privacy_options] == "invite_only")+ updater.update_setting(:must_approve_users, updater.fields[:privacy_options] == "must_approve")+ endendenddiff --git a/spec/components/wizard/step_updater_spec.rb b/spec/components/wizard/step_updater_spec.rbindex a79f34db37d..f38190a6037 100644--- a/spec/components/wizard/step_updater_spec.rb+++ b/spec/components/wizard/step_updater_spec.rb@@ -63,7 +63,7 @@ describe Wizard::StepUpdater docontext "privacy settings" doit "updates to open correctly" do- updater = wizard.create_updater('privacy', privacy: 'open', invite_only: false)+ updater = wizard.create_updater('privacy', privacy: 'open', privacy_options: 'open')updater.updateexpect(updater.success?).to eq(true)expect(SiteSetting.login_required?).to eq(false)@@ -72,7 +72,7 @@ describe Wizard::StepUpdater doendit "updates to private correctly" do- updater = wizard.create_updater('privacy', privacy: 'restricted', invite_only: true)+ updater = wizard.create_updater('privacy', privacy: 'restricted', privacy_options: 'invite_only')updater.updateexpect(updater.success?).to eq(true)expect(SiteSetting.login_required?).to eq(true)diff --git a/spec/components/wizard/wizard_builder_spec.rb b/spec/components/wizard/wizard_builder_spec.rbindex a9c671eb9c4..b0846fb782c 100644--- a/spec/components/wizard/wizard_builder_spec.rb+++ b/spec/components/wizard/wizard_builder_spec.rb@@ -119,16 +119,28 @@ describe Wizard::Builder doit 'should set the right default value for the fields' doSiteSetting.login_required = true- SiteSetting.invite_only = false+ SiteSetting.invite_only = truefields = privacy_step.fieldslogin_required_field = fields.first- invite_only_field = fields.last+ privacy_options_field = fields.last+ expect(fields.length).to eq(2)expect(login_required_field.id).to eq('privacy')expect(login_required_field.value).to eq("restricted")- expect(invite_only_field.id).to eq('invite_only')- expect(invite_only_field.value).to eq(false)+ expect(privacy_options_field.id).to eq('privacy_options')+ expect(privacy_options_field.value).to eq("invite_only")+ end++ it 'should not show privacy_options field on special case' do+ SiteSetting.invite_only = true+ SiteSetting.must_approve_users = true++ fields = privacy_step.fields+ login_required_field = fields.first++ expect(fields.length).to eq(1)+ expect(login_required_field.id).to eq('privacy')endendend