From 581e47055c0336dcab89595ef4a48dbcb2b796f9 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Mon, 20 Feb 2017 11:52:19 -0500 Subject: [PATCH] unassign can optionally not create a tracking topic --- config/locales/server.en.yml | 1 + config/settings.yml | 1 + plugin.rb | 39 +++++++++++++++++++----------------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 9137471..d13de81 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -3,6 +3,7 @@ en: 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_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" discourse_assign: assigned_to: "Topic assigned to @%{username}" unassigned: "Topic was unassigned" diff --git a/config/settings.yml b/config/settings.yml index 199d0ea..de7000f 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1,5 +1,6 @@ plugins: assigns_by_staff_mention: false + unassign_creates_tracking_post: true assigns_public: false assigns_user_url_path: client: true diff --git a/plugin.rb b/plugin.rb index 6c7ae80..78f1ad2 100644 --- a/plugin.rb +++ b/plugin.rb @@ -127,22 +127,13 @@ SQL true end - def unassign() - end - end - - class ::DiscourseAssign::AssignController < Admin::AdminController - before_filter :ensure_logged_in - def unassign - topic_id = params.require(:topic_id) - topic = Topic.find(topic_id.to_i) - if assigned_to_id = topic.custom_fields["assigned_to_id"] - topic.custom_fields["assigned_to_id"] = nil - topic.custom_fields["assigned_by_id"] = nil - topic.save! + if assigned_to_id = @topic.custom_fields["assigned_to_id"] + @topic.custom_fields["assigned_to_id"] = nil + @topic.custom_fields["assigned_by_id"] = nil + @topic.save! - post = topic.posts.where(post_number: 1).first + post = @topic.posts.where(post_number: 1).first post.publish_change_to_clients!(:revised, { reload_topic: true }) assigned_user = User.find_by(id: assigned_to_id) @@ -156,19 +147,31 @@ SQL Notification.where( notification_type: Notification.types[:custom], user_id: assigned_user.try(:id), - topic_id: topic.id, + topic_id: @topic.id, post_number: 1 ).where("data like '%discourse_assign.assign_notification%'") .destroy_all - - post_type = SiteSetting.assigns_public ? Post.types[:small_action] : Post.types[:whisper] - topic.add_moderator_post(current_user, + if SiteSetting.unassign_creates_tracking_post + post_type = SiteSetting.assigns_public ? Post.types[:small_action] : Post.types[:whisper] + @topic.add_moderator_post(@assigned_by, I18n.t('discourse_assign.unassigned'), { bump: false, post_type: post_type, action_code: "assigned"}) + end end + end + end + + class ::DiscourseAssign::AssignController < Admin::AdminController + before_filter :ensure_logged_in + + def unassign + topic_id = params.require(:topic_id) + topic = Topic.find(topic_id.to_i) + assigner = TopicAssigner.new(topic, current_user) + assigner.unassign render json: success_json end