mirror of
https://github.com/discourse/discourse.git
synced 2025-02-28 05:34:09 +08:00
UX: show if webhook is disabled (#7217)
+ show in staff logs when webhook is created/updated/destroyed
This commit is contained in:
parent
bfcbc4d2d6
commit
34730a0b16
@ -4,8 +4,8 @@ import { bufferedRender } from "discourse-common/lib/buffered-render";
|
|||||||
|
|
||||||
export default Ember.Component.extend(
|
export default Ember.Component.extend(
|
||||||
bufferedRender({
|
bufferedRender({
|
||||||
classes: ["text-muted", "text-danger", "text-successful"],
|
classes: ["text-muted", "text-danger", "text-successful", "text-muted"],
|
||||||
icons: ["circle-o", "times-circle", "circle"],
|
icons: ["circle-o", "times-circle", "circle", "circle"],
|
||||||
|
|
||||||
@computed("deliveryStatuses", "model.last_delivery_status")
|
@computed("deliveryStatuses", "model.last_delivery_status")
|
||||||
status(deliveryStatuses, lastDeliveryStatus) {
|
status(deliveryStatuses, lastDeliveryStatus) {
|
||||||
|
@ -34,6 +34,7 @@ class Admin::WebHooksController < Admin::AdminController
|
|||||||
web_hook = WebHook.new(web_hook_params)
|
web_hook = WebHook.new(web_hook_params)
|
||||||
|
|
||||||
if web_hook.save
|
if web_hook.save
|
||||||
|
StaffActionLogger.new(current_user).log_web_hook(web_hook, UserHistory.actions[:web_hook_create])
|
||||||
render_serialized(web_hook, AdminWebHookSerializer, root: 'web_hook')
|
render_serialized(web_hook, AdminWebHookSerializer, root: 'web_hook')
|
||||||
else
|
else
|
||||||
render_json_error web_hook.errors.full_messages
|
render_json_error web_hook.errors.full_messages
|
||||||
@ -42,6 +43,7 @@ class Admin::WebHooksController < Admin::AdminController
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
if @web_hook.update_attributes(web_hook_params)
|
if @web_hook.update_attributes(web_hook_params)
|
||||||
|
StaffActionLogger.new(current_user).log_web_hook(@web_hook, UserHistory.actions[:web_hook_update], changes: @web_hook.saved_changes)
|
||||||
render_serialized(@web_hook, AdminWebHookSerializer, root: 'web_hook')
|
render_serialized(@web_hook, AdminWebHookSerializer, root: 'web_hook')
|
||||||
else
|
else
|
||||||
render_json_error @web_hook.errors.full_messages
|
render_json_error @web_hook.errors.full_messages
|
||||||
@ -50,6 +52,7 @@ class Admin::WebHooksController < Admin::AdminController
|
|||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@web_hook.destroy!
|
@web_hook.destroy!
|
||||||
|
StaffActionLogger.new(current_user).log_web_hook(@web_hook, UserHistory.actions[:web_hook_destroy])
|
||||||
render json: success_json
|
render json: success_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -85,7 +85,10 @@ class UserHistory < ActiveRecord::Base
|
|||||||
entity_export: 66,
|
entity_export: 66,
|
||||||
change_password: 67,
|
change_password: 67,
|
||||||
topic_timestamps_changed: 68,
|
topic_timestamps_changed: 68,
|
||||||
approve_user: 69
|
approve_user: 69,
|
||||||
|
web_hook_create: 70,
|
||||||
|
web_hook_update: 71,
|
||||||
|
web_hook_destroy: 72
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -149,7 +152,10 @@ class UserHistory < ActiveRecord::Base
|
|||||||
:entity_export,
|
:entity_export,
|
||||||
:change_name,
|
:change_name,
|
||||||
:topic_timestamps_changed,
|
:topic_timestamps_changed,
|
||||||
:approve_user
|
:approve_user,
|
||||||
|
:web_hook_create,
|
||||||
|
:web_hook_update,
|
||||||
|
:web_hook_destroy
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ class WebHook < ActiveRecord::Base
|
|||||||
def self.last_delivery_statuses
|
def self.last_delivery_statuses
|
||||||
@last_delivery_statuses ||= Enum.new(inactive: 1,
|
@last_delivery_statuses ||= Enum.new(inactive: 1,
|
||||||
failed: 2,
|
failed: 2,
|
||||||
successful: 3)
|
successful: 3,
|
||||||
|
disabled: 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.default_event_types
|
def self.default_event_types
|
||||||
|
@ -16,4 +16,8 @@ class AdminWebHookSerializer < ApplicationSerializer
|
|||||||
def web_hook_event_types
|
def web_hook_event_types
|
||||||
ActiveModel::ArraySerializer.new(object.web_hook_event_types).as_json
|
ActiveModel::ArraySerializer.new(object.web_hook_event_types).as_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def last_delivery_status
|
||||||
|
object.active ? object.last_delivery_status : WebHook.last_delivery_statuses[:disabled]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -583,6 +583,30 @@ class StaffActionLogger
|
|||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log_web_hook(web_hook, action, opts = {})
|
||||||
|
details = [
|
||||||
|
"webhook_id: #{web_hook.id}",
|
||||||
|
"payload_url: #{web_hook.payload_url}"
|
||||||
|
]
|
||||||
|
|
||||||
|
if changes = opts[:changes]
|
||||||
|
changes.reject! { |k, v| k == "updated_at" }
|
||||||
|
old_values = []
|
||||||
|
new_values = []
|
||||||
|
changes.each do |k, v|
|
||||||
|
old_values << "#{k}: #{v[0]}"
|
||||||
|
new_values << "#{k}: #{v[1]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
UserHistory.create!(params(opts).merge(
|
||||||
|
action: action,
|
||||||
|
context: details.join(", "),
|
||||||
|
previous_value: old_values&.join(", "),
|
||||||
|
new_value: new_values&.join(", ")
|
||||||
|
))
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def params(opts = nil)
|
def params(opts = nil)
|
||||||
|
@ -3213,6 +3213,7 @@ en:
|
|||||||
inactive: "Inactive"
|
inactive: "Inactive"
|
||||||
failed: "Failed"
|
failed: "Failed"
|
||||||
successful: "Successful"
|
successful: "Successful"
|
||||||
|
disabled: "Disabled"
|
||||||
events:
|
events:
|
||||||
none: "There are no related events."
|
none: "There are no related events."
|
||||||
redeliver: "Redeliver"
|
redeliver: "Redeliver"
|
||||||
@ -3702,6 +3703,9 @@ en:
|
|||||||
change_name: "change name"
|
change_name: "change name"
|
||||||
topic_timestamps_changed: "topic timestamps changed"
|
topic_timestamps_changed: "topic timestamps changed"
|
||||||
approve_user: "approved user"
|
approve_user: "approved user"
|
||||||
|
web_hook_create: "webhook create"
|
||||||
|
web_hook_update: "webhook update"
|
||||||
|
web_hook_destroy: "webhook destroy"
|
||||||
screened_emails:
|
screened_emails:
|
||||||
title: "Screened Emails"
|
title: "Screened Emails"
|
||||||
description: "When someone tries to create a new account, the following email addresses will be checked and the registration will be blocked, or some other action performed."
|
description: "When someone tries to create a new account, the following email addresses will be checked and the registration will be blocked, or some other action performed."
|
||||||
|
@ -4349,3 +4349,6 @@ en:
|
|||||||
unknown: "unknown"
|
unknown: "unknown"
|
||||||
user_merged: "%{username} was merged into this account"
|
user_merged: "%{username} was merged into this account"
|
||||||
user_delete_self: "Deleted by self from %{url}"
|
user_delete_self: "Deleted by self from %{url}"
|
||||||
|
update: "Updated"
|
||||||
|
create: "Created"
|
||||||
|
destroy: "Destroyed"
|
||||||
|
@ -34,6 +34,7 @@ describe Admin::WebHooksController do
|
|||||||
|
|
||||||
json = ::JSON.parse(response.body)
|
json = ::JSON.parse(response.body)
|
||||||
expect(json["web_hook"]["payload_url"]).to eq("https://meta.discourse.org/")
|
expect(json["web_hook"]["payload_url"]).to eq("https://meta.discourse.org/")
|
||||||
|
expect(UserHistory.where(acting_user_id: admin.id, action: UserHistory.actions[:web_hook_create]).count).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns error when field is not filled correctly' do
|
it 'returns error when field is not filled correctly' do
|
||||||
@ -57,6 +58,30 @@ describe Admin::WebHooksController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#update' do
|
||||||
|
it "logs webhook update" do
|
||||||
|
put "/admin/api/web_hooks/#{web_hook.id}.json", params: {
|
||||||
|
web_hook: { active: false, payload_url: "https://test.com" }
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(UserHistory.where(acting_user_id: admin.id,
|
||||||
|
action: UserHistory.actions[:web_hook_update],
|
||||||
|
new_value: "payload_url: https://test.com, active: false").exists?).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#destroy' do
|
||||||
|
it "logs webhook destroy" do
|
||||||
|
delete "/admin/api/web_hooks/#{web_hook.id}.json", params: {
|
||||||
|
web_hook: { active: false, payload_url: "https://test.com" }
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(UserHistory.where(acting_user_id: admin.id, action: UserHistory.actions[:web_hook_destroy]).exists?).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#ping' do
|
describe '#ping' do
|
||||||
it 'enqueues the ping event' do
|
it 'enqueues the ping event' do
|
||||||
expect do
|
expect do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user