From 33e6dadfc3d127fca4713fe20f573a63c2d591f4 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Tue, 15 Aug 2023 12:24:20 +1000 Subject: [PATCH 1/4] FIX: translations for granular webhooks After those core changes we need additional translations https://github.com/discourse/discourse/pull/23070 --- config/locales/client.en.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index f5af30a5..54e1480d 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -47,9 +47,10 @@ en: admin: web_hooks: - solved_event: - name: "Solved Event" - details: "When a user marks a post as the accepted or unaccepted answer." + groups: + solved: "Solved Event" + event_details: + solved_accept_unaccept: "When an user marks a post as the accepted or unaccepted answer" api: scopes: descriptions: From 4afcd4568942e3d89a43f627f95732850d408924 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Tue, 15 Aug 2023 14:23:31 +1000 Subject: [PATCH 2/4] FIX: granular event --- config/locales/client.en.yml | 3 ++- plugin.rb | 8 ++++---- spec/fabricators/solved_hook_fabricator.rb | 7 +++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 54e1480d..7bdb01f3 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -50,7 +50,8 @@ en: groups: solved: "Solved Event" event_details: - solved_accept_unaccept: "When an user marks a post as the accepted or unaccepted answer" + 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..7dd9445e 100644 --- a/spec/fabricators/solved_hook_fabricator.rb +++ b/spec/fabricators/solved_hook_fabricator.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true Fabricator(:solved_web_hook, from: :web_hook) do - transient solved_hook: WebHookEventType.find_by(name: "solved") + transient solved_hook: WebHookEventType.find_by(name: "accepted_solution"), + unsolved_hook: WebHookEventType.find_by(name: "unaccepted_solution") - after_build { |web_hook, transients| web_hook.web_hook_event_types = [transients[:solved_hook]] } + after_build do |web_hook, transients| + web_hook.web_hook_event_types = [transients[:solved_hook], transients[:unsolved_hook]] + end end From c81585fba0aede20bab22105a3ff0bc171d79633 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Tue, 26 Sep 2023 11:36:11 +1000 Subject: [PATCH 3/4] FIX: update after changes --- config/locales/client.en.yml | 5 ++--- spec/fabricators/solved_hook_fabricator.rb | 8 +++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 7bdb01f3..789d0ccb 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -47,9 +47,8 @@ en: admin: web_hooks: - groups: - solved: "Solved Event" - event_details: + solved_event: + 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: diff --git a/spec/fabricators/solved_hook_fabricator.rb b/spec/fabricators/solved_hook_fabricator.rb index 7dd9445e..f80469a9 100644 --- a/spec/fabricators/solved_hook_fabricator.rb +++ b/spec/fabricators/solved_hook_fabricator.rb @@ -1,10 +1,8 @@ # frozen_string_literal: true Fabricator(:solved_web_hook, from: :web_hook) do - transient solved_hook: WebHookEventType.find_by(name: "accepted_solution"), - unsolved_hook: WebHookEventType.find_by(name: "unaccepted_solution") - - after_build do |web_hook, transients| - web_hook.web_hook_event_types = [transients[:solved_hook], transients[:unsolved_hook]] + after_build do |web_hook| + web_hook.web_hook_event_types = + WebHookEventType.where(name: %w[accepted_solution unaccepted_solution]) end end From c5ff1b389700152d751d7c8c9e0a242bb4bad240 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Fri, 6 Oct 2023 12:12:01 +1100 Subject: [PATCH 4/4] FIX: discourse compatibility --- .discourse-compatibility | 1 + 1 file changed, 1 insertion(+) diff --git a/.discourse-compatibility b/.discourse-compatibility index 09f1198e..b75e7c6d 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,3 +1,4 @@ +< 3.2.0.beta2-dev: 9fbf43e2f077e86f0a1ff769af6036d4e78bfff1 3.1.0.beta1: 62fe282c756ac7de43a22a09b0d675882a507743 2.9.0.beta11: 882dd61e11f9bab8e99510296938b0cdbc3269c4 2.9.0.beta1: e6cce5486df906ede74aa1b17ab308a145a99b88