Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tagging personal messages #271

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/javascripts/discourse/lib/wizard-schema.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const action = {
post: null,
post_builder: null,
post_template: null,
tags: null,
skip_redirect: null,
custom_fields: null,
required: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@
</div>
</div>

<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_topic.tags"}}</label>
</div>

<div class="setting-value">
{{wizard-mapper
inputs=this.action.tags
property="tags"
onUpdate=(action "mappedFieldUpdated")
options=(hash
tagSelection="output"
outputDefaultSelection="tag"
listSelection="output"
wizardFieldSelection=true
userFieldSelection="key,value"
context="action"
)
}}
</div>
</div>

{{#if this.action.post_builder}}
<div class="setting full">
<div class="setting-label">
Expand Down Expand Up @@ -124,28 +146,6 @@
</div>
</div>

<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.create_topic.tags"}}</label>
</div>

<div class="setting-value">
{{wizard-mapper
inputs=this.action.tags
property="tags"
onUpdate=(action "mappedFieldUpdated")
options=(hash
tagSelection="output"
outputDefaultSelection="tag"
listSelection="output"
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_topic.visible"}}</label>
Expand Down
14 changes: 10 additions & 4 deletions lib/custom_wizard/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def send_message
end

params = basic_topic_params
params.delete(:tags) unless user_can_tag

targets = CustomWizard::Mapper.new(
inputs: action['recipient'],
Expand Down Expand Up @@ -610,6 +611,10 @@ def basic_topic_params
user: user
).perform

if tags = action_tags
params[:tags] = tags
end

params[:raw] = action['post_builder'] ?
mapper.interpolate(
action['post_template'],
Expand All @@ -632,10 +637,6 @@ def public_topic_params
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] == ""
Expand Down Expand Up @@ -837,4 +838,9 @@ def save_log
@log.join('; ')
)
end
def user_can_tag
allowed_groups =
SiteSetting.pm_tags_allowed_for_groups.split('|').map(&:to_i)
user.groups.pluck(:id).any? { |group| allowed_groups.include?(group) }
end
end