FEATURE: Trigger user webhook when a user logs in/out.

https://meta.discourse.org/t/how-do-you-learn-how-to-build-these-plugins/57946/10?u=tgxworld
This commit is contained in:
Guo Xiang Tan 2017-12-20 17:47:30 +08:00
parent 6e0b2a9f37
commit 6c4ee9d5b5
3 changed files with 20 additions and 2 deletions

View File

@ -22,7 +22,13 @@ DiscourseEvent.on(:post_edited) do |post, topic_changed|
WebHook.enqueue_topic_hooks(:topic_edited, post.topic) if post.is_first_post? && topic_changed
end
%i(user_created user_approved user_updated).each do |event|
%i(
user_logged_out
user_created
user_logged_in
user_approved
user_updated
).each do |event|
DiscourseEvent.on(event) do |user|
WebHook.enqueue_hooks(:user, user_id: user.id, event_name: event.to_s)
end

View File

@ -2813,7 +2813,7 @@ en:
details: "When there is a new reply, edit, deleted or recovered."
user_event:
name: "User Event"
details: "When a user is created, approved or updated."
details: "When a user logs in, logs out, is created, approved or updated."
delivery_status:
title: "Delivery Status"
inactive: "Inactive"

View File

@ -207,6 +207,18 @@ describe WebHook do
expect(job_args["event_name"]).to eq("user_updated")
expect(job_args["user_id"]).to eq(user.id)
user.logged_out
job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first
expect(job_args["event_name"]).to eq("user_logged_out")
expect(job_args["user_id"]).to eq(user.id)
user.logged_in
job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first
expect(job_args["event_name"]).to eq("user_logged_in")
expect(job_args["user_id"]).to eq(user.id)
end
end
end