Privacy Step

This commit is contained in:
Robin Ward 2016-09-09 15:57:44 -04:00
parent af83c8dc14
commit e3640ee5f6
12 changed files with 160 additions and 25 deletions

View file

@ -0,0 +1,17 @@
import { observes, on } from 'ember-addons/ember-computed-decorators';
export default Ember.Component.extend({
tagName: 'label',
click(e) {
e.preventDefault();
this.sendAction('onChange', this.get('radioValue'));
},
@observes('value')
@on('init')
updateVal() {
const checked = this.get('value') === this.get('radioValue');
Ember.run.next(() => this.$('input[type=radio]').prop('checked', checked));
}
});

View file

@ -0,0 +1,7 @@
export default Ember.Component.extend({
actions: {
changed(value) {
this.set('field.value', value);
}
}
});

View file

@ -0,0 +1,12 @@
<div class='radio-area'>
<input type="radio" name={{label}}>
<span class='radio-label'>
{{#if icon}}
{{fa-icon icon}}
{{/if}}
{{label}}
</span>
</div>
<div class='radio-description'>
{{description}}
</div>

View file

@ -0,0 +1,10 @@
{{#each field.choices as |c|}}
<div class="radio-field-choice">
{{radio-button value=field.value
radioValue=c.id
label=c.label
icon=c.icon
description=c.description
onChange="changed"}}
</div>
{{/each}}

View file

@ -51,7 +51,8 @@ export default function() {
index: 1, index: 1,
fields: [ fields: [
{ id: 'snack', type: 'dropdown', required: true }, { id: 'snack', type: 'dropdown', required: true },
{ id: 'theme-preview', type: 'component' } { id: 'theme-preview', type: 'component' },
{ id: 'an-image', type: 'image' }
], ],
previous: 'hello-world' previous: 'hello-world'
}] }]

View file

@ -263,3 +263,20 @@ body.wizard {
} }
} }
.radio-field-choice {
margin-bottom: 1.5em;
input {
outline: 0;
}
.radio-label {
font-weight: bold;
margin-left: 0.5em;
}
.radio-description {
margin-top: 0.25em;
margin-left: 1.75em;
color: #777;
}
}

View file

@ -1,17 +1,37 @@
class WizardFieldChoiceSerializer < ApplicationSerializer class WizardFieldChoiceSerializer < ApplicationSerializer
attributes :id, :label, :data attributes :id, :label, :description, :icon, :data
def id def id
object.id object.id
end end
def i18nkey
field = object.field
step = field.step
"wizard.step.#{step.id}.fields.#{field.id}.choices.#{id}"
end
def label def label
return object.label if object.label.present? return object.label if object.label.present?
# Try getting one from a translation # Try getting one from a translation
field = object.field I18n.t("#{i18nkey}.label", default: id)
step = field.step end
I18n.t("wizard.step.#{step.id}.fields.#{field.id}.options.#{id}", default: id)
def description
I18n.t("#{i18nkey}.description", default: "")
end
def include_description?
description.present?
end
def icon
object.icon
end
def include_icon?
object.icon.present?
end end
def data def data

View file

@ -3236,6 +3236,21 @@ en:
site_description: site_description:
label: "Describe your forum in one sentence" label: "Describe your forum in one sentence"
placeholder: "A place for Jane and her friends to discuss cool stuff" placeholder: "A place for Jane and her friends to discuss cool stuff"
privacy:
title: "Privacy Options"
description: "Feel free to set things up privately, then switch to public later!"
fields:
privacy:
choices:
open:
label: "Open Access"
description: "Anyone can access and sign up for your forum"
restricted:
label: "Restricted Access"
description: "Access will be restricted to those you've invited"
contact: contact:
title: "Don't be a Stranger" title: "Don't be a Stranger"
fields: fields:
@ -3255,9 +3270,11 @@ en:
fields: fields:
theme_id: theme_id:
label: "Theme" label: "Theme"
options: choices:
default: "Simple" default:
dark: "Dark" label: "Simple"
dark:
label: "Dark"
logos: logos:
title: "Personalize your Forum" title: "Personalize your Forum"
fields: fields:

View file

@ -52,6 +52,17 @@ class Wizard
step.add_field(id: 'site_description', type: 'text', required: true, value: SiteSetting.site_description) step.add_field(id: 'site_description', type: 'text', required: true, value: SiteSetting.site_description)
end 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')
privacy.add_choice('open', icon: 'unlock')
privacy.add_choice('restricted', icon: 'lock')
end
wizard.append_step('contact') do |step| wizard.append_step('contact') do |step|
step.add_field(id: 'contact_email', type: 'text', required: true, value: SiteSetting.contact_email) step.add_field(id: 'contact_email', type: 'text', required: true, value: SiteSetting.contact_email)
step.add_field(id: 'contact_url', type: 'text', value: SiteSetting.contact_url) step.add_field(id: 'contact_url', type: 'text', value: SiteSetting.contact_url)

