mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:16:41 +08:00
FEATURE: Webhook for user destroyed event (#6124)
This commit is contained in:
parent
caa669cf29
commit
84ab825e41
|
@ -115,6 +115,7 @@ class User < ActiveRecord::Base
|
|||
after_save :expire_old_email_tokens
|
||||
after_save :index_search
|
||||
after_commit :trigger_user_created_event, on: :create
|
||||
after_commit :trigger_user_destroyed_event, on: :destroy
|
||||
|
||||
before_destroy do
|
||||
# These tables don't have primary keys, so destroying them with activerecord is tricky:
|
||||
|
@ -1270,6 +1271,11 @@ class User < ActiveRecord::Base
|
|||
true
|
||||
end
|
||||
|
||||
def trigger_user_destroyed_event
|
||||
DiscourseEvent.trigger(:user_destroyed, self)
|
||||
true
|
||||
end
|
||||
|
||||
def set_skip_validate_email
|
||||
if self.primary_email
|
||||
self.primary_email.skip_validate_email = !should_validate_email_address?
|
||||
|
|
|
@ -41,6 +41,7 @@ end
|
|||
user_logged_in
|
||||
user_approved
|
||||
user_updated
|
||||
user_destroyed
|
||||
).each do |event|
|
||||
DiscourseEvent.on(event) do |user|
|
||||
WebHook.enqueue_object_hooks(:user, user, event)
|
||||
|
|
|
@ -291,6 +291,13 @@ describe WebHook do
|
|||
expect(job_args["event_name"]).to eq("user_logged_in")
|
||||
payload = JSON.parse(job_args["payload"])
|
||||
expect(payload["id"]).to eq(user.id)
|
||||
|
||||
UserDestroyer.new(Discourse.system_user).destroy(user)
|
||||
job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first
|
||||
|
||||
expect(job_args["event_name"]).to eq("user_destroyed")
|
||||
payload = JSON.parse(job_args["payload"])
|
||||
expect(payload["id"]).to eq(user.id)
|
||||
end
|
||||
|
||||
it 'should enqueue the right hooks for category events' do
|
||||
|
|
|
@ -55,6 +55,13 @@ describe UserDestroyer do
|
|||
UserDestroyer.new(@admin).destroy(@user, destroy_opts.merge(quiet: true))
|
||||
}.to_not change { UserHistory.where(action: UserHistory.actions[:delete_user]).count }
|
||||
end
|
||||
|
||||
it 'triggers a extensibility event' do
|
||||
event = DiscourseEvent.track_events { destroy }.last
|
||||
|
||||
expect(event[:event_name]).to eq(:user_destroyed)
|
||||
expect(event[:params].first).to eq(@user)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples "email block list" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user