diff --git a/.discourse-compatibility b/.discourse-compatibility index 383d9d77..d02f073c 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,3 +1,4 @@ +< 3.2.0.beta2-dev: 9fbf43e2f077e86f0a1ff769af6036d4e78bfff1 3.1.999: b5d487d6a5bfe2571d936eec5911d02a5f3fcc32 3.1.0.beta1: 62fe282c756ac7de43a22a09b0d675882a507743 2.9.0.beta11: 882dd61e11f9bab8e99510296938b0cdbc3269c4 diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index f5af30a5..789d0ccb 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -48,8 +48,9 @@ en: admin: web_hooks: solved_event: - name: "Solved Event" - details: "When a user marks a post as the accepted or unaccepted answer." + group_name: "Solved Event" + accepted_solution: "When an user marks a post as the accepted answer" + unaccepted_solution: "When an user marks a post as the unaccepted answer" api: scopes: descriptions: diff --git a/plugin.rb b/plugin.rb index 09410d50..3e37002b 100644 --- a/plugin.rb +++ b/plugin.rb @@ -160,7 +160,7 @@ def self.accept_answer!(post, acting_user, topic: nil) topic.save! post.save! - if WebHook.active_web_hooks(:solved).exists? + if WebHook.active_web_hooks(:accepted_solution).exists? payload = WebHook.generate_payload(:post, post) WebHook.enqueue_solved_hooks(:accepted_solution, post, payload) end @@ -201,7 +201,7 @@ def self.unaccept_answer!(post, topic: nil) notification.destroy! if notification - if WebHook.active_web_hooks(:solved).exists? + if WebHook.active_web_hooks(:unaccepted_solution).exists? payload = WebHook.generate_payload(:post, post) WebHook.enqueue_solved_hooks(:unaccepted_solution, post, payload) end @@ -420,7 +420,7 @@ def solved_count class ::WebHook def self.enqueue_solved_hooks(event, post, payload = nil) - if active_web_hooks("solved").exists? && post.present? + if active_web_hooks(event).exists? && post.present? payload ||= WebHook.generate_payload(:post, post) WebHook.enqueue_hooks( @@ -605,7 +605,7 @@ def topic_accepted_answer WHERE tc.name = '#{::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD}' AND tc.value IS NOT NULL ) AND topics.id IN ( - SELECT top.id + SELECT top.id FROM topics top INNER JOIN category_custom_fields cc ON top.category_id = cc.category_id diff --git a/spec/fabricators/solved_hook_fabricator.rb b/spec/fabricators/solved_hook_fabricator.rb index fb768447..f80469a9 100644 --- a/spec/fabricators/solved_hook_fabricator.rb +++ b/spec/fabricators/solved_hook_fabricator.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true Fabricator(:solved_web_hook, from: :web_hook) do - transient solved_hook: WebHookEventType.find_by(name: "solved") - - after_build { |web_hook, transients| web_hook.web_hook_event_types = [transients[:solved_hook]] } + after_build do |web_hook| + web_hook.web_hook_event_types = + WebHookEventType.where(name: %w[accepted_solution unaccepted_solution]) + end end