Add method to webhook.

This commit is contained in:
Yang Luo
2021-12-26 19:56:02 +08:00
parent 2ec947d488
commit 5015bf1c7d
4 changed files with 29 additions and 4 deletions

View File

@ -27,6 +27,7 @@ type Webhook struct {
CreatedTime string `xorm:"varchar(100)" json:"createdTime"` CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
Url string `xorm:"varchar(100)" json:"url"` Url string `xorm:"varchar(100)" json:"url"`
Method string `xorm:"varchar(100)" json:"method"`
ContentType string `xorm:"varchar(100)" json:"contentType"` ContentType string `xorm:"varchar(100)" json:"contentType"`
Events []string `xorm:"varchar(100)" json:"events"` Events []string `xorm:"varchar(100)" json:"events"`

View File

@ -26,7 +26,7 @@ func sendWebhook(webhook *Webhook, record *Record) error {
body := strings.NewReader(util.StructToJson(record)) body := strings.NewReader(util.StructToJson(record))
req, err := http.NewRequest("POST", webhook.Url, body) req, err := http.NewRequest(webhook.Method, webhook.Url, body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -114,6 +114,23 @@ class WebhookEditPage extends React.Component {
}} /> }} />
</Col> </Col>
</Row> </Row>
<Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}>
{Setting.getLabel(i18next.t("webhook:Method"), i18next.t("webhook:Method - Tooltip"))} :
</Col>
<Col span={22} >
<Select virtual={false} style={{width: '100%'}} value={this.state.webhook.method} onChange={(value => {this.updateWebhookField('method', value);})}>
{
[
{id: 'POST', name: 'POST'},
{id: 'GET', name: 'GET'},
{id: 'PUT', name: 'PUT'},
{id: 'DELETE', name: 'DELETE'},
].map((method, index) => <Option key={index} value={method.id}>{method.name}</Option>)
}
</Select>
</Col>
</Row>
<Row style={{marginTop: '20px'}} > <Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}> <Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}>
{Setting.getLabel(i18next.t("webhook:Content type"), i18next.t("webhook:Content type - Tooltip"))} : {Setting.getLabel(i18next.t("webhook:Content type"), i18next.t("webhook:Content type - Tooltip"))} :

View File

@ -20,10 +20,8 @@ import * as Setting from "./Setting";
import * as WebhookBackend from "./backend/WebhookBackend"; import * as WebhookBackend from "./backend/WebhookBackend";
import i18next from "i18next"; import i18next from "i18next";
import BaseListPage from "./BaseListPage"; import BaseListPage from "./BaseListPage";
import * as ProviderBackend from "./backend/ProviderBackend";
class WebhookListPage extends BaseListPage { class WebhookListPage extends BaseListPage {
newWebhook() { newWebhook() {
const randomName = Setting.getRandomName(); const randomName = Setting.getRandomName();
return { return {
@ -31,6 +29,7 @@ class WebhookListPage extends BaseListPage {
name: `webhook_${randomName}`, name: `webhook_${randomName}`,
createdTime: moment().format(), createdTime: moment().format(),
url: "https://example.com/callback", url: "https://example.com/callback",
method: "POST",
contentType: "application/json", contentType: "application/json",
events: ["signup", "login", "logout", "update-user"], events: ["signup", "login", "logout", "update-user"],
organization: "built-in", organization: "built-in",
@ -125,11 +124,19 @@ class WebhookListPage extends BaseListPage {
) )
} }
}, },
{
title: i18next.t("webhook:Method"),
dataIndex: 'method',
key: 'method',
width: '120px',
sorter: true,
...this.getColumnSearchProps('method'),
},
{ {
title: i18next.t("webhook:Content type"), title: i18next.t("webhook:Content type"),
dataIndex: 'contentType', dataIndex: 'contentType',
key: 'contentType', key: 'contentType',
width: '150px', width: '200px',
sorter: true, sorter: true,
filterMultiple: false, filterMultiple: false,
filters: [ filters: [