1
0
Fork 0

Merge branch 'master' into add_date_time_inputs

Dieser Commit ist enthalten in:
Angus McLeod 2020-07-22 11:30:40 +10:00
Commit 888072f196
18 geänderte Dateien mit 771 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -1 +1 @@
2.6.0.beta1: bb85b3a0d2c0ab6b59bcb405731c39089ec6731c
2.5.0: bb85b3a0d2c0ab6b59bcb405731c39089ec6731c

Datei anzeigen

@ -20,11 +20,13 @@ export default Component.extend(UndoChanges, {
sendToApi: equal('action.type', 'send_to_api'),
addToGroup: equal('action.type', 'add_to_group'),
routeTo: equal('action.type', 'route_to'),
createCategory: equal('action.type', 'create_category'),
createGroup: equal('action.type', 'create_group'),
apiEmpty: empty('action.api'),
groupPropertyTypes: selectKitContent(['id', 'name']),
hasAdvanced: or('hasCustomFields', 'routeTo'),
showAdvanced: and('hasAdvanced', 'action.type'),
hasCustomFields: or('basicTopicFields', 'updateProfile'),
hasCustomFields: or('basicTopicFields', 'updateProfile', 'createGroup', 'createCategory'),
basicTopicFields: or('createTopic', 'sendMessage', 'openComposer'),
publicTopicFields: or('createTopic', 'openComposer'),
showSkipRedirect: or('createTopic', 'sendMessage'),

Datei anzeigen

@ -17,7 +17,7 @@ export default Component.extend(UndoChanges, {
isText: equal('field.type', 'text'),
isTextarea: equal('field.type', 'textarea'),
isUrl: equal('field.type', 'url'),
showPrefill: or('isCategory', 'isTag', 'isGroup', 'isDropdown'),
showPrefill: or('isText', 'isCategory', 'isTag', 'isGroup', 'isDropdown'),
showContent: or('isCategory', 'isTag', 'isGroup', 'isDropdown'),
showLimit: or('isCategory', 'isTag'),
showMinLength: or('isText', 'isTextarea', 'isUrl', 'isComposer'),

Datei anzeigen

@ -13,6 +13,7 @@ export default Component.extend({
showText: computed('activeType', function() { return this.showInput('text') }),
showWizardField: computed('activeType', function() { return this.showInput('wizardField') }),
showWizardAction: computed('activeType', function() { return this.showInput('wizardAction') }),
showUserField: computed('activeType', function() { return this.showInput('userField') }),
showUserFieldOptions: computed('activeType', function() { return this.showInput('userFieldOptions') }),
showCategory: computed('activeType', function() { return this.showInput('category') }),
@ -22,6 +23,7 @@ export default Component.extend({
showList: computed('activeType', function() { return this.showInput('list') }),
textEnabled: computed('options.textSelection', 'inputType', function() { return this.optionEnabled('textSelection') }),
wizardFieldEnabled: computed('options.wizardFieldSelection', 'inputType', function() { return this.optionEnabled('wizardFieldSelection') }),
wizardActionEnabled: computed('options.wizardActionSelection', 'inputType', function() { return this.optionEnabled('wizardActionSelection') }),
userFieldEnabled: computed('options.userFieldSelection', 'inputType', function() { return this.optionEnabled('userFieldSelection') }),
userFieldOptionsEnabled: computed('options.userFieldOptionsSelection', 'inputType', function() { return this.optionEnabled('userFieldOptionsSelection') }),
categoryEnabled: computed('options.categorySelection', 'inputType', function() { return this.optionEnabled('categorySelection') }),
@ -32,7 +34,7 @@ export default Component.extend({
groups: alias('site.groups'),
categories: alias('site.categories'),
showComboBox: or('showWizardField', 'showUserField', 'showUserFieldOptions'),
showComboBox: or('showWizardField', 'showWizardAction', 'showUserField', 'showUserFieldOptions'),
showMultiSelect: or('showCategory', 'showGroup'),
hasTypes: gt('selectorTypes.length', 1),
showTypes: false,
@ -73,20 +75,48 @@ export default Component.extend({
return type ? I18n.t(`admin.wizard.selector.label.${snakeCase(type)}`) : null;
},
comboBoxAllowAny: alias('showWizardField'),
comboBoxAllowAny: or('showWizardField', 'showWizardAction'),
@discourseComputed('activeType')
comboBoxContent(activeType) {
const controller = getOwner(this).lookup('controller:admin-wizards-wizard-show');
const wizardFields = controller.wizardFields;
const userFields = controller.userFields;
@discourseComputed
showController() {
return getOwner(this).lookup('controller:admin-wizards-wizard-show');
},
@discourseComputed(
'activeType',
'showController.wizardFields.[]',
'showController.wizard.actions.[]',
'showController.userFields.[]',
'showController.currentField.id',
'showController.currentAction.id'
)
comboBoxContent(
activeType,
wizardFields,
wizardActions,
userFields,
currentFieldId,
currentActionId
) {
let content;
if (activeType === 'wizardField') {
content = wizardFields;
if (this.options.context === 'field') {
content = content.filter(field => field.id !== controller.currentField.id);
content = content.filter(field => field.id !== currentFieldId);
}
}
if (activeType === 'wizardAction') {
content = wizardActions.map(a => ({
id: a.id,
label: `${generateName(a.type)} (${a.id})`,
type: a.type
}));
if (this.options.context === 'action') {
content = content.filter(a => a.id !== currentActionId);
}
}

Datei anzeigen

@ -11,6 +11,7 @@ export default Component.extend({
previewEnabled: true,
fieldsEnabled: true,
hasWizardFields: notEmpty('wizardFieldList'),
hasWizardActions: notEmpty('wizardActionList'),
didReceiveAttrs() {
this._super(...arguments);
@ -46,6 +47,11 @@ export default Component.extend({
return wizardFields.map((f) => ` w{${f.id}}`);
},
@discourseComputed('wizardActions')
wizardActionList(wizardActions) {
return wizardActions.map((a) => ` w{${a.id}}`);
},
actions: {
togglePreview() {
this.toggleProperty('forcePreview');

Datei anzeigen

@ -46,7 +46,7 @@ export default Controller.extend({
I18n.t('admin.wizard.after_time_time_label');
},
@discourseComputed('currentStep.id', 'wizard.save_submissions', 'wizard.steps.@each.fields[]')
@discourseComputed('currentStep.id', 'wizard.save_submissions', 'currentStep.fields.@each.label')
wizardFields(currentStepId, saveSubmissions) {
let steps = this.wizard.steps;
if (!saveSubmissions) {

Datei anzeigen

@ -80,6 +80,7 @@ const selectionTypes = [
'text',
'list',
'wizardField',
'wizardAction',
'userField',
'userFieldOptions',
'group',

Datei anzeigen

@ -115,6 +115,7 @@ const action = {
post_template: null,
category: null,
tags: null,
visible: null,
custom_fields: null,
skip_redirect: null
},
@ -144,7 +145,9 @@ const action = {
watch_categories: {
categories: null,
notification_level: null,
mute_remainder: null
mute_remainder: null,
wizard_user: true,
usernames: null
},
send_to_api: {
api: null,
@ -157,12 +160,36 @@ const action = {
route_to: {
url: null,
code: null
},
create_category: {
name: null,
slug: null,
color: null,
text_color: "FFFFFF",
parent_category_id: null,
permissions: null,
custom_fields: null
},
create_group: {
name: null,
full_name: null,
title: null,
bio_raw: null,
owner_usernames: null,
usernames: null,
grant_trust_level: null,
mentionable_level: null,
messageable_level: null,
visibility_level: null,
members_visibility_level: null,
custom_fields: null
}
},
mapped: [
'title',
'category',
'tags',
'visible',
'custom_fields',
'required',
'recipient',
@ -170,7 +197,22 @@ const action = {
'group',
'url',
'categories',
'mute_remainder'
'mute_remainder',
'name',
'slug',
'color',
'text_color',
'parent_category_id',
'permissions',
'full_name',
'bio_raw',
'owner_usernames',
'usernames',
'grant_trust_level',
'mentionable_level',
'messageable_level',
'visibility_level',
'members_visibility_level'
],
advanced: [
'code',

Datei anzeigen

@ -139,6 +139,24 @@
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_topic.visible"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.visible
property='visible'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
wizardFieldSelection=true
userFieldSelection=true
context='action'
)}}
</div>
</div>
{{/if}}
{{#if sendMessage}}
@ -297,6 +315,7 @@
options=(hash
textSelection='key,value'
wizardFieldSelection=true
wizardActionSelection=true
userFieldSelection='key,value'
categorySelection='output'
context='action'
@ -338,6 +357,358 @@
)}}
</div>
</div>
<div class="setting full">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.watch_categories.wizard_user"}}</label>
</div>
<div class="setting-value">
{{input type="checkbox" checked=action.wizard_user}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.watch_categories.usernames"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.usernames
property='usernames'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
context='action'
wizardFieldSelection=true
userFieldSelection='key,value'
userSelection='output'
)}}
</div>
</div>
{{/if}}
{{#if createGroup}}
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_group.name"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.name
property='name'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection=true
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_group.full_name"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.full_name
property='full_name'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection=true
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_group.title"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.title
property='title'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection=true
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_group.bio_raw"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.bio_raw
property='bio_raw'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection=true
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_group.owner_usernames"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.owner_usernames
property='owner_usernames'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection=true
userSelection='output'
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_group.usernames"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.usernames
property='usernames'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection=true
userSelection='output'
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_group.grant_trust_level"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.grant_trust_level
property='grant_trust_level'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection=true
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_group.mentionable_level"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.mentionable_level
property='mentionable_level'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection=true
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_group.messageable_level"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.messageable_level
property='messageable_level'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection=true
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_group.visibility_level"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.visibility_level
property='visibility_level'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection=true
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_group.members_visibility_level"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.members_visibility_level
property='members_visibility_level'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection=true
context='action'
)}}
</div>
</div>
{{/if}}
{{#if createCategory}}
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_category.name"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.name
property='name'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection='key,value'
wizardFieldSelection=true
userFieldSelection='key,value'
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_category.slug"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.slug
property='slug'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection='key,value'
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_category.color"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.color
property='color'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection='key,value'
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_category.text_color"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.text_color
property='text_color'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection=true
wizardFieldSelection=true
userFieldSelection='key,value'
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_category.parent_category"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.parent_category_id
property='parent_category_id'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
textSelection='key,value'
wizardFieldSelection=true
userFieldSelection='key,value'
categorySelection='output'
context='action'
)}}
</div>
</div>
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_category.permissions"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.permissions
property='permissions'
onUpdate=(action 'mappedFieldUpdated')
options=(hash
inputTypes='association'
textSelection=true
wizardFieldSelection=true
wizardActionSelection='key'
userFieldSelection=true
groupSelection='key'
context='action'
)}}
</div>
</div>
{{/if}}
{{#if showAdvanced}}

Datei anzeigen

@ -28,6 +28,13 @@
{{wizardFieldList}}
</label>
{{/if}}
{{#if hasWizardActions}}
<label>
{{i18n 'admin.wizard.action.post_builder.wizard_actions'}}
{{wizardActionList}}
</label>
{{/if}}
</div>
{{/if}}
{{/if}}

Datei anzeigen

@ -35,10 +35,6 @@
& + div {
margin-top: 30px;
&+ div.setting {
margin-top: 30px;
}
}
}

Datei anzeigen

@ -94,6 +94,7 @@ en:
label:
text: "text"
wizard_field: "wizard field"
wizard_action: "wizard action"
user_field: "user field"
user_field_options: "user field options"
user: "user"
@ -106,6 +107,7 @@ en:
text: "Enter text"
property: "Select property"
wizard_field: "Select field"
wizard_action: "Select action"
user_field: "Select field"
user_field_options: "Select field"
user: "Select user"
@ -208,6 +210,7 @@ en:
label: "Create Topic"
category: "Category"
tags: "Tags"
visible: "Visible"
open_composer:
label: "Open Composer"
update_profile:
@ -226,11 +229,14 @@ en:
watching_first_post: "Watching First Post"
muted: "Muted"
select_a_notification_level: "Select level"
wizard_user: "Wizard User"
usernames: "Users"
post_builder:
checkbox: "Post Builder"
label: "Builder"
user_properties: "User Properties"
wizard_fields: "Wizard Fields"
wizard_actions: "Wizard Actions"
placeholder: "Insert wizard fields using the field_id in w{}. Insert user properties using property in u{}."
add_to_group:
label: "Add to Group"
@ -246,6 +252,27 @@ en:
select_an_endpoint: "Select an endpoint"
body: "Body"
body_placeholder: "JSON"
create_category:
label: "Create Category"
name: Name
slug: Slug
color: Color
text_color: Text color
parent_category: Parent Category
permissions: Permissions
create_group:
label: Create Group
name: Name
full_name: Full Name
title: Title
bio_raw: About
owner_usernames: Owners
usernames: Members
grant_trust_level: Automatic Trust Level
mentionable_level: Mentionable Level
messageable_level: Messageable Level
visibility_level: Visibility Level
members_visibility_level: Members Visibility Level
submissions:
nav_label: "Submissions"

Datei anzeigen

@ -121,17 +121,35 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
:api,
:api_endpoint,
:api_body,
:wizard_user,
title: mapped_params,
category: mapped_params,
tags: mapped_params,
custom_fields: mapped_params,
visible: mapped_params,
required: mapped_params,
recipient: mapped_params,
categories: mapped_params,
mute_remainder: mapped_params,
profile_updates: mapped_params,
group: mapped_params,
url: mapped_params
url: mapped_params,
name: mapped_params,
slug: mapped_params,
color: mapped_params,
text_color: mapped_params,
parent_category_id: mapped_params,
permissions: mapped_params,
full_name: mapped_params,
title: mapped_params,
bio_raw: mapped_params,
usernames: mapped_params,
owner_usernames: mapped_params,
grant_trust_level: mapped_params,
mentionable_level: mapped_params,
messageable_level: mapped_params,
visibility_level: mapped_params,
members_visibility_level: mapped_params
]
)
end

Datei anzeigen

@ -0,0 +1,27 @@
class UpdateWatchCategoriesAction < ActiveRecord::Migration[6.0]
def change
watch_category_wizards = PluginStoreRow.where("
plugin_name = 'custom_wizard' AND
value::jsonb -> 'actions' @> '[{ \"type\" : \"watch_categories\" }]'::jsonb
")
if watch_category_wizards.exists?
watch_category_wizards.each do |row|
begin
wizard_json = JSON.parse(row.value)
rescue TypeError, JSON::ParserError
next
end
wizard_json['actions'].each do |a|
if a['type'] === "watch_categories" && a['wizard_user'] == nil
a['wizard_user'] = true
end
end
row.value = wizard_json.to_json
row.save
end
end
end
end

Datei anzeigen

@ -2,12 +2,14 @@ class CustomWizard::Action
attr_accessor :data,
:action,
:user,
:guardian,
:result
def initialize(params)
@wizard = params[:wizard]
@action = params[:action]
@user = params[:user]
@guardian = Guardian.new(@user)
@data = params[:data]
@log = []
@result = CustomWizard::ActionResult.new
@ -22,6 +24,10 @@ class CustomWizard::Action
@result.handler.enqueue_jobs
end
if @result.success? && @result.output.present?
data[action['id']] = @result.output
end
save_log
end
@ -30,12 +36,9 @@ class CustomWizard::Action
end
def create_topic
params = basic_topic_params
params = basic_topic_params.merge(public_topic_params)
if params[:title].present? && params[:raw].present?
params[:category] = action_category
params[:tags] = action_tags
creator = PostCreator.new(user, params)
post = creator.create
@ -49,6 +52,7 @@ class CustomWizard::Action
if creator.errors.blank?
log_success("created topic", "id: #{post.topic.id}")
result.handler = creator
result.output = post.topic.id
end
else
log_error("invalid topic params", "title: #{params[:title]}; post: #{params[:raw]}")
@ -87,6 +91,7 @@ class CustomWizard::Action
if creator.errors.blank?
log_success("created message", "id: #{post.topic.id}")
result.handler = creator
result.output = post.topic.id
end
else
log_error(
@ -135,17 +140,18 @@ class CustomWizard::Action
end
def watch_categories
watched_categories = CustomWizard::Mapper.new(
inputs: action['categories'],
data: data,
user: user
).perform
watched_categories = [*watched_categories].map(&:to_i)
notification_level = action['notification_level']
if notification_level.blank?
log_error("Notifcation Level was not set! Exiting wizard action")
log_error("Notifcation Level was not set. Exiting wizard action")
return
end
@ -154,12 +160,52 @@ class CustomWizard::Action
data: data,
user: user
).perform
users = []
if action['usernames']
mapped_users = CustomWizard::Mapper.new(
inputs: action['usernames'],
data: data,
user: user
).perform
if mapped_users.present?
mapped_users = mapped_users.split(',')
.map { |username| User.find_by(username: username) }
users.push(*mapped_users)
end
end
if ActiveRecord::Type::Boolean.new.cast(action['wizard_user'])
users.push(user)
end
Category.all.each do |category|
if watched_categories.present? && watched_categories.include?(category.id.to_s)
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[notification_level.to_sym], category.id)
elsif mute_remainder
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id)
category_ids = Category.all.pluck(:id)
set_level = CategoryUser.notification_levels[notification_level.to_sym]
mute_level = CategoryUser.notification_levels[:muted]
users.each do |user|
category_ids.each do |category_id|
new_level = nil
if watched_categories.include?(category_id) && set_level != nil
new_level = set_level
elsif mute_remainder
new_level = mute_level
end
if new_level
CategoryUser.set_notification_level_for_category(user, new_level, category_id)
end
end
if watched_categories.any?
log_success("#{user.username} notifications for #{watched_categories} set to #{set_level}")
end
if mute_remainder
log_success("#{user.username} notifications for all other categories muted")
end
end
end
@ -274,6 +320,44 @@ class CustomWizard::Action
log_info("route: #{route_to}")
end
def create_group
guardian.ensure_can_create!(Group)
group =
begin
Group.new(new_group_params)
rescue ArgumentError => e
raise Discourse::InvalidParameters, "Invalid group params"
end
if group.save
GroupActionLogger.new(user, group).log_change_group_settings
log_success("Group created", group.name)
result.output = group.name
else
log_error("Group creation failed")
end
end
def create_category
guardian.ensure_can_create!(Category)
category =
begin
Category.new(new_category_params.merge(user: user))
rescue ArgumentError => e
raise Discourse::InvalidParameters, "Invalid category params"
end
if category.save
StaffActionLogger.new(user).log_category_creation(category)
log_success("Category created", category.name)
result.output = category.id
else
log_error("Category creation failed")
end
end
private
def action_category
@ -350,10 +434,131 @@ class CustomWizard::Action
add_custom_fields(params)
end
def public_topic_params
params = {}
if (category = action_category)
params[:category] = category
end
if (tags = action_tags)
params[:tags] = tags
end
if public_topic_fields.any?
public_topic_fields.each do |field|
unless action[field].nil? || action[field] == ""
params[field.to_sym] = CustomWizard::Mapper.new(
inputs: action[field],
data: data,
user: user
).perform
end
end
end
params
end
def new_group_params
params = {}
%w(
name
full_name
title
bio_raw
owner_usernames
usernames
mentionable_level
messageable_level
visibility_level
members_visibility_level
grant_trust_level
).each do |attr|
input = action[attr]
if attr === "name" && input.blank?
raise ArgumentError.new
end
if attr === "full_name" && input.blank?
input = action["name"]
end
if input.present?
value = CustomWizard::Mapper.new(
inputs: input,
data: data,
user: user
).perform
value = value.parameterize(separator: '_') if attr === "name"
value = value.to_i if attr.include?("_level")
params[attr.to_sym] = value
end
end
add_custom_fields(params)
end
def new_category_params
params = {}
%w(
name
slug
color
text_color
parent_category_id
permissions
).each do |attr|
if action[attr].present?
value = CustomWizard::Mapper.new(
inputs: action[attr],
data: data,
user: user
).perform
if attr === "parent_category_id" && value.is_a?(Array)
value = value[0]
end
if attr === "permissions" && value.is_a?(Array)
permissions = value
value = {}
permissions.each do |p|
k = p[:key]
v = p[:value].to_i
if k.is_a?(Array)
group = Group.find_by(id: k[0])
k = group.name
else
k = k.parameterize(separator: '_')
end
value[k] = v
end
end
params[attr.to_sym] = value
end
end
add_custom_fields(params)
end
def creates_post?
[:create_topic, :send_message].include?(action['type'].to_sym)
end
def public_topic_fields
['visible']
end
def profile_url_fields
['profile_background', 'card_background']
end

Datei anzeigen

@ -1,5 +1,5 @@
class CustomWizard::ActionResult
attr_accessor :success, :handler
attr_accessor :success, :handler, :output
def initialize
@success = false

Datei anzeigen

@ -2,10 +2,12 @@ class CustomWizard::Field
def self.types
@types ||= {
text: {
min_length: nil
min_length: nil,
prefill: nil
},
textarea: {
min_length: nil
min_length: nil,
prefill: nil
},
composer: {
min_length: nil

Datei anzeigen

@ -187,6 +187,10 @@ class CustomWizard::Mapper
def map_wizard_field(value)
data && !data.key?("submitted_at") && data[value]
end
def map_wizard_action(value)
data && !data.key?("submitted_at") && data[value]
end
def map_user_field(value)
if value.include?(User::USER_FIELD_PREFIX)