From 9943e3c3164c6c204928093fca59c3408f566c8a Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sun, 26 Dec 2021 21:02:56 +0800 Subject: [PATCH] Add isEnabled to webhook. --- object/record.go | 4 ++++ object/webhook.go | 1 + web/src/SyncerEditPage.js | 2 +- web/src/SyncerListPage.js | 2 +- web/src/WebhookEditPage.js | 12 +++++++++++- web/src/WebhookListPage.js | 15 ++++++++++++++- web/src/locales/de/data.json | 12 +++++++++--- web/src/locales/en/data.json | 12 +++++++++--- web/src/locales/fr/data.json | 12 +++++++++--- web/src/locales/ja/data.json | 12 +++++++++--- web/src/locales/ko/data.json | 12 +++++++++--- web/src/locales/ru/data.json | 12 +++++++++--- web/src/locales/zh/data.json | 12 +++++++++--- 13 files changed, 95 insertions(+), 25 deletions(-) diff --git a/object/record.go b/object/record.go index 35750d6e..ce3e3b8d 100644 --- a/object/record.go +++ b/object/record.go @@ -146,6 +146,10 @@ func GetRecordsByField(record *Record) []*Record { func SendWebhooks(record *Record) error { webhooks := getWebhooksByOrganization(record.Organization) for _, webhook := range webhooks { + if !webhook.IsEnabled { + continue + } + matched := false for _, event := range webhook.Events { if record.Action == event { diff --git a/object/webhook.go b/object/webhook.go index ce1fb1f1..1053c2e3 100644 --- a/object/webhook.go +++ b/object/webhook.go @@ -38,6 +38,7 @@ type Webhook struct { ContentType string `xorm:"varchar(100)" json:"contentType"` Headers []*Header `xorm:"mediumtext" json:"headers"` Events []string `xorm:"varchar(100)" json:"events"` + IsEnabled bool `json:"isEnabled"` } func GetWebhookCount(owner, field, value string) int { diff --git a/web/src/SyncerEditPage.js b/web/src/SyncerEditPage.js index 4638024b..5d534ff5 100644 --- a/web/src/SyncerEditPage.js +++ b/web/src/SyncerEditPage.js @@ -250,7 +250,7 @@ class SyncerEditPage extends React.Component { - {Setting.getLabel(i18next.t("syncer:Is enabled"), i18next.t("syncer:Is enabled - Tooltip"))} : + {Setting.getLabel(i18next.t("general:Is enabled"), i18next.t("general:Is enabled - Tooltip"))} : { diff --git a/web/src/SyncerListPage.js b/web/src/SyncerListPage.js index ebfb470f..0290d808 100644 --- a/web/src/SyncerListPage.js +++ b/web/src/SyncerListPage.js @@ -192,7 +192,7 @@ class SyncerListPage extends BaseListPage { ...this.getColumnSearchProps('syncInterval'), }, { - title: i18next.t("syncer:Is enabled"), + title: i18next.t("general:Is enabled"), dataIndex: 'isEnabled', key: 'isEnabled', width: '120px', diff --git a/web/src/WebhookEditPage.js b/web/src/WebhookEditPage.js index d846e753..e3990320 100644 --- a/web/src/WebhookEditPage.js +++ b/web/src/WebhookEditPage.js @@ -13,7 +13,7 @@ // limitations under the License. import React from "react"; -import {Button, Card, Col, Input, Row, Select} from 'antd'; +import {Button, Card, Col, Input, Row, Select, Switch} from 'antd'; import {LinkOutlined} from "@ant-design/icons"; import * as WebhookBackend from "./backend/WebhookBackend"; import * as OrganizationBackend from "./backend/OrganizationBackend"; @@ -181,6 +181,16 @@ class WebhookEditPage extends React.Component { + + + {Setting.getLabel(i18next.t("general:Is enabled"), i18next.t("general:Is enabled - Tooltip"))} : + + + { + this.updateWebhookField('isEnabled', checked); + }} /> + + ) } diff --git a/web/src/WebhookListPage.js b/web/src/WebhookListPage.js index cf2d5125..a6d06d49 100644 --- a/web/src/WebhookListPage.js +++ b/web/src/WebhookListPage.js @@ -14,7 +14,7 @@ import React from "react"; import {Link} from "react-router-dom"; -import {Button, Popconfirm, Table} from 'antd'; +import {Button, Popconfirm, Switch, Table} from 'antd'; import moment from "moment"; import * as Setting from "./Setting"; import * as WebhookBackend from "./backend/WebhookBackend"; @@ -34,6 +34,7 @@ class WebhookListPage extends BaseListPage { contentType: "application/json", headers: [], events: ["signup", "login", "logout", "update-user"], + isEnabled: true, } } @@ -156,6 +157,18 @@ class WebhookListPage extends BaseListPage { return Setting.getTags(text); } }, + { + title: i18next.t("general:Is enabled"), + dataIndex: 'isEnabled', + key: 'isEnabled', + width: '120px', + sorter: true, + render: (text, record, index) => { + return ( + + ) + } + }, { title: i18next.t("general:Action"), dataIndex: '', diff --git a/web/src/locales/de/data.json b/web/src/locales/de/data.json index 381c9713..68af22b0 100644 --- a/web/src/locales/de/data.json +++ b/web/src/locales/de/data.json @@ -87,6 +87,8 @@ "Home - Tooltip": "Application homepage", "ID": "ID", "ID - Tooltip": "random string", + "Is enabled": "Is enabled", + "Is enabled - Tooltip": "Is enabled - Tooltip", "LDAPs": "LDAPs", "LDAPs - Tooltip": "LDAPs - Tooltip", "Logo - Tooltip": "App's image tag", @@ -335,8 +337,6 @@ "Database type": "Database type", "Database type - Tooltip": "Database type - Tooltip", "Edit Syncer": "Edit Syncer", - "Is enabled": "Is enabled", - "Is enabled - Tooltip": "Is enabled - Tooltip", "Is hashed": "Is hashed", "Sync interval": "Sync interval", "Sync interval - Tooltip": "Sync interval - Tooltip", @@ -417,7 +417,13 @@ "Edit Webhook": "Edit Webhook", "Events": "Events", "Events - Tooltip": "Events - Tooltip", + "Headers": "Headers", + "Headers - Tooltip": "Headers - Tooltip", + "Method": "Method", + "Method - Tooltip": "Method - Tooltip", + "Name": "Name", "URL": "URL", - "URL - Tooltip": "URL - Tooltip" + "URL - Tooltip": "URL - Tooltip", + "Value": "Value" } } \ No newline at end of file diff --git a/web/src/locales/en/data.json b/web/src/locales/en/data.json index 37483177..870ea121 100644 --- a/web/src/locales/en/data.json +++ b/web/src/locales/en/data.json @@ -87,6 +87,8 @@ "Home - Tooltip": "Home - Tooltip", "ID": "ID", "ID - Tooltip": "ID - Tooltip", + "Is enabled": "Is enabled", + "Is enabled - Tooltip": "Is enabled - Tooltip", "LDAPs": "LDAPs", "LDAPs - Tooltip": "LDAPs - Tooltip", "Logo - Tooltip": "Logo - Tooltip", @@ -335,8 +337,6 @@ "Database type": "Database type", "Database type - Tooltip": "Database type - Tooltip", "Edit Syncer": "Edit Syncer", - "Is enabled": "Is enabled", - "Is enabled - Tooltip": "Is enabled - Tooltip", "Is hashed": "Is hashed", "Sync interval": "Sync interval", "Sync interval - Tooltip": "Sync interval - Tooltip", @@ -417,7 +417,13 @@ "Edit Webhook": "Edit Webhook", "Events": "Events", "Events - Tooltip": "Events - Tooltip", + "Headers": "Headers", + "Headers - Tooltip": "Headers - Tooltip", + "Method": "Method", + "Method - Tooltip": "Method - Tooltip", + "Name": "Name", "URL": "URL", - "URL - Tooltip": "URL - Tooltip" + "URL - Tooltip": "URL - Tooltip", + "Value": "Value" } } \ No newline at end of file diff --git a/web/src/locales/fr/data.json b/web/src/locales/fr/data.json index 381c9713..68af22b0 100644 --- a/web/src/locales/fr/data.json +++ b/web/src/locales/fr/data.json @@ -87,6 +87,8 @@ "Home - Tooltip": "Application homepage", "ID": "ID", "ID - Tooltip": "random string", + "Is enabled": "Is enabled", + "Is enabled - Tooltip": "Is enabled - Tooltip", "LDAPs": "LDAPs", "LDAPs - Tooltip": "LDAPs - Tooltip", "Logo - Tooltip": "App's image tag", @@ -335,8 +337,6 @@ "Database type": "Database type", "Database type - Tooltip": "Database type - Tooltip", "Edit Syncer": "Edit Syncer", - "Is enabled": "Is enabled", - "Is enabled - Tooltip": "Is enabled - Tooltip", "Is hashed": "Is hashed", "Sync interval": "Sync interval", "Sync interval - Tooltip": "Sync interval - Tooltip", @@ -417,7 +417,13 @@ "Edit Webhook": "Edit Webhook", "Events": "Events", "Events - Tooltip": "Events - Tooltip", + "Headers": "Headers", + "Headers - Tooltip": "Headers - Tooltip", + "Method": "Method", + "Method - Tooltip": "Method - Tooltip", + "Name": "Name", "URL": "URL", - "URL - Tooltip": "URL - Tooltip" + "URL - Tooltip": "URL - Tooltip", + "Value": "Value" } } \ No newline at end of file diff --git a/web/src/locales/ja/data.json b/web/src/locales/ja/data.json index 381c9713..68af22b0 100644 --- a/web/src/locales/ja/data.json +++ b/web/src/locales/ja/data.json @@ -87,6 +87,8 @@ "Home - Tooltip": "Application homepage", "ID": "ID", "ID - Tooltip": "random string", + "Is enabled": "Is enabled", + "Is enabled - Tooltip": "Is enabled - Tooltip", "LDAPs": "LDAPs", "LDAPs - Tooltip": "LDAPs - Tooltip", "Logo - Tooltip": "App's image tag", @@ -335,8 +337,6 @@ "Database type": "Database type", "Database type - Tooltip": "Database type - Tooltip", "Edit Syncer": "Edit Syncer", - "Is enabled": "Is enabled", - "Is enabled - Tooltip": "Is enabled - Tooltip", "Is hashed": "Is hashed", "Sync interval": "Sync interval", "Sync interval - Tooltip": "Sync interval - Tooltip", @@ -417,7 +417,13 @@ "Edit Webhook": "Edit Webhook", "Events": "Events", "Events - Tooltip": "Events - Tooltip", + "Headers": "Headers", + "Headers - Tooltip": "Headers - Tooltip", + "Method": "Method", + "Method - Tooltip": "Method - Tooltip", + "Name": "Name", "URL": "URL", - "URL - Tooltip": "URL - Tooltip" + "URL - Tooltip": "URL - Tooltip", + "Value": "Value" } } \ No newline at end of file diff --git a/web/src/locales/ko/data.json b/web/src/locales/ko/data.json index 381c9713..68af22b0 100644 --- a/web/src/locales/ko/data.json +++ b/web/src/locales/ko/data.json @@ -87,6 +87,8 @@ "Home - Tooltip": "Application homepage", "ID": "ID", "ID - Tooltip": "random string", + "Is enabled": "Is enabled", + "Is enabled - Tooltip": "Is enabled - Tooltip", "LDAPs": "LDAPs", "LDAPs - Tooltip": "LDAPs - Tooltip", "Logo - Tooltip": "App's image tag", @@ -335,8 +337,6 @@ "Database type": "Database type", "Database type - Tooltip": "Database type - Tooltip", "Edit Syncer": "Edit Syncer", - "Is enabled": "Is enabled", - "Is enabled - Tooltip": "Is enabled - Tooltip", "Is hashed": "Is hashed", "Sync interval": "Sync interval", "Sync interval - Tooltip": "Sync interval - Tooltip", @@ -417,7 +417,13 @@ "Edit Webhook": "Edit Webhook", "Events": "Events", "Events - Tooltip": "Events - Tooltip", + "Headers": "Headers", + "Headers - Tooltip": "Headers - Tooltip", + "Method": "Method", + "Method - Tooltip": "Method - Tooltip", + "Name": "Name", "URL": "URL", - "URL - Tooltip": "URL - Tooltip" + "URL - Tooltip": "URL - Tooltip", + "Value": "Value" } } \ No newline at end of file diff --git a/web/src/locales/ru/data.json b/web/src/locales/ru/data.json index 381c9713..68af22b0 100644 --- a/web/src/locales/ru/data.json +++ b/web/src/locales/ru/data.json @@ -87,6 +87,8 @@ "Home - Tooltip": "Application homepage", "ID": "ID", "ID - Tooltip": "random string", + "Is enabled": "Is enabled", + "Is enabled - Tooltip": "Is enabled - Tooltip", "LDAPs": "LDAPs", "LDAPs - Tooltip": "LDAPs - Tooltip", "Logo - Tooltip": "App's image tag", @@ -335,8 +337,6 @@ "Database type": "Database type", "Database type - Tooltip": "Database type - Tooltip", "Edit Syncer": "Edit Syncer", - "Is enabled": "Is enabled", - "Is enabled - Tooltip": "Is enabled - Tooltip", "Is hashed": "Is hashed", "Sync interval": "Sync interval", "Sync interval - Tooltip": "Sync interval - Tooltip", @@ -417,7 +417,13 @@ "Edit Webhook": "Edit Webhook", "Events": "Events", "Events - Tooltip": "Events - Tooltip", + "Headers": "Headers", + "Headers - Tooltip": "Headers - Tooltip", + "Method": "Method", + "Method - Tooltip": "Method - Tooltip", + "Name": "Name", "URL": "URL", - "URL - Tooltip": "URL - Tooltip" + "URL - Tooltip": "URL - Tooltip", + "Value": "Value" } } \ No newline at end of file diff --git a/web/src/locales/zh/data.json b/web/src/locales/zh/data.json index ffc9c4fe..5a473b57 100644 --- a/web/src/locales/zh/data.json +++ b/web/src/locales/zh/data.json @@ -87,6 +87,8 @@ "Home - Tooltip": "应用的首页", "ID": "ID", "ID - Tooltip": "唯一的随机字符串", + "Is enabled": "已启用", + "Is enabled - Tooltip": "是否启用", "LDAPs": "LDAPs", "LDAPs - Tooltip": "LDAPs", "Logo - Tooltip": "应用程序向外展示的图标", @@ -335,8 +337,6 @@ "Database type": "数据库类型", "Database type - Tooltip": "数据库类型", "Edit Syncer": "修改同步器", - "Is enabled": "已启用", - "Is enabled - Tooltip": "是否启用", "Is hashed": "是否参与哈希计算", "Sync interval": "同步间隔", "Sync interval - Tooltip": "单位为分钟", @@ -417,7 +417,13 @@ "Edit Webhook": "修改Webhook", "Events": "事件", "Events - Tooltip": "事件", + "Headers": "协议头", + "Headers - Tooltip": "HTTP协议头(键值对)", + "Method": "方法", + "Method - Tooltip": "HTTP方法", + "Name": "名称", "URL": "URL", - "URL - Tooltip": "URL" + "URL - Tooltip": "URL", + "Value": "值" } } \ No newline at end of file