FEATURE: reassign on "move to inbox"

This commit is contained in:
Sam 2017-02-28 10:33:03 -05:00
parent 7f23e4f83c
commit 23aa28e2b4
2 changed files with 23 additions and 4 deletions

View File

@ -6,7 +6,7 @@ en:
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_group_archive: "When a message is archived by a group, unassign message (reassign if moved back to inbox)"
unassign_on_close: "When a topic is closed unassign topic"
discourse_assign:
assigned_to: "Topic assigned to @%{username}"

View File

@ -348,11 +348,30 @@ SQL
::TopicAssigner.auto_assign(post, force: true)
end
on(:move_to_inbox) do |info|
if SiteSetting.unassign_on_group_archive && info[:group]
if topic = info[:topic]
if user_id = topic.custom_fields["prev_assigned_to_id"]
if user = User.find_by(id: user_id.to_i)
assigner = TopicAssigner.new(topic, Discourse.system_user)
assigner.assign(user, silent: true)
end
end
end
end
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
topic = info[:topic]
if user_id = topic.custom_fields["assigned_to_id"]
if user = User.find_by(id: user_id.to_i)
topic.custom_fields["prev_assigned_to_id"] = user.id
topic.save
assigner = TopicAssigner.new(topic, Discourse.system_user)
assigner.unassign(silent: true)
end
end
end
end