Skip to content

Commit

Permalink
FEATURE: Prevents assign notification & change status on solved
Browse files Browse the repository at this point in the history
Relates to this [topic](https://meta.discourse.org/t/assign-plugin-for-informatica/256974/94)

Add an event listener to `accepted_solution` event

Add `assigns_reminder_assigned_topics_query` modifier to not notify if
`prevent_assign_notification` setting is on.

Add settings to prevent assign notification and change status on solved
  • Loading branch information
Grubba27 committed Apr 23, 2024
1 parent a18ce6d commit c6f8794
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
31 changes: 31 additions & 0 deletions app/lib/plugin_initializer.rb
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module DiscourseSolved
class PluginInitializer
attr_reader :plugin

def initialize(plugin)
@plugin = plugin
end

def apply_plugin_api
# this method should be overridden by subclasses
raise NotImplementedError
end
end

class AssignsRemainderForTopicsQuery < PluginInitializer
def apply_plugin_api
plugin.register_modifier(:assigns_reminder_assigned_topics_query) do |query|
next query if !SiteSetting.prevent_assign_notification
query.where(
"topics.id NOT IN (
SELECT topic_id
FROM topic_custom_fields
WHERE name = 'accepted_answer_post_id'
)",
)
end
end
end
end
3 changes: 3 additions & 0 deletions config/locales/server.en.yml
Expand Up @@ -11,6 +11,9 @@ en:
solved_topics_auto_close_hours: "Auto close topic (n) hours after the last reply once the topic has been marked as solved. Set to 0 to disable auto closing."
show_filter_by_solved_status: "Show a dropdown to filter a topic list by solved status."
notify_on_staff_accept_solved: "Send notification to the topic creator when a post is marked as solution by a staff."
prevent_assign_notification: "Prevent notification from discourse-assign for solved topics."
assign_to_status_on_solved: "Enable assigning a status when a topic is solved. Requires discourse-assign plugin."
status_to_assign_on_solved: "The status to assign when a topic is solved."
disable_solved_education_message: "Disable education message for solved topics."
accept_solutions_topic_author: "Allow the topic author to accept a solution."
solved_add_schema_markup: "Add QAPage schema markup to HTML."
Expand Down
7 changes: 7 additions & 0 deletions config/settings.yml
Expand Up @@ -32,6 +32,13 @@ discourse_solved:
client: true
notify_on_staff_accept_solved:
default: false
prevent_assign_notification:
default: false
assign_to_status_on_solved:
default: false
status_to_assign_on_solved:
type: string
default: "Done"
disable_solved_education_message:
default: false
accept_solutions_topic_author:
Expand Down
9 changes: 9 additions & 0 deletions plugin.rb
Expand Up @@ -622,4 +622,13 @@ def self.skip_db?
end
end
end

if defined?(DiscourseAssign) && SiteSetting.assign_to_status_on_solved
on(:accepted_solution) do |post|
Assigner.new(post.topic, post.acting_user).assign(
post.acting_user,
status: SiteSetting.status_to_assign_on_solved,
)
end
end
end

0 comments on commit c6f8794

Please sign in to comment.