From cc528c5d8cf11d5ae90c5dc8225861f48a7876b0 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Wed, 17 May 2023 23:57:14 +0800 Subject: [PATCH] Add object to webhook --- object/record.go | 11 +++++++++-- web/src/WebhookEditPage.js | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/object/record.go b/object/record.go index aa10e9b8..e54fcb6d 100644 --- a/object/record.go +++ b/object/record.go @@ -47,7 +47,8 @@ type Record struct { RequestUri string `xorm:"varchar(1000)" json:"requestUri"` Action string `xorm:"varchar(1000)" json:"action"` - ExtendedUser *User `xorm:"-" json:"extendedUser"` + Object string `xorm:"-" json:"object"` + ExtendedUser *User `xorm:"-" json:"extendedUser"` IsTriggered bool `json:"isTriggered"` } @@ -60,6 +61,11 @@ func NewRecord(ctx *context.Context) *Record { requestUri = requestUri[0:1000] } + object := "" + if ctx.Input.RequestBody != nil && len(ctx.Input.RequestBody) != 0 { + object = string(ctx.Input.RequestBody) + } + record := Record{ Name: util.GenerateId(), CreatedTime: util.GetCurrentTime(), @@ -68,6 +74,7 @@ func NewRecord(ctx *context.Context) *Record { Method: ctx.Request.Method, RequestUri: requestUri, Action: action, + Object: object, IsTriggered: false, } return &record @@ -159,7 +166,7 @@ func SendWebhooks(record *Record) error { if matched { if webhook.IsUserExtended { - user := getUser(record.Organization, record.User) + user := GetMaskedUser(getUser(record.Organization, record.User)) record.ExtendedUser = user } diff --git a/web/src/WebhookEditPage.js b/web/src/WebhookEditPage.js index a23dee09..36b647d7 100644 --- a/web/src/WebhookEditPage.js +++ b/web/src/WebhookEditPage.js @@ -28,6 +28,20 @@ require("codemirror/mode/javascript/javascript"); const {Option} = Select; +const applicationTemplate = { + owner: "admin", // this.props.account.applicationName, + name: "application_123", + organization: "built-in", + createdTime: "2022-01-01T01:03:42+08:00", + displayName: "New Application - 123", + logo: `${Setting.StaticBaseUrl}/img/casdoor-logo_1185x256.png`, + enablePassword: true, + enableSignUp: true, + enableSigninSession: false, + enableCodeSignin: false, + enableSamlCompress: false, +}; + const previewTemplate = { "id": 9078, "owner": "built-in", @@ -37,9 +51,10 @@ const previewTemplate = { "clientIp": "159.89.126.192", "user": "admin", "method": "POST", - "requestUri": "/api/login", + "requestUri": "/api/add-application", "action": "login", "isTriggered": false, + "object": JSON.stringify(applicationTemplate), }; const userTemplate = { @@ -49,7 +64,7 @@ const userTemplate = { "updatedTime": "", "id": "9eb20f79-3bb5-4e74-99ac-39e3b9a171e8", "type": "normal-user", - "password": "123", + "password": "***", "passwordSalt": "", "displayName": "Admin", "avatar": "https://cdn.casbin.com/usercontent/admin/avatar/1596241359.png",