From f693a2d25a40fc44ed4fbd3a97719e0934e0290f Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 1 Jul 2019 12:31:50 +1000 Subject: [PATCH] Add add_to_group action --- .../components/wizard-custom-action.js.es6 | 4 +++- .../components/wizard-custom-field.js.es6 | 8 ++++++- .../components/wizard-custom-action.hbs | 22 +++++++++++++++++++ config/locales/client.en.yml | 6 +++++ lib/builder.rb | 18 ++++++++++++++- 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 976501e5..8a2147b1 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -3,7 +3,8 @@ import { default as computed, observes } from 'ember-addons/ember-computed-decor const ACTION_TYPES = [ { id: 'create_topic', name: 'Create Topic' }, { id: 'update_profile', name: 'Update Profile' }, - { id: 'send_message', name: 'Send Message' } + { id: 'send_message', name: 'Send Message' }, + { id: 'add_to_group', name: 'Add to Group' } ]; const PROFILE_FIELDS = [ @@ -26,6 +27,7 @@ export default Ember.Component.extend({ createTopic: Ember.computed.equal('action.type', 'create_topic'), updateProfile: Ember.computed.equal('action.type', 'update_profile'), sendMessage: Ember.computed.equal('action.type', 'send_message'), + addToGroup: Ember.computed.equal('action.type', 'add_to_group'), disableId: Ember.computed.not('action.isNew'), @computed('currentStepId', 'wizard.save_submissions') diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index bdef2d67..19cc0ba2 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -15,7 +15,13 @@ export default Ember.Component.extend({ @computed() presetChoices() { return [ - { id: 'categories', name: I18n.t('admin.wizard.field.choices_preset.categories') } + { + id: 'categories', + name: I18n.t('admin.wizard.field.choices_preset.categories') + },{ + id: 'groups', + name: I18n.t('admin.wizard.field.choices_preset.groups') + } ]; }, }); diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 7a7f3cfc..5cc5685e 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -204,3 +204,25 @@ allowUserField=true}} {{/if}} + +{{#if addToGroup}} +
+
+

{{i18n "admin.wizard.action.add_to_group.group_selection"}}

+
+
+ {{combo-box value=action.group_id + content=availableFields + nameProperty="label" + none='admin.wizard.select_field' + isDisabled=action.custom_group_enabled}} +
+ {{input type='checkbox' checked=action.custom_group_enabled}} + {{i18n 'admin.wizard.action.add_to_group.custom_group'}} + {{#if action.custom_group_enabled}} + {{input value=action.group_id}} + {{/if}} +
+
+
+{{/if}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 84e5bd06..5463f94a 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -87,6 +87,7 @@ en: choices_preset: label: "Preset" categories: "Categories" + groups: "Groups" filter: "Preset Filter" choice: value: "Value" @@ -121,6 +122,11 @@ en: user_fields: "User Fields: " wizard_fields: "Wizard Fields: " placeholder: "Insert wizard fields using the field_id in w{}. Insert user fields using field key in u{}." + add_to_group: + label: "Add to Group" + group: "Group" + group_selection: "Group Selection" + custom_group: "Custom Group" custom_title: "Custom Title" custom_category: label: "Custom Category" diff --git a/lib/builder.rb b/lib/builder.rb index 0e5c4fb1..542a3f8b 100644 --- a/lib/builder.rb +++ b/lib/builder.rb @@ -202,9 +202,14 @@ class CustomWizard::Builder end elsif field_template['choices_preset'] && field_template['choices_preset'].length > 0 objects = [] + site = Site.new(Guardian.new(@wizard.user)) if field_template['choices_preset'] === 'categories' - objects = Site.new(Guardian.new(@wizard.user)).categories + objects = site.categories + end + + if field_template['choices_preset'] === 'groups' + objects = site.groups end if field_template['choices_filters'] && field_template['choices_filters'].length > 0 @@ -404,6 +409,17 @@ class CustomWizard::Builder end end + def add_to_group(user, action, data) + puts "GROUP NAME: #{data[action['group_id']]}" + if group_id = data[action['group_id']] + puts "GROUP: #{Group.find(group_id)}" + if group = Group.find(group_id) + puts "HERE IS THE GROUP: #{group.inspect}" + group.add(user) + end + end + end + def save_submissions(data, final_step) if final_step data['submitted_at'] = Time.now.iso8601