1
0
Fork 0

Complete new group category actions

Dieser Commit ist enthalten in:
Angus McLeod 2020-07-16 17:50:09 +10:00
Ursprung aa380e2d6c
Commit 1e4348b67a
6 geänderte Dateien mit 98 neuen und 25 gelöschten Zeilen

Datei anzeigen

@ -171,6 +171,8 @@ const action = {
full_name: null, full_name: null,
title: null, title: null,
bio_raw: null, bio_raw: null,
owner_usernames: null,
usernames: null,
grant_trust_level: null, grant_trust_level: null,
mentionable_level: null, mentionable_level: null,
messageable_level: null, messageable_level: null,
@ -195,7 +197,16 @@ const action = {
'color', 'color',
'text_color', 'text_color',
'parent_category_id', 'parent_category_id',
'permittions' '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

@ -413,6 +413,44 @@
)}} )}}
</div> </div>
</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 full field-mapper-setting">
<div class="setting-label"> <div class="setting-label">
<label>{{i18n "admin.wizard.action.create_group.grant_trust_level"}}</label> <label>{{i18n "admin.wizard.action.create_group.grant_trust_level"}}</label>

Datei anzeigen

@ -255,6 +255,8 @@ en:
full_name: Full Name full_name: Full Name
title: Title title: Title
bio_raw: About bio_raw: About
owner_usernames: Owners
usernames: Members
grant_trust_level: Automatic Trust Level grant_trust_level: Automatic Trust Level
mentionable_level: Mentionable Level mentionable_level: Mentionable Level
messageable_level: Messageable Level messageable_level: Messageable Level

Datei anzeigen

@ -138,9 +138,10 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
parent_category_id: mapped_params, parent_category_id: mapped_params,
permissions: mapped_params, permissions: mapped_params,
full_name: mapped_params, full_name: mapped_params,
bio_raw: mapped_params,
title: mapped_params, title: mapped_params,
bio_raw: mapped_params, bio_raw: mapped_params,
usernames: mapped_params,
owner_usernames: mapped_params,
grant_trust_level: mapped_params, grant_trust_level: mapped_params,
mentionable_level: mapped_params, mentionable_level: mapped_params,
messageable_level: mapped_params, messageable_level: mapped_params,

Datei anzeigen

@ -281,12 +281,12 @@ class CustomWizard::Action
group = group =
begin begin
Group.new(new_group_params.merge(user: user)) Group.new(new_group_params)
rescue ArgumentError => e rescue ArgumentError => e
raise Discourse::InvalidParameters, "Invalid group params" raise Discourse::InvalidParameters, "Invalid group params"
end end
if group.update(new_group_params) if group.save
GroupActionLogger.new(user, group).log_change_group_settings GroupActionLogger.new(user, group).log_change_group_settings
log_success("Group created", group.name) log_success("Group created", group.name)
else else
@ -395,18 +395,26 @@ class CustomWizard::Action
name name
full_name full_name
title title
bio_raw
owner_usernames
usernames
mentionable_level mentionable_level
messageable_level messageable_level
visibility_level visibility_level
members_visibility_level members_visibility_level
grant_trust_level grant_trust_level
).each do |attr| ).each do |attr|
if action["group_#{attr}"].present? if action[attr].present?
params[attr.to_sym] = CustomWizard::Mapper.new( value = CustomWizard::Mapper.new(
inputs: action["group_#{attr}"], inputs: action[attr],
data: data, data: data,
user: user user: user
).perform ).perform
value = value.parameterize(separator: '_') if attr === "name"
value = value.to_i if attr.include?("_level")
params[attr.to_sym] = value
end end
end end
@ -425,26 +433,37 @@ class CustomWizard::Action
permissions permissions
).each do |attr| ).each do |attr|
if action[attr].present? if action[attr].present?
params[attr.to_sym] = CustomWizard::Mapper.new( value = CustomWizard::Mapper.new(
inputs: action[attr], inputs: action[attr],
data: data, data: data,
user: user user: user
).perform ).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
end end
if params[:parent_category_id].present? params[attr.to_sym] = value
params[:parent_category_id] = params[:parent_category_id][0]
end 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 end
add_custom_fields(params) add_custom_fields(params)

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