diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb index 9b729bdf8d4..0d6ecb6d662 100644 --- a/app/models/reviewable.rb +++ b/app/models/reviewable.rb @@ -213,6 +213,8 @@ class Reviewable < ActiveRecord::Base update(score: self.score + rs.score, latest_score: rs.created_at, force_review: force_review) topic.update(reviewable_score: topic.reviewable_score + rs.score) if topic + DiscourseEvent.trigger(:reviewable_score_updated, self) + rs end @@ -625,6 +627,10 @@ protected ) self.score = result[0].score + + DiscourseEvent.trigger(:reviewable_score_updated, self) + + self.score end def increment_version!(version = nil) diff --git a/config/initializers/012-web_hook_events.rb b/config/initializers/012-web_hook_events.rb index e7620933332..4bf6c2afc18 100644 --- a/config/initializers/012-web_hook_events.rb +++ b/config/initializers/012-web_hook_events.rb @@ -85,8 +85,13 @@ end end end -DiscourseEvent.on(:reviewable_created) do |reviewable| - WebHook.enqueue_object_hooks(:reviewable, reviewable, :reviewable_created, reviewable.serializer) +%i( + reviewable_created + reviewable_score_updated +).each do |event| + DiscourseEvent.on(event) do |reviewable| + WebHook.enqueue_object_hooks(:reviewable, reviewable, event, reviewable.serializer) + end end DiscourseEvent.on(:reviewable_transitioned_to) do |status, reviewable| diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rb index f6b873aaee8..03c665acc2f 100644 --- a/spec/models/web_hook_spec.rb +++ b/spec/models/web_hook_spec.rb @@ -494,6 +494,17 @@ describe WebHook do payload = JSON.parse(job_args["payload"]) expect(payload["id"]).to eq(reviewable.id) + reviewable.add_score( + Discourse.system_user, + ReviewableScore.types[:off_topic], + reason: "test" + ) + job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first + + expect(job_args["event_name"]).to eq("reviewable_score_updated") + payload = JSON.parse(job_args["payload"]) + expect(payload["id"]).to eq(reviewable.id) + reviewable.perform(Discourse.system_user, :reject_user_delete) job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first