FEATURE: Add webhooks for user suspend and unsuspend (#23684)
This commit is contained in:
parent
a2da2e02e7
commit
da313ba49b
|
@ -43,6 +43,10 @@ end
|
|||
DiscourseEvent.on(event) { |user| WebHook.enqueue_object_hooks(:user, user, event) }
|
||||
end
|
||||
|
||||
%i[user_suspended user_unsuspended].each do |event|
|
||||
DiscourseEvent.on(event) { |args| WebHook.enqueue_object_hooks(:user, args[:user], event) }
|
||||
end
|
||||
|
||||
%i[group_created group_updated].each do |event|
|
||||
DiscourseEvent.on(event) { |group| WebHook.enqueue_object_hooks(:group, group, event) }
|
||||
end
|
||||
|
|
|
@ -4939,7 +4939,7 @@ en:
|
|||
details: "When there is a new reply, edit, deleted or recovered."
|
||||
user_event:
|
||||
name: "User Event"
|
||||
details: "When a user logs in, logs out, confirms their email, is created, approved or updated."
|
||||
details: "When a user logs in, logs out, confirms their email, is created, approved, updated, suspended or unsuspended."
|
||||
group_event:
|
||||
name: "Group Event"
|
||||
details: "When a group is created, updated or destroyed."
|
||||
|
|
|
@ -311,6 +311,29 @@ RSpec.describe Admin::UsersController do
|
|||
)
|
||||
end
|
||||
|
||||
context "with webhook" do
|
||||
fab!(:user_web_hook) { Fabricate(:user_web_hook) }
|
||||
|
||||
it "enqueues a user_suspended webhook event" do
|
||||
expect do
|
||||
put "/admin/users/#{user.id}/suspend.json",
|
||||
params: {
|
||||
suspend_until: 5.hours.from_now,
|
||||
reason: "because I said so",
|
||||
}
|
||||
end.to change { Jobs::EmitWebHookEvent.jobs.size }.by(2)
|
||||
|
||||
user.reload
|
||||
job_args =
|
||||
Jobs::EmitWebHookEvent.jobs.last["args"].find do |args|
|
||||
args["event_name"] == "user_suspended"
|
||||
end
|
||||
expect(job_args).to be_present
|
||||
expect(job_args["id"]).to eq(user.id)
|
||||
expect(job_args["payload"]).to eq(WebHook.generate_payload(:user, user))
|
||||
end
|
||||
end
|
||||
|
||||
it "requires suspend_until and reason" do
|
||||
expect(user).not_to be_suspended
|
||||
put "/admin/users/#{user.id}/suspend.json", params: {}
|
||||
|
@ -496,6 +519,29 @@ RSpec.describe Admin::UsersController do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#unsuspend" do
|
||||
context "when logged in as an admin" do
|
||||
before { sign_in(admin) }
|
||||
|
||||
context "with webhook" do
|
||||
fab!(:user_web_hook) { Fabricate(:user_web_hook) }
|
||||
|
||||
it "enqueues a user_unsuspended webhook event" do
|
||||
user.update!(suspended_at: DateTime.now, suspended_till: 2.years.from_now)
|
||||
|
||||
expect do put "/admin/users/#{user.id}/unsuspend.json" end.to change {
|
||||
Jobs::EmitWebHookEvent.jobs.size
|
||||
}.by(1)
|
||||
|
||||
user.reload
|
||||
job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first
|
||||
expect(job_args["id"]).to eq(user.id)
|
||||
expect(job_args["payload"]).to eq(WebHook.generate_payload(:user, user))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#revoke_admin" do
|
||||
fab!(:another_admin) { Fabricate(:admin) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue