FEATURE: better wizard privacy controls (#7391)

This commit is contained in:
Arpit Jalan 2019-04-22 19:47:29 +05:30 committed by GitHub
parent f112f279ae
commit a63ef4cfc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 15 deletions

View File

@ -1,5 +1,5 @@
{{#each field.choices as |c|}}
<div class="radio-field-choice">
<div class="radio-field-choice {{fieldClass}}">
{{radio-button value=field.value
radioValue=c.id
label=c.label

View File

@ -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;
}

View File

@ -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"

View File

@ -83,15 +83,25 @@ class Wizard
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?)
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')
end
step.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")
end
end
end

View File

@ -63,7 +63,7 @@ describe Wizard::StepUpdater do
context "privacy settings" do
it "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.update
expect(updater.success?).to eq(true)
expect(SiteSetting.login_required?).to eq(false)
@ -72,7 +72,7 @@ describe Wizard::StepUpdater do
end
it "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.update
expect(updater.success?).to eq(true)
expect(SiteSetting.login_required?).to eq(true)

View File

@ -119,16 +119,28 @@ describe Wizard::Builder do
it 'should set the right default value for the fields' do
SiteSetting.login_required = true
SiteSetting.invite_only = false
SiteSetting.invite_only = true
fields = privacy_step.fields
login_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')
end
end
end