0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 18:50:27 +01:00

Add watch_tags action

Dieser Commit ist enthalten in:
Angus McLeod 2022-12-23 17:28:09 +01:00
Ursprung 17fe4d732a
Commit 34ff9e4136
8 geänderte Dateien mit 163 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -15,6 +15,7 @@ export default Component.extend(UndoChanges, {
createTopic: equal("action.type", "create_topic"), createTopic: equal("action.type", "create_topic"),
updateProfile: equal("action.type", "update_profile"), updateProfile: equal("action.type", "update_profile"),
watchCategories: equal("action.type", "watch_categories"), watchCategories: equal("action.type", "watch_categories"),
watchTags: equal("action.type", "watch_tags"),
sendMessage: equal("action.type", "send_message"), sendMessage: equal("action.type", "send_message"),
openComposer: equal("action.type", "open_composer"), openComposer: equal("action.type", "open_composer"),
sendToApi: equal("action.type", "send_to_api"), sendToApi: equal("action.type", "send_to_api"),
@ -36,9 +37,7 @@ export default Component.extend(UndoChanges, {
availableNotificationLevels: notificationLevels.map((type) => { availableNotificationLevels: notificationLevels.map((type) => {
return { return {
id: type, id: type,
name: I18n.t( name: I18n.t(`admin.wizard.action.watch_x.notification_level.${type}`),
`admin.wizard.action.watch_categories.notification_level.${type}`
),
}; };
}), }),

Datei anzeigen

@ -132,6 +132,12 @@ const action = {
wizard_user: true, wizard_user: true,
usernames: null, usernames: null,
}, },
watch_tags: {
tags: null,
notification_level: null,
wizard_user: true,
usernames: null,
},
send_to_api: { send_to_api: {
api: null, api: null,
api_endpoint: null, api_endpoint: null,

Datei anzeigen

@ -386,7 +386,7 @@
<div class="setting"> <div class="setting">
<div class="setting-label"> <div class="setting-label">
<label>{{i18n "admin.wizard.action.watch_categories.notification_level.label"}}</label> <label>{{i18n "admin.wizard.action.watch_x.notification_level.label"}}</label>
</div> </div>
<div class="setting-value"> <div class="setting-value">
@ -396,14 +396,14 @@
onChange=(action (mut action.notification_level)) onChange=(action (mut action.notification_level))
options=(hash options=(hash
isDisabled=action.custom_title_enabled isDisabled=action.custom_title_enabled
none="admin.wizard.action.watch_categories.select_a_notification_level" none="admin.wizard.action.watch_x.select_a_notification_level"
)}} )}}
</div> </div>
</div> </div>
<div class="setting full"> <div class="setting full">
<div class="setting-label"> <div class="setting-label">
<label>{{i18n "admin.wizard.action.watch_categories.wizard_user"}}</label> <label>{{i18n "admin.wizard.action.watch_x.wizard_user"}}</label>
</div> </div>
<div class="setting-value"> <div class="setting-value">
@ -413,7 +413,76 @@
<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.watch_categories.usernames"}}</label> <label>{{i18n "admin.wizard.action.watch_x.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 watchTags}}
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.watch_tags.tags"}}</label>
</div>
<div class="setting-value">
{{wizard-mapper
inputs=action.tags
property="tags"
onUpdate=(action "mappedFieldUpdated")
options=(hash
textSelection="key,value"
tagSelection="output"
wizardFieldSelection=true
wizardActionSelection=true
userFieldSelection="key,value"
context="action"
)}}
</div>
</div>
<div class="setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.watch_x.notification_level.label"}}</label>
</div>
<div class="setting-value">
{{combo-box
value=action.notification_level
content=availableNotificationLevels
onChange=(action (mut action.notification_level))
options=(hash
isDisabled=action.custom_title_enabled
none="admin.wizard.action.watch_x.select_a_notification_level"
)}}
</div>
</div>
<div class="setting full">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.watch_x.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_x.usernames"}}</label>
</div> </div>
<div class="setting-value"> <div class="setting-value">

Datei anzeigen

@ -370,6 +370,10 @@ en:
label: "Watch Categories" label: "Watch Categories"
categories: "Categories" categories: "Categories"
mute_remainder: "Mute Remainder" mute_remainder: "Mute Remainder"
watch_tags:
label: "Watch Tags"
tags: "Tags"
watch_x:
notification_level: notification_level:
label: "Notification Level" label: "Notification Level"
regular: "Normal" regular: "Normal"

Datei anzeigen

