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: {
|
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,20 @@ 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
|
||||||
|
|
||||||
|
unless watched_categories.is_a?(Array)
|
||||||
|
watched_categories = [watched_categories]
|
||||||
|
end
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
@ -163,11 +166,51 @@ class CustomWizard::Action
|
||||||
user: user
|
user: user
|
||||||
).perform
|
).perform
|
||||||
|
|
||||||
Category.all.each do |category|
|
users = []
|
||||||
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)
|
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_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
|
elsif mute_remainder
|
||||||
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id)
|
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