Add Create Category action and Create Group serverside
Dieser Commit ist enthalten in:
Ursprung
f0edc18804
Commit
11bf892bcc
7 geänderte Dateien mit 252 neuen und 6 gelöschten Zeilen
|
@ -20,6 +20,7 @@ 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'),
|
||||
apiEmpty: empty('action.api'),
|
||||
groupPropertyTypes: selectKitContent(['id', 'name']),
|
||||
hasAdvanced: or('hasCustomFields', 'routeTo'),
|
||||
|
|
|
@ -157,6 +157,14 @@ 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
|
||||
}
|
||||
},
|
||||
mapped: [
|
||||
|
@ -170,7 +178,13 @@ const action = {
|
|||
'group',
|
||||
'url',
|
||||
'categories',
|
||||
'mute_remainder'
|
||||
'mute_remainder',
|
||||
'name',
|
||||
'slug',
|
||||
'color',
|
||||
'text_color',
|
||||
'parent_category_id',
|
||||
'permittions'
|
||||
],
|
||||
advanced: [
|
||||
'code',
|
||||
|
|
|
@ -340,6 +340,125 @@
|
|||
</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
|
||||
userFieldSelection=true
|
||||
groupSelection='key'
|
||||
context='action'
|
||||
)}}
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if showAdvanced}}
|
||||
{{wizard-advanced-toggle showAdvanced=action.showAdvanced}}
|
||||
|
||||
|
|
|
@ -35,10 +35,6 @@
|
|||
|
||||
& + div {
|
||||
margin-top: 30px;
|
||||
|
||||
&+ div.setting {
|
||||
margin-top: 30px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -241,6 +241,14 @@ 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
|
||||
|
||||
submissions:
|
||||
nav_label: "Submissions"
|
||||
|
|
|
@ -130,7 +130,13 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
|
|||
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
|
||||
]
|
||||
)
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
@ -274,6 +276,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.merge(user: user))
|
||||
rescue ArgumentError => e
|
||||
raise Discourse::InvalidParameters, "Invalid group params"
|
||||
end
|
||||
|
||||
if group.update(new_group_params)
|
||||
GroupActionLogger.new(user, group).log_change_group_settings
|
||||
log_success("Group created", group.name)
|
||||
else
|
||||
log_error("Group creation failed")
|
||||
end
|
||||
end
|
||||
|
||||
def create_category
|
||||
guardian.ensure_can_create!(Category)
|
||||
|
||||
byebug
|
||||
|
||||
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)
|
||||
else
|
||||
log_error("Category creation failed")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def action_category
|
||||
|
@ -350,6 +390,68 @@ class CustomWizard::Action
|
|||
add_custom_fields(params)
|
||||
end
|
||||
|
||||
def new_group_params
|
||||
params = {}
|
||||
|
||||
%w(
|
||||
name
|
||||
full_name
|
||||
title
|
||||
mentionable_level
|
||||
messageable_level
|
||||
visibility_level
|
||||
members_visibility_level
|
||||
grant_trust_level
|
||||
).each do |attr|
|
||||
if action["group_#{attr}"].present?
|
||||
params[attr.to_sym] = CustomWizard::Mapper.new(
|
||||
inputs: action["group_#{attr}"],
|
||||
data: data,
|
||||
user: user
|
||||
).perform
|
||||
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?
|
||||
params[attr.to_sym] = CustomWizard::Mapper.new(
|
||||
inputs: action[attr],
|
||||
data: data,
|
||||
user: user
|
||||
).perform
|
||||
end
|
||||
end
|
||||
|
||||
if params[:parent_category_id].present?
|
||||
params[:parent_category_id] = params[:parent_category_id][0]
|
||||
end
|
||||
|
||||
if params[:permissions].present?
|
||||
permissions = {}
|
||||
params[:permissions].each do |p|
|
||||
if group = Group.find_by(id: p[:key][0])
|
||||
permissions[group.name] = p[:value].to_i
|
||||
end
|
||||
end
|
||||
params[:permissions] = permissions
|
||||
end
|
||||
|
||||
add_custom_fields(params)
|
||||
end
|
||||
|
||||
def creates_post?
|
||||
[:create_topic, :send_message].include?(action['type'].to_sym)
|
||||
end
|
||||
|
|
Laden …
In neuem Issue referenzieren