@ -190,6 +190,52 @@ class CustomWizard::Action
end end
end end
def watch_tags
tags = CustomWizard::Mapper.new(
inputs: action['tags'],
data: mapper_data,
user: user
).perform
tags = [*tags]
level = action['notification_level'].to_sym
if level.blank?
log_error("Notifcation Level was not set. Exiting watch tags action")
return
end
users = []
if action['usernames']
mapped_users = CustomWizard::Mapper.new(
inputs: action['usernames'],
data: mapper_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
users.each do |user|
result = TagUser.batch_set(user, level, tags)
if result
log_success("#{user.username} notifications for #{tags} set to #{level}")
else
log_error("failed to set #{user.username} notifications for #{tags} to #{level}")
end
end
end
def watch_categories def watch_categories
watched_categories = CustomWizard::Mapper.new( watched_categories = CustomWizard::Mapper.new(
inputs: action['categories'], inputs: action['categories'],

Datei anzeigen

@ -69,7 +69,7 @@ class CustomWizard::Subscription
action: { action: {
type: { type: {
none: ['create_topic', 'update_profile', 'open_composer', 'route_to'], none: ['create_topic', 'update_profile', 'open_composer', 'route_to'],
standard: ['create_topic', 'update_profile', 'open_composer', 'route_to', 'send_message', 'watch_categories', 'add_to_group'], standard: ['create_topic', 'update_profile', 'open_composer', 'route_to', 'send_message', 'watch_categories', 'watch_tags', 'add_to_group'],
business: ['*'], business: ['*'],
community: ['*'] community: ['*']
} }

Datei anzeigen

@ -3,12 +3,14 @@
describe CustomWizard::Action do describe CustomWizard::Action do
fab!(:user) { Fabricate(:user, name: "Angus", username: 'angus', email: "angus@email.com", trust_level: TrustLevel[2]) } fab!(:user) { Fabricate(:user, name: "Angus", username: 'angus', email: "angus@email.com", trust_level: TrustLevel[2]) }
fab!(:category) { Fabricate(:category, name: 'cat1', slug: 'cat-slug') } fab!(:category) { Fabricate(:category, name: 'cat1', slug: 'cat-slug') }
fab!(:tag) { Fabricate(:tag, name: 'tag1') }
fab!(:group) { Fabricate(:group) } fab!(:group) { Fabricate(:group) }
let(:wizard_template) { get_wizard_fixture("wizard") } let(:wizard_template) { get_wizard_fixture("wizard") }
let(:open_composer) { get_wizard_fixture("actions/open_composer") } let(:open_composer) { get_wizard_fixture("actions/open_composer") }
let(:create_category) { get_wizard_fixture("actions/create_category") } let(:create_category) { get_wizard_fixture("actions/create_category") }
let(:watch_categories) { get_wizard_fixture("actions/watch_categories") } let(:watch_categories) { get_wizard_fixture("actions/watch_categories") }
let(:watch_tags) { get_wizard_fixture("actions/watch_tags") }
let(:create_group) { get_wizard_fixture("actions/create_group") } let(:create_group) { get_wizard_fixture("actions/create_group") }
let(:add_to_group) { get_wizard_fixture("actions/add_to_group") } let(:add_to_group) { get_wizard_fixture("actions/add_to_group") }
let(:send_message) { get_wizard_fixture("actions/send_message") } let(:send_message) { get_wizard_fixture("actions/send_message") }
@ -219,6 +221,20 @@ describe CustomWizard::Action do
enable_subscription("standard") enable_subscription("standard")
end end
it 'watches tags' do
watch_tags[:tags][0][:output] = tag.name
wizard_template[:actions] << watch_tags
update_template(wizard_template)
wizard = CustomWizard::Builder.new(@template[:id], user).build
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update
expect(TagUser.where(
tag_id: tag.id,
user_id: user.id
).first.notification_level).to eq(2)
end
it 'watches categories' do it 'watches categories' do
watch_categories[:categories][0][:output] = category.id watch_categories[:categories][0][:output] = category.id
wizard_template[:actions] << watch_categories wizard_template[:actions] << watch_categories

15
spec/fixtures/actions/watch_tags.json gevendort Normale Datei
Datei anzeigen

@ -0,0 +1,15 @@
{
"id": "action_3",
"run_after": "step_1",
"type": "watch_tags",
"notification_level": "tracking",
"wizard_user": true,
"tags": [
{
"type": "assignment",
"output": "tag1",
"output_type": "text",
"output_connector": "set"
}
]
}