Skip to content

Commit

Permalink
FIX: correctly retrieve 'login required' setting value on wizard (#7355)
Browse files Browse the repository at this point in the history
* FIX: correctly retrieve 'login required' setting value on wizard

FEATURE: extract 'invite only' setting in a separate checkbox control

* Update invite_only checkbox locale on wizard.

Co-Authored-By: techAPJ <arpit@techapj.com>
  • Loading branch information
arpitjalan committed Apr 11, 2019
1 parent 9a428ac commit 7143572
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
@@ -0,0 +1,7 @@
<label>
{{input type="checkbox"
class="wizard-checkbox"
checked=field.value}}

{{field.placeholder}}
</label>
6 changes: 4 additions & 2 deletions config/locales/server.en.yml
Expand Up @@ -4261,10 +4261,12 @@ en:
choices:
open:
label: "Public"
description: "Anyone can access this community and sign up for an account"
description: "Anyone can access this community"
restricted:
label: "Private"
description: "Only people I have invited or approved can access this community"
description: "Only logged in users can access this community"
invite_only:
placeholder: "People must be explicitly invited. Public registration is disabled."
contact:
title: "Contact"
Expand Down
11 changes: 8 additions & 3 deletions lib/wizard/builder.rb
Expand Up @@ -76,17 +76,22 @@ def build
end

@wizard.append_step('privacy') do |step|
locked = SiteSetting.login_required? && SiteSetting.invite_only?
privacy = step.add_field(id: 'privacy',
type: 'radio',
required: true,
value: locked ? 'restricted' : 'open')
value: SiteSetting.login_required? ? 'restricted' : 'open')
privacy.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?)

step.on_update do |updater|
updater.update_setting(:login_required, updater.fields[:privacy] == 'restricted')
updater.update_setting(:invite_only, updater.fields[:privacy] == 'restricted')
updater.update_setting(:invite_only, updater.fields[:invite_only])
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/components/wizard/step_updater_spec.rb
Expand Up @@ -63,7 +63,7 @@

context "privacy settings" do
it "updates to open correctly" do
updater = wizard.create_updater('privacy', privacy: 'open')
updater = wizard.create_updater('privacy', privacy: 'open', invite_only: false)
updater.update
expect(updater.success?).to eq(true)
expect(SiteSetting.login_required?).to eq(false)
Expand All @@ -72,7 +72,7 @@
end

it "updates to private correctly" do
updater = wizard.create_updater('privacy', privacy: 'restricted')
updater = wizard.create_updater('privacy', privacy: 'restricted', invite_only: true)
updater.update
expect(updater.success?).to eq(true)
expect(SiteSetting.login_required?).to eq(true)
Expand Down
18 changes: 18 additions & 0 deletions spec/components/wizard/wizard_builder_spec.rb
Expand Up @@ -113,4 +113,22 @@ class GlobalPathInstance
end
end
end

context 'privacy step' do
let(:privacy_step) { wizard.steps.find { |s| s.id == 'privacy' } }

it 'should set the right default value for the fields' do
SiteSetting.login_required = true
SiteSetting.invite_only = false

fields = privacy_step.fields
login_required_field = fields.first
invite_only_field = fields.last

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)
end
end
end

0 comments on commit 7143572

Please sign in to comment.