Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 09:20:29 +01:00
Merge pull request #48 from paviliondev/set_watch_category_users
Set watch category users
Dieser Commit ist enthalten in:
Commit
c4eb3e6cff
6 geänderte Dateien mit 111 neuen und 8 gelöschten Zeilen
|
@ -144,7 +144,9 @@ const action = {
|
||||||
watch_categories: {
|
watch_categories: {
|
||||||
categories: null,
|
categories: null,
|
||||||
notification_level: null,
|
notification_level: null,
|
||||||
mute_remainder: null
|
mute_remainder: null,
|
||||||
|
wizard_user: true,
|
||||||
|
usernames: null
|
||||||
},
|
},
|
||||||
send_to_api: {
|
send_to_api: {
|
||||||
api: null,
|
api: null,
|
||||||
|
|
|
@ -297,6 +297,7 @@
|
||||||
options=(hash
|
options=(hash
|
||||||
textSelection='key,value'
|
textSelection='key,value'
|
||||||
wizardFieldSelection=true
|
wizardFieldSelection=true
|
||||||
|
wizardActionSelection=true
|
||||||
userFieldSelection='key,value'
|
userFieldSelection='key,value'
|
||||||
categorySelection='output'
|
categorySelection='output'
|
||||||
context='action'
|
context='action'
|
||||||
|
@ -338,6 +339,35 @@
|
||||||
)}}
|
)}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="setting full">
|
||||||
|
<div class="setting-label">
|
||||||
|
<label>{{i18n "admin.wizard.action.watch_categories.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_categories.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}}
|
||||||
|
|
||||||
{{#if createGroup}}
|
{{#if createGroup}}
|
||||||
|
|
|
@ -223,6 +223,8 @@ en:
|
||||||
watching_first_post: "Watching First Post"
|
watching_first_post: "Watching First Post"
|
||||||
muted: "Muted"
|
muted: "Muted"
|
||||||
select_a_notification_level: "Select level"
|
select_a_notification_level: "Select level"
|
||||||
|
wizard_user: "Wizard User"
|
||||||
|
usernames: "Users"
|
||||||
post_builder:
|
post_builder:
|
||||||
checkbox: "Post Builder"
|
checkbox: "Post Builder"
|
||||||
label: "Builder"
|
label: "Builder"
|
||||||
|
|
|
@ -120,6 +120,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
|
||||||
:api,
|
:api,
|
||||||
:api_endpoint,
|
:api_endpoint,
|
||||||
:api_body,
|
:api_body,
|
||||||
|
:wizard_user,
|
||||||
title: mapped_params,
|
title: mapped_params,
|
||||||
category: mapped_params,
|
category: mapped_params,
|
||||||
tags: mapped_params,
|
tags: mapped_params,
|
||||||
|
|
27
db/migrate/20200718014105_update_watch_categories_action.rb
Normale Datei
27
db/migrate/20200718014105_update_watch_categories_action.rb
Normale Datei
|
@ -0,0 +1,27 @@
|
||||||
|
class UpdateWatchCategoriesAction < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
watch_category_wizards = PluginStoreRow.where("
|
||||||
|
plugin_name = 'custom_wizard' AND
|
||||||
|
value::jsonb -> 'actions' @> '[{ \"type\" : \"watch_categories\" }]'::jsonb
|
||||||
|
")
|
||||||
|
|
||||||
|
if watch_category_wizards.exists?
|
||||||
|
watch_category_wizards.each do |row|
|
||||||
|
begin
|
||||||
|
wizard_json = JSON.parse(row.value)
|
||||||
|
rescue TypeError, JSON::ParserError
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
wizard_json['actions'].each do |a|
|
||||||
|
if a['type'] === "watch_categories" && a['wizard_user'] == nil
|
||||||
|
a['wizard_user'] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
row.value = wizard_json.to_json
|
||||||
|
row.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -143,17 +143,18 @@ class CustomWizard::Action
|
||||||
end
|
end
|
||||||
|
|
||||||
def watch_categories
|
def watch_categories
|
||||||
|
|
||||||
watched_categories = CustomWizard::Mapper.new(
|
watched_categories = CustomWizard::Mapper.new(
|
||||||
inputs: action['categories'],
|
inputs: action['categories'],
|
||||||
data: data,
|
data: data,
|
||||||
user: user
|
user: user
|
||||||
).perform
|
).perform
|
||||||
|
|
||||||
|
watched_categories = [*watched_categories].map(&:to_i)
|
||||||
|
|
||||||
notification_level = action['notification_level']
|
notification_level = action['notification_level']
|
||||||
|
|
||||||
if notification_level.blank?
|
if notification_level.blank?
|
||||||
log_error("Notifcation Level was not set! Exiting wizard action")
|
log_error("Notifcation Level was not set. Exiting wizard action")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -162,12 +163,52 @@ class CustomWizard::Action
|
||||||
data: data,
|
data: data,
|
||||||
user: user
|
user: user
|
||||||
).perform
|
).perform
|
||||||
|
|
||||||
|
users = []
|
||||||
|
|
||||||
|
if action['usernames']
|
||||||
|
mapped_users = CustomWizard::Mapper.new(
|
||||||
|
inputs: action['usernames'],
|
||||||
|
data: 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
|
||||||
|
|
||||||
Category.all.each do |category|
|
category_ids = Category.all.pluck(:id)
|
||||||
if watched_categories.present? && watched_categories.include?(category.id.to_s)
|
set_level = CategoryUser.notification_levels[notification_level.to_sym]
|
||||||
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[notification_level.to_sym], category.id)
|
mute_level = CategoryUser.notification_levels[:muted]
|
||||||
elsif mute_remainder
|
|
||||||
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id)
|
users.each do |user|
|
||||||
|
category_ids.each do |category_id|
|
||||||
|
new_level = nil
|
||||||
|
|
||||||
|
if watched_categories.include?(category_id) && set_level != nil
|
||||||
|
new_level = set_level
|
||||||
|
elsif mute_remainder
|
||||||
|
new_level = mute_level
|
||||||
|
end
|
||||||
|
|
||||||
|
if new_level
|
||||||
|
CategoryUser.set_notification_level_for_category(user, new_level, category_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if watched_categories.any?
|
||||||
|
log_success("#{user.username} notifications for #{watched_categories} set to #{set_level}")
|
||||||
|
end
|
||||||
|
|
||||||
|
if mute_remainder
|
||||||
|
log_success("#{user.username} notifications for all other categories muted")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren