2022-02-13 23:39:27 +08:00
|
|
|
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
|
2021-02-13 13:30:51 +08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
import React from "react";
|
|
|
|
import {Link} from "react-router-dom";
|
2023-03-10 19:16:08 +08:00
|
|
|
import {Button, Table} from "antd";
|
2021-02-13 12:15:19 +08:00
|
|
|
import moment from "moment";
|
|
|
|
import * as Setting from "./Setting";
|
|
|
|
import * as ProviderBackend from "./backend/ProviderBackend";
|
2021-02-14 16:59:08 +08:00
|
|
|
import * as Provider from "./auth/Provider";
|
2021-02-19 23:23:59 +08:00
|
|
|
import i18next from "i18next";
|
2021-12-25 10:55:10 +08:00
|
|
|
import BaseListPage from "./BaseListPage";
|
2023-04-25 23:05:53 +08:00
|
|
|
import PopconfirmModal from "./common/modal/PopconfirmModal";
|
2021-02-13 12:15:19 +08:00
|
|
|
|
2021-12-25 10:55:10 +08:00
|
|
|
class ProviderListPage extends BaseListPage {
|
2022-11-04 21:31:08 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
2023-02-02 16:43:51 +08:00
|
|
|
|
|
|
|
componentDidMount() {
|
2023-06-29 20:32:34 +03:00
|
|
|
super.componentDidMount();
|
2023-02-02 16:43:51 +08:00
|
|
|
this.setState({
|
|
|
|
owner: Setting.isAdminUser(this.props.account) ? "admin" : this.props.account.owner,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
newProvider() {
|
2021-12-12 18:51:12 +08:00
|
|
|
const randomName = Setting.getRandomName();
|
2023-08-07 17:22:32 +08:00
|
|
|
const owner = Setting.isDefaultOrganizationSelected(this.props.account) ? this.state.owner : Setting.getRequestOrganization(this.props.account);
|
2021-02-13 12:15:19 +08:00
|
|
|
return {
|
2023-06-29 20:32:34 +03:00
|
|
|
owner: owner,
|
2021-11-06 11:32:22 +08:00
|
|
|
name: `provider_${randomName}`,
|
2021-02-13 12:15:19 +08:00
|
|
|
createdTime: moment().format(),
|
2021-11-06 11:32:22 +08:00
|
|
|
displayName: `New Provider - ${randomName}`,
|
2021-05-14 23:45:20 +08:00
|
|
|
category: "OAuth",
|
2021-03-28 20:20:40 +08:00
|
|
|
type: "GitHub",
|
2021-08-23 22:25:55 +08:00
|
|
|
method: "Normal",
|
2021-02-13 12:15:19 +08:00
|
|
|
clientId: "",
|
|
|
|
clientSecret: "",
|
2021-06-09 20:39:43 +08:00
|
|
|
enableSignUp: true,
|
2021-05-14 23:45:20 +08:00
|
|
|
host: "",
|
|
|
|
port: 0,
|
2021-02-13 12:15:19 +08:00
|
|
|
providerUrl: "https://github.com/organizations/xxx/settings/applications/1234567",
|
2022-07-10 15:45:55 +08:00
|
|
|
};
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
addProvider() {
|
|
|
|
const newProvider = this.newProvider();
|
|
|
|
ProviderBackend.addProvider(newProvider)
|
|
|
|
.then((res) => {
|
2022-11-29 20:32:47 +08:00
|
|
|
if (res.status === "ok") {
|
|
|
|
this.props.history.push({pathname: `/providers/${newProvider.owner}/${newProvider.name}`, mode: "add"});
|
2022-12-02 00:06:28 +08:00
|
|
|
Setting.showMessage("success", i18next.t("general:Successfully added"));
|
2022-11-29 20:32:47 +08:00
|
|
|
} else {
|
2022-12-02 00:06:28 +08:00
|
|
|
Setting.showMessage("error", `${i18next.t("general:Failed to add")}: ${res.msg}`);
|
2022-11-29 20:32:47 +08:00
|
|
|
}
|
|
|
|
})
|
2021-02-13 12:15:19 +08:00
|
|
|
.catch(error => {
|
2022-12-02 00:06:28 +08:00
|
|
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
2021-02-13 12:15:19 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteProvider(i) {
|
2021-12-25 10:55:10 +08:00
|
|
|
ProviderBackend.deleteProvider(this.state.data[i])
|
2021-02-13 12:15:19 +08:00
|
|
|
.then((res) => {
|
2022-12-02 00:06:28 +08:00
|
|
|
if (res.status === "ok") {
|
|
|
|
Setting.showMessage("success", i18next.t("general:Successfully deleted"));
|
|
|
|
this.setState({
|
|
|
|
data: Setting.deleteRow(this.state.data, i),
|
|
|
|
pagination: {total: this.state.pagination.total - 1},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`);
|
|
|
|
}
|
|
|
|
})
|
2021-02-13 12:15:19 +08:00
|
|
|
.catch(error => {
|
2022-12-02 00:06:28 +08:00
|
|
|
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
2021-02-13 12:15:19 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderTable(providers) {
|
|
|
|
const columns = [
|
|
|
|
{
|
2021-02-19 23:23:59 +08:00
|
|
|
title: i18next.t("general:Name"),
|
2022-07-10 15:45:55 +08:00
|
|
|
dataIndex: "name",
|
|
|
|
key: "name",
|
|
|
|
width: "120px",
|
|
|
|
fixed: "left",
|
2021-12-25 10:55:10 +08:00
|
|
|
sorter: true,
|
2022-07-10 15:45:55 +08:00
|
|
|
...this.getColumnSearchProps("name"),
|
2021-02-13 12:15:19 +08:00
|
|
|
render: (text, record, index) => {
|
|
|
|
return (
|
2022-11-21 01:17:55 +08:00
|
|
|
<Link to={`/providers/${record.owner}/${text}`}>
|
2021-02-13 12:15:19 +08:00
|
|
|
{text}
|
|
|
|
</Link>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2022-08-06 23:54:56 +08:00
|
|
|
},
|
2021-02-13 12:15:19 +08:00
|
|
|
},
|
2022-11-21 01:17:55 +08:00
|
|
|
{
|
|
|
|
title: i18next.t("general:Organization"),
|
|
|
|
dataIndex: "owner",
|
|
|
|
key: "owner",
|
|
|
|
width: "150px",
|
|
|
|
sorter: true,
|
2023-06-06 20:50:28 +08:00
|
|
|
...this.getColumnSearchProps("owner"),
|
2023-05-17 17:25:59 +08:00
|
|
|
render: (text, record, index) => {
|
|
|
|
return (text !== "admin") ? text : i18next.t("provider:admin (Shared)");
|
|
|
|
},
|
2022-11-21 01:17:55 +08:00
|
|
|
},
|
2021-02-13 12:15:19 +08:00
|
|
|
{
|
2021-04-28 00:13:50 +08:00
|
|
|
title: i18next.t("general:Created time"),
|
2022-07-10 15:45:55 +08:00
|
|
|
dataIndex: "createdTime",
|
|
|
|
key: "createdTime",
|
|
|
|
width: "180px",
|
2021-12-25 10:55:10 +08:00
|
|
|
sorter: true,
|
2021-02-13 12:15:19 +08:00
|
|
|
render: (text, record, index) => {
|
|
|
|
return Setting.getFormattedDate(text);
|
2022-08-06 23:54:56 +08:00
|
|
|
},
|
2021-02-13 12:15:19 +08:00
|
|
|
},
|
|
|
|
{
|
2021-04-28 00:13:50 +08:00
|
|
|
title: i18next.t("general:Display name"),
|
2022-07-10 15:45:55 +08:00
|
|
|
dataIndex: "displayName",
|
|
|
|
key: "displayName",
|
2021-02-13 12:15:19 +08:00
|
|
|
// width: '100px',
|
2021-12-25 10:55:10 +08:00
|
|
|
sorter: true,
|
2022-07-10 15:45:55 +08:00
|
|
|
...this.getColumnSearchProps("displayName"),
|
2021-02-13 12:15:19 +08:00
|
|
|
},
|
2021-05-14 23:45:20 +08:00
|
|
|
{
|
|
|
|
title: i18next.t("provider:Category"),
|
2022-07-10 15:45:55 +08:00
|
|
|
dataIndex: "category",
|
|
|
|
key: "category",
|
2021-12-25 10:55:10 +08:00
|
|
|
filterMultiple: false,
|
|
|
|
filters: [
|
2023-08-26 23:39:02 +08:00
|
|
|
{text: "Captcha", value: "Captcha"},
|
2022-07-10 15:45:55 +08:00
|
|
|
{text: "Email", value: "Email"},
|
2023-08-26 23:39:02 +08:00
|
|
|
{text: "Notification", value: "Notification"},
|
|
|
|
{text: "OAuth", value: "OAuth"},
|
|
|
|
{text: "Payment", value: "Payment"},
|
|
|
|
{text: "SAML", value: "SAML"},
|
2022-07-10 15:45:55 +08:00
|
|
|
{text: "SMS", value: "SMS"},
|
|
|
|
{text: "Storage", value: "Storage"},
|
2023-08-26 23:39:02 +08:00
|
|
|
{text: "Web3", value: "Web3"},
|
2021-12-25 10:55:10 +08:00
|
|
|
],
|
2022-07-10 15:45:55 +08:00
|
|
|
width: "110px",
|
2021-12-25 10:55:10 +08:00
|
|
|
sorter: true,
|
2021-05-14 23:45:20 +08:00
|
|
|
},
|
2021-02-13 12:15:19 +08:00
|
|
|
{
|
2021-02-19 23:23:59 +08:00
|
|
|
title: i18next.t("provider:Type"),
|
2022-07-10 15:45:55 +08:00
|
|
|
dataIndex: "type",
|
|
|
|
key: "type",
|
|
|
|
width: "110px",
|
|
|
|
align: "center",
|
2021-12-25 10:55:10 +08:00
|
|
|
filterMultiple: false,
|
|
|
|
filters: [
|
2023-08-26 23:39:02 +08:00
|
|
|
{text: "Captcha", value: "Captcha", children: Setting.getProviderTypeOptions("Captcha").map((o) => {return {text: o.id, value: o.name};})},
|
2022-08-06 23:47:28 +08:00
|
|
|
{text: "Email", value: "Email", children: Setting.getProviderTypeOptions("Email").map((o) => {return {text: o.id, value: o.name};})},
|
2023-08-26 23:39:02 +08:00
|
|
|
{text: "Notification", value: "Notification", children: Setting.getProviderTypeOptions("Notification").map((o) => {return {text: o.id, value: o.name};})},
|
|
|
|
{text: "OAuth", value: "OAuth", children: Setting.getProviderTypeOptions("OAuth").map((o) => {return {text: o.id, value: o.name};})},
|
|
|
|
{text: "Payment", value: "Payment", children: Setting.getProviderTypeOptions("Payment").map((o) => {return {text: o.id, value: o.name};})},
|
|
|
|
{text: "SAML", value: "SAML", children: Setting.getProviderTypeOptions("SAML").map((o) => {return {text: o.id, value: o.name};})},
|
2022-08-06 23:47:28 +08:00
|
|
|
{text: "SMS", value: "SMS", children: Setting.getProviderTypeOptions("SMS").map((o) => {return {text: o.id, value: o.name};})},
|
|
|
|
{text: "Storage", value: "Storage", children: Setting.getProviderTypeOptions("Storage").map((o) => {return {text: o.id, value: o.name};})},
|
2023-08-26 23:39:02 +08:00
|
|
|
{text: "Web3", value: "Web3", children: Setting.getProviderTypeOptions("Web3").map((o) => {return {text: o.id, value: o.name};})},
|
2021-12-25 10:55:10 +08:00
|
|
|
],
|
|
|
|
sorter: true,
|
2021-02-14 10:20:42 +08:00
|
|
|
render: (text, record, index) => {
|
2021-11-28 18:46:20 +08:00
|
|
|
return Provider.getProviderLogoWidget(record);
|
2022-08-06 23:54:56 +08:00
|
|
|
},
|
2021-02-13 12:15:19 +08:00
|
|
|
},
|
|
|
|
{
|
2021-02-19 23:23:59 +08:00
|
|
|
title: i18next.t("provider:Client ID"),
|
2022-07-10 15:45:55 +08:00
|
|
|
dataIndex: "clientId",
|
|
|
|
key: "clientId",
|
|
|
|
width: "100px",
|
2021-12-25 10:55:10 +08:00
|
|
|
sorter: true,
|
2022-07-10 15:45:55 +08:00
|
|
|
...this.getColumnSearchProps("clientId"),
|
2021-05-23 23:38:38 +08:00
|
|
|
render: (text, record, index) => {
|
|
|
|
return Setting.getShortText(text);
|
2022-08-06 23:54:56 +08:00
|
|
|
},
|
2021-02-13 12:15:19 +08:00
|
|
|
},
|
|
|
|
{
|
2021-02-19 23:23:59 +08:00
|
|
|
title: i18next.t("provider:Provider URL"),
|
2022-07-10 15:45:55 +08:00
|
|
|
dataIndex: "providerUrl",
|
|
|
|
key: "providerUrl",
|
|
|
|
width: "150px",
|
2021-12-25 10:55:10 +08:00
|
|
|
sorter: true,
|
2022-07-10 15:45:55 +08:00
|
|
|
...this.getColumnSearchProps("providerUrl"),
|
2021-02-13 12:15:19 +08:00
|
|
|
render: (text, record, index) => {
|
|
|
|
return (
|
2021-03-27 11:38:15 +08:00
|
|
|
<a target="_blank" rel="noreferrer" href={text}>
|
2021-02-13 23:00:43 +08:00
|
|
|
{
|
|
|
|
Setting.getShortText(text)
|
|
|
|
}
|
2021-02-13 12:15:19 +08:00
|
|
|
</a>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2022-08-06 23:54:56 +08:00
|
|
|
},
|
2021-02-13 12:15:19 +08:00
|
|
|
},
|
|
|
|
{
|
2021-02-19 23:23:59 +08:00
|
|
|
title: i18next.t("general:Action"),
|
2022-07-10 15:45:55 +08:00
|
|
|
dataIndex: "",
|
|
|
|
key: "op",
|
|
|
|
width: "170px",
|
2021-07-23 09:46:01 +08:00
|
|
|
fixed: (Setting.isMobile()) ? "false" : "right",
|
2021-02-13 12:15:19 +08:00
|
|
|
render: (text, record, index) => {
|
|
|
|
return (
|
|
|
|
<div>
|
2022-11-21 01:17:55 +08:00
|
|
|
<Button disabled={!Setting.isAdminUser(this.props.account) && (record.owner !== this.props.account.owner)} style={{marginTop: "10px", marginBottom: "10px", marginRight: "10px"}} type="primary" onClick={() => this.props.history.push(`/providers/${record.owner}/${record.name}`)}>{i18next.t("general:Edit")}</Button>
|
2023-03-10 19:16:08 +08:00
|
|
|
<PopconfirmModal
|
2023-03-07 22:38:48 +08:00
|
|
|
title={i18next.t("general:Sure to delete") + `: ${record.name} ?`}
|
2021-02-13 12:15:19 +08:00
|
|
|
onConfirm={() => this.deleteProvider(index)}
|
2023-05-09 00:06:52 +08:00
|
|
|
disabled={!Setting.isAdminUser(this.props.account) && (record.owner !== this.props.account.owner)}
|
2021-02-13 12:15:19 +08:00
|
|
|
>
|
2023-03-10 19:16:08 +08:00
|
|
|
</PopconfirmModal>
|
2021-02-13 12:15:19 +08:00
|
|
|
</div>
|
2022-07-10 15:45:55 +08:00
|
|
|
);
|
2022-08-06 23:54:56 +08:00
|
|
|
},
|
2021-02-13 12:15:19 +08:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-11-06 11:32:22 +08:00
|
|
|
const paginationProps = {
|
2021-12-25 10:55:10 +08:00
|
|
|
total: this.state.pagination.total,
|
2021-11-06 11:32:22 +08:00
|
|
|
showQuickJumper: true,
|
|
|
|
showSizeChanger: true,
|
2021-12-25 10:55:10 +08:00
|
|
|
showTotal: () => i18next.t("general:{total} in total").replace("{total}", this.state.pagination.total),
|
2021-11-06 11:32:22 +08:00
|
|
|
};
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2023-04-22 20:18:38 +08:00
|
|
|
<Table scroll={{x: "max-content"}} columns={columns} dataSource={providers} rowKey={(record) => `${record.owner}/${record.name}`} size="middle" bordered pagination={paginationProps}
|
2022-07-10 15:45:55 +08:00
|
|
|
title={() => (
|
|
|
|
<div>
|
|
|
|
{i18next.t("general:Providers")}
|
2023-08-27 16:28:37 +08:00
|
|
|
<Button id="add-button" type="primary" size="small" onClick={this.addProvider.bind(this)}>{i18next.t("general:Add")}</Button>
|
2022-07-10 15:45:55 +08:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
loading={this.state.loading}
|
|
|
|
onChange={this.handleTableChange}
|
2021-02-13 12:15:19 +08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:55:10 +08:00
|
|
|
fetch = (params = {}) => {
|
|
|
|
let field = params.searchedColumn, value = params.searchText;
|
2022-08-08 23:35:24 +08:00
|
|
|
const sortField = params.sortField, sortOrder = params.sortOrder;
|
2021-12-25 10:55:10 +08:00
|
|
|
if (params.category !== undefined && params.category !== null) {
|
|
|
|
field = "category";
|
|
|
|
value = params.category;
|
|
|
|
} else if (params.type !== undefined && params.type !== null) {
|
|
|
|
field = "type";
|
|
|
|
value = params.type;
|
|
|
|
}
|
2022-07-10 15:45:55 +08:00
|
|
|
this.setState({loading: true});
|
2023-06-29 20:32:34 +03:00
|
|
|
(Setting.isDefaultOrganizationSelected(this.props.account) ? ProviderBackend.getGlobalProviders(params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder)
|
|
|
|
: ProviderBackend.getProviders(Setting.getRequestOrganization(this.props.account), params.pagination.current, params.pagination.pageSize, field, value, sortField, sortOrder))
|
2021-12-25 10:55:10 +08:00
|
|
|
.then((res) => {
|
2023-06-04 00:42:57 +08:00
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
});
|
2021-12-25 10:55:10 +08:00
|
|
|
if (res.status === "ok") {
|
|
|
|
this.setState({
|
|
|
|
data: res.data,
|
|
|
|
pagination: {
|
|
|
|
...params.pagination,
|
|
|
|
total: res.data2,
|
|
|
|
},
|
|
|
|
searchText: params.searchText,
|
|
|
|
searchedColumn: params.searchedColumn,
|
|
|
|
});
|
2023-01-06 15:04:13 +08:00
|
|
|
} else {
|
2023-02-18 16:21:12 +08:00
|
|
|
if (Setting.isResponseDenied(res)) {
|
2023-01-06 15:04:13 +08:00
|
|
|
this.setState({
|
|
|
|
isAuthorized: false,
|
|
|
|
});
|
2023-06-04 00:42:57 +08:00
|
|
|
} else {
|
|
|
|
Setting.showMessage("error", res.msg);
|
2023-01-06 15:04:13 +08:00
|
|
|
}
|
2021-07-23 09:46:01 +08:00
|
|
|
}
|
2021-12-25 10:55:10 +08:00
|
|
|
});
|
|
|
|
};
|
2021-02-13 12:15:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ProviderListPage;
|