View file

@ -1,13 +1,14 @@
class Wizard class Wizard
class Choice class Choice
attr_reader :id, :label, :data attr_reader :id, :label, :icon, :data
attr_accessor :field attr_accessor :field
def initialize(id, opts) def initialize(id, opts)
@id = id @id = id
@data = opts[:data] @data = opts[:data]
@label = opts[:label] @label = opts[:label]
@icon = opts[:icon]
end end
end end

View file

@ -15,19 +15,24 @@ class Wizard
def update_locale(fields) def update_locale(fields)
old_locale = SiteSetting.default_locale old_locale = SiteSetting.default_locale
update_setting(:default_locale, fields, :default_locale) update_setting_field(:default_locale, fields, :default_locale)
@refresh_required = true if old_locale != fields[:default_locale] @refresh_required = true if old_locale != fields[:default_locale]
end end
def update_privacy(fields)
update_setting(:login_required, fields[:privacy] == 'restricted')
update_setting(:invite_only, fields[:privacy] == 'restricted')
end
def update_forum_title(fields) def update_forum_title(fields)
update_setting(:title, fields, :title) update_setting_field(:title, fields, :title)
update_setting(:site_description, fields, :site_description) update_setting_field(:site_description, fields, :site_description)
end end
def update_contact(fields) def update_contact(fields)
update_setting(:contact_email, fields, :contact_email) update_setting_field(:contact_email, fields, :contact_email)
update_setting(:contact_url, fields, :contact_url) update_setting_field(:contact_url, fields, :contact_url)
update_setting(:site_contact_username, fields, :site_contact_username) update_setting_field(:site_contact_username, fields, :site_contact_username)
end end
def update_colors(fields) def update_colors(fields)
@ -60,10 +65,10 @@ class Wizard
end end
def update_logos(fields) def update_logos(fields)
update_setting(:logo_url, fields, :logo_url) update_setting_field(:logo_url, fields, :logo_url)
update_setting(:logo_small_url, fields, :logo_small_url) update_setting_field(:logo_small_url, fields, :logo_small_url)
update_setting(:favicon_url, fields, :favicon_url) update_setting_field(:favicon_url, fields, :favicon_url)
update_setting(:apple_touch_icon_url, fields, :apple_touch_icon_url) update_setting_field(:apple_touch_icon_url, fields, :apple_touch_icon_url)
end end
def success? def success?
@ -76,11 +81,13 @@ class Wizard
protected protected
def update_setting(id, fields, field_id) def update_setting(id, value)
value = fields[field_id]
value.strip! if value.is_a?(String) value.strip! if value.is_a?(String)
SiteSetting.set_and_log(id, value, @current_user) if SiteSetting.send(id) != value SiteSetting.set_and_log(id, value, @current_user) if SiteSetting.send(id) != value
end
def update_setting_field(id, fields, field_id)
update_setting(id, fields[field_id])
rescue Discourse::InvalidParameters => e rescue Discourse::InvalidParameters => e
errors.add(field_id, e.message) errors.add(field_id, e.message)
end end

View file

@ -19,9 +19,6 @@ describe Wizard::StepUpdater do
end end
end end
it "updates the locale" do
end
it "updates the forum title step" do it "updates the forum title step" do
updater = Wizard::StepUpdater.new(user, 'forum_title') updater = Wizard::StepUpdater.new(user, 'forum_title')
updater.update(title: 'new forum title', site_description: 'neat place') updater.update(title: 'new forum title', site_description: 'neat place')
@ -31,6 +28,24 @@ describe Wizard::StepUpdater do
expect(SiteSetting.site_description).to eq("neat place") expect(SiteSetting.site_description).to eq("neat place")
end end
context "privacy settings" do
let(:updater) { Wizard::StepUpdater.new(user, 'privacy') }
it "updates to open correctly" do
updater.update(privacy: 'open')
expect(updater.success?).to eq(true)
expect(SiteSetting.login_required?).to eq(false)
expect(SiteSetting.invite_only?).to eq(false)
end
it "updates to private correctly" do
updater.update(privacy: 'restricted')
expect(updater.success?).to eq(true)
expect(SiteSetting.login_required?).to eq(true)
expect(SiteSetting.invite_only?).to eq(true)
end
end
context "contact step" do context "contact step" do
let(:updater) { Wizard::StepUpdater.new(user, 'contact') } let(:updater) { Wizard::StepUpdater.new(user, 'contact') }