FEATURE: unassign on close and unassign on group archive settings
FIX: don't backfill assignment on closed or deleted topics
This commit is contained in:
parent
2827e3b0b0
commit
7f23e4f83c
|
@ -1,11 +1,13 @@
|
|||
en:
|
||||
site_settings:
|
||||
assigns_public: "Allow general public to see topic assignments"
|
||||
assigns_user_url_path: "Path to link all user links for assigned (use: {username} to subtitue username)"
|
||||
assigns_user_url_path: "Assigned users link to the following path (use: {username} to subtitue username)"
|
||||
assigns_by_staff_mention: "If a staff member mentions another staff member, topic is automatically assigned"
|
||||
unassign_creates_tracking_post: "If you unassign a topic a whisper or small action will be created to track change"
|
||||
assign_self_regex: "Regex that needs to pass for self assign. Example 'my list'"
|
||||
assign_other_regex: "Regex that needs to pass for assigning topics to others via mention. Example 'your list'."
|
||||
unassign_on_group_archive: "When a message is archived by a group, unassign message"
|
||||
unassign_on_close: "When a topic is closed unassign topic"
|
||||
discourse_assign:
|
||||
assigned_to: "Topic assigned to @%{username}"
|
||||
unassigned: "Topic was unassigned"
|
||||
|
|
|
@ -4,6 +4,8 @@ plugins:
|
|||
assigns_public: false
|
||||
assign_self_regex: ""
|
||||
assign_other_regex: ""
|
||||
unassign_on_close: false
|
||||
unassign_on_group_archive: false
|
||||
assigns_user_url_path:
|
||||
client: true
|
||||
default: "/latest?assigned={username}"
|
||||
|
|
21
plugin.rb
21
plugin.rb
|
@ -25,9 +25,10 @@ after_initialize do
|
|||
sql = <<SQL
|
||||
SELECT p.topic_id, MAX(post_number) post_number
|
||||
FROM posts p
|
||||
JOIN topics t ON t.id = p.topic_id
|
||||
LEFT JOIN topic_custom_fields tc ON tc.name = 'assigned_to_id' AND tc.topic_id = p.topic_id
|
||||
WHERE p.user_id IN (SELECT id FROM users WHERE moderator OR admin) AND
|
||||
( #{staff_mention} ) AND tc.value IS NULL
|
||||
( #{staff_mention} ) AND tc.value IS NULL AND NOT t.closed AND t.deleted_at IS NULL
|
||||
GROUP BY p.topic_id
|
||||
SQL
|
||||
|
||||
|
@ -60,6 +61,12 @@ SQL
|
|||
end
|
||||
|
||||
def self.auto_assign(post, force: false)
|
||||
|
||||
if SiteSetting.unassign_on_close && post.topic && post.topic.closed
|
||||
assigner = new(post.topic, Discourse.system_user)
|
||||
assigner.unassign(silent: true)
|
||||
end
|
||||
|
||||
return unless SiteSetting.assigns_by_staff_mention
|
||||
|
||||
if post.user && post.topic && post.user.staff?
|
||||
|
@ -149,7 +156,7 @@ SQL
|
|||
true
|
||||
end
|
||||
|
||||
def unassign
|
||||
def unassign(silent: false)
|
||||
if assigned_to_id = @topic.custom_fields["assigned_to_id"]
|
||||
@topic.custom_fields["assigned_to_id"] = nil
|
||||
@topic.custom_fields["assigned_by_id"] = nil
|
||||
|
@ -174,7 +181,7 @@ SQL
|
|||
).where("data like '%discourse_assign.assign_notification%'")
|
||||
.destroy_all
|
||||
|
||||
if SiteSetting.unassign_creates_tracking_post
|
||||
if SiteSetting.unassign_creates_tracking_post && !silent
|
||||
post_type = SiteSetting.assigns_public ? Post.types[:small_action] : Post.types[:whisper]
|
||||
@topic.add_moderator_post(@assigned_by,
|
||||
I18n.t('discourse_assign.unassigned'),
|
||||
|
@ -341,4 +348,12 @@ SQL
|
|||
::TopicAssigner.auto_assign(post, force: true)
|
||||
end
|
||||
|
||||
on(:archive_message) do |info|
|
||||
if SiteSetting.unassign_on_group_archive && info[:group]
|
||||
assigner = TopicAssigner.new(info[:topic], Discourse.system_user)
|
||||
# not forcing silent cause archive leaves no trace
|
||||
assigner.unassign
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue