Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-28 11:50:28 +01:00
Add watch category users and migration
Dieser Commit ist enthalten in:
Ursprung
290bacc4bd
Commit
36c0281b2f
6 geänderte Dateien mit 113 neuen und 8 gelöschten Zeilen
|
@ -144,7 +144,9 @@ const action = {
|
|||
watch_categories: {
|
||||
categories: null,
|
||||
notification_level: null,
|
||||
mute_remainder: null
|
||||
mute_remainder: null,
|
||||
wizard_user: true,
|
||||
usernames: null
|
||||
},
|
||||
send_to_api: {
|
||||
api: null,
|
||||
|
|
|
@ -297,6 +297,7 @@
|
|||
options=(hash
|
||||
textSelection='key,value'
|
||||
wizardFieldSelection=true
|
||||
wizardActionSelection=true
|
||||
userFieldSelection='key,value'
|
||||
categorySelection='output'
|
||||
context='action'
|
||||
|
@ -338,6 +339,35 @@
|
|||
)}}
|
||||
</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 createGroup}}
|
||||
|
|
|
@ -223,6 +223,8 @@ en:
|
|||
watching_first_post: "Watching First Post"
|
||||
muted: "Muted"
|
||||
select_a_notification_level: "Select level"
|
||||
wizard_user: "Wizard User"
|
||||
usernames: "Users"
|
||||
post_builder:
|
||||
checkbox: "Post Builder"
|
||||
label: "Builder"
|
||||
|
|
|
@ -120,6 +120,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
|
|||
:api,
|
||||
:api_endpoint,
|
||||
:api_body,
|
||||
:wizard_user,
|
||||
title: mapped_params,
|
||||
category: 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,20 @@ class CustomWizard::Action
|
|||
end
|
||||
|
||||
def watch_categories
|
||||
|
||||
watched_categories = CustomWizard::Mapper.new(
|
||||
inputs: action['categories'],
|
||||
data: data,
|
||||
user: user
|
||||
).perform
|
||||
|
||||
unless watched_categories.is_a?(Array)
|
||||
watched_categories = [watched_categories]
|
||||
end
|
||||
|
||||
notification_level = action['notification_level']
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -162,12 +165,52 @@ class CustomWizard::Action
|
|||
data: data,
|
||||
user: user
|
||||
).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|
|
||||
if watched_categories.present? && watched_categories.include?(category.id.to_s)
|
||||
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[notification_level.to_sym], category.id)
|
||||
elsif mute_remainder
|
||||
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id)
|
||||
category_ids = Category.all.pluck(:id)
|
||||
set_level = CategoryUser.notification_levels[notification_level.to_sym]
|
||||
mute_level = CategoryUser.notification_levels[:muted]
|
||||
|
||||
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
|
||||
|
|
Laden …
In neuem Issue referenzieren