1
0
Fork 0

Merge pull request #47 from paviliondev/create_category_and_create_group_actions

Create category and create group actions
Dieser Commit ist enthalten in:
Angus McLeod 2020-07-17 11:09:14 +10:00 committet von GitHub
Commit 783af5b5f7
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
9 geänderte Dateien mit 533 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -20,6 +20,8 @@ export default Component.extend(UndoChanges, {
sendToApi: equal('action.type', 'send_to_api'), sendToApi: equal('action.type', 'send_to_api'),
addToGroup: equal('action.type', 'add_to_group'), addToGroup: equal('action.type', 'add_to_group'),
routeTo: equal('action.type', 'route_to'), routeTo: equal('action.type', 'route_to'),
createCategory: equal('action.type', 'create_category'),
createGroup: equal('action.type', 'create_group'),
apiEmpty: empty('action.api'), apiEmpty: empty('action.api'),
groupPropertyTypes: selectKitContent(['id', 'name']), groupPropertyTypes: selectKitContent(['id', 'name']),
hasAdvanced: or('hasCustomFields', 'routeTo'), hasAdvanced: or('hasCustomFields', 'routeTo'),

Datei anzeigen

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

Datei anzeigen

@ -157,6 +157,27 @@ const action = {
route_to: { route_to: {
url: null, url: null,
code: null code: null
},
create_category: {
name: null,
slug: null,
color: null,
text_color: "FFFFFF",
parent_category_id: null,
permissions: 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
} }
}, },
mapped: [ mapped: [
@ -170,7 +191,22 @@ const action = {
'group', 'group',
'url', 'url',
'categories', '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: [ advanced: [
'code', 'code',

Datei anzeigen

@ -340,6 +340,328 @@
</div> </div>
{{/if}} {{/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
userFieldSelection=true
groupSelection='key'
context='action'
)}}
</div>
</div>
{{/if}}
{{#if showAdvanced}} {{#if showAdvanced}}
{{wizard-advanced-toggle showAdvanced=action.showAdvanced}} {{wizard-advanced-toggle showAdvanced=action.showAdvanced}}

Datei anzeigen

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

Datei anzeigen

@ -241,6 +241,27 @@ en:
select_an_endpoint: "Select an endpoint" select_an_endpoint: "Select an endpoint"
body: "Body" body: "Body"
body_placeholder: "JSON" 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: submissions:
nav_label: "Submissions" nav_label: "Submissions"

Datei anzeigen

@ -130,7 +130,23 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
mute_remainder: mapped_params, mute_remainder: mapped_params,
profile_updates: mapped_params, profile_updates: mapped_params,
group: 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 end

Datei anzeigen

@ -2,12 +2,14 @@ class CustomWizard::Action
attr_accessor :data, attr_accessor :data,
:action, :action,
:user, :user,
:guardian,
:result :result
def initialize(params) def initialize(params)
@wizard = params[:wizard] @wizard = params[:wizard]
@action = params[:action] @action = params[:action]
@user = params[:user] @user = params[:user]
@guardian = Guardian.new(@user)
@data = params[:data] @data = params[:data]
@log = [] @log = []
@result = CustomWizard::ActionResult.new @result = CustomWizard::ActionResult.new
@ -274,6 +276,42 @@ class CustomWizard::Action
log_info("route: #{route_to}") log_info("route: #{route_to}")
end 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)
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)
else
log_error("Category creation failed")
end
end
private private
def action_category def action_category
@ -350,6 +388,97 @@ class CustomWizard::Action
add_custom_fields(params) add_custom_fields(params)
end 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? def creates_post?
[:create_topic, :send_message].include?(action['type'].to_sym) [:create_topic, :send_message].include?(action['type'].to_sym)
end end

Datei anzeigen

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