2021-02-13 13:30:51 +08:00
|
|
|
// Copyright 2021 The casbin Authors. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// 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";
|
2021-05-05 23:32:21 +08:00
|
|
|
import {Button, Card, Col, Input, Row, Select} from 'antd';
|
2021-02-13 12:15:19 +08:00
|
|
|
import * as OrganizationBackend from "./backend/OrganizationBackend";
|
|
|
|
import * as Setting from "./Setting";
|
2021-02-19 23:23:59 +08:00
|
|
|
import i18next from "i18next";
|
2021-04-29 20:27:07 +08:00
|
|
|
import {LinkOutlined} from "@ant-design/icons";
|
2021-02-13 12:15:19 +08:00
|
|
|
|
2021-05-05 23:32:21 +08:00
|
|
|
const { Option } = Select;
|
|
|
|
|
2021-02-13 12:15:19 +08:00
|
|
|
class OrganizationEditPage extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
classes: props,
|
|
|
|
organizationName: props.match.params.organizationName,
|
|
|
|
organization: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-27 11:38:15 +08:00
|
|
|
UNSAFE_componentWillMount() {
|
2021-02-13 12:15:19 +08:00
|
|
|
this.getOrganization();
|
|
|
|
}
|
|
|
|
|
|
|
|
getOrganization() {
|
|
|
|
OrganizationBackend.getOrganization("admin", this.state.organizationName)
|
|
|
|
.then((organization) => {
|
|
|
|
this.setState({
|
|
|
|
organization: organization,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
parseOrganizationField(key, value) {
|
|
|
|
// if ([].includes(key)) {
|
|
|
|
// value = Setting.myParseInt(value);
|
|
|
|
// }
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateOrganizationField(key, value) {
|
|
|
|
value = this.parseOrganizationField(key, value);
|
|
|
|
|
|
|
|
let organization = this.state.organization;
|
|
|
|
organization[key] = value;
|
|
|
|
this.setState({
|
|
|
|
organization: organization,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderOrganization() {
|
|
|
|
return (
|
|
|
|
<Card size="small" title={
|
|
|
|
<div>
|
2021-02-19 23:23:59 +08:00
|
|
|
{i18next.t("organization:Edit Organization")}
|
|
|
|
<Button type="primary" onClick={this.submitOrganizationEdit.bind(this)}>{i18next.t("general:Save")}</Button>
|
2021-02-13 12:15:19 +08:00
|
|
|
</div>
|
|
|
|
} style={{marginLeft: '5px'}} type="inner">
|
|
|
|
<Row style={{marginTop: '10px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
2021-03-27 11:38:15 +08:00
|
|
|
{i18next.t("general:Name")}:
|
2021-02-13 12:15:19 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Input value={this.state.organization.name} onChange={e => {
|
|
|
|
this.updateOrganizationField('name', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
2021-04-28 00:13:50 +08:00
|
|
|
{i18next.t("general:Display name")}:
|
2021-02-13 12:15:19 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Input value={this.state.organization.displayName} onChange={e => {
|
|
|
|
this.updateOrganizationField('displayName', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-04-29 20:27:07 +08:00
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
|
|
|
Favicon:
|
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={1}>
|
|
|
|
URL:
|
|
|
|
</Col>
|
|
|
|
<Col span={23} >
|
|
|
|
<Input prefix={<LinkOutlined/>} value={this.state.organization.favicon} onChange={e => {
|
|
|
|
this.updateOrganizationField('favicon', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={1}>
|
|
|
|
{i18next.t("general:Preview")}:
|
|
|
|
</Col>
|
|
|
|
<Col span={23} >
|
|
|
|
<a target="_blank" rel="noreferrer" href={this.state.organization.favicon}>
|
|
|
|
<img src={this.state.organization.favicon} alt={this.state.organization.favicon} height={90} style={{marginBottom: '20px'}}/>
|
|
|
|
</a>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-02-13 12:15:19 +08:00
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
2021-02-19 23:23:59 +08:00
|
|
|
{i18next.t("organization:Website URL")}:
|
2021-02-13 12:15:19 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Input value={this.state.organization.websiteUrl} onChange={e => {
|
|
|
|
this.updateOrganizationField('websiteUrl', e.target.value);
|
|
|
|
}} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-05-05 23:32:21 +08:00
|
|
|
<Row style={{marginTop: '20px'}} >
|
|
|
|
<Col style={{marginTop: '5px'}} span={2}>
|
|
|
|
{i18next.t("general:Password type")}:
|
|
|
|
</Col>
|
|
|
|
<Col span={22} >
|
|
|
|
<Select virtual={false} style={{width: '100%'}} value={this.state.organization.passwordType} onChange={(value => {this.updateOrganizationField('passwordType', value);})}>
|
|
|
|
{
|
|
|
|
['plain', 'salt']
|
|
|
|
.map((item, index) => <Option key={index} value={item}>{item}</Option>)
|
|
|
|
}
|
|
|
|
</Select>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2021-02-13 12:15:19 +08:00
|
|
|
</Card>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
submitOrganizationEdit() {
|
|
|
|
let organization = Setting.deepCopy(this.state.organization);
|
|
|
|
OrganizationBackend.updateOrganization(this.state.organization.owner, this.state.organizationName, organization)
|
|
|
|
.then((res) => {
|
2021-03-28 00:48:34 +08:00
|
|
|
if (res.msg === "") {
|
2021-02-13 12:15:19 +08:00
|
|
|
Setting.showMessage("success", `Successfully saved`);
|
|
|
|
this.setState({
|
|
|
|
organizationName: this.state.organization.name,
|
|
|
|
});
|
|
|
|
this.props.history.push(`/organizations/${this.state.organization.name}`);
|
|
|
|
} else {
|
2021-03-28 00:48:34 +08:00
|
|
|
Setting.showMessage("error", res.msg);
|
2021-02-13 12:15:19 +08:00
|
|
|
this.updateOrganizationField('name', this.state.organizationName);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2021-03-28 08:59:12 +08:00
|
|
|
Setting.showMessage("error", `Failed to connect to server: ${error}`);
|
2021-02-13 12:15:19 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Row style={{width: "100%"}}>
|
|
|
|
<Col span={1}>
|
|
|
|
</Col>
|
|
|
|
<Col span={22}>
|
|
|
|
{
|
|
|
|
this.state.organization !== null ? this.renderOrganization() : null
|
|
|
|
}
|
|
|
|
</Col>
|
|
|
|
<Col span={1}>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row style={{margin: 10}}>
|
|
|
|
<Col span={2}>
|
|
|
|
</Col>
|
|
|
|
<Col span={18}>
|
2021-02-19 23:23:59 +08:00
|
|
|
<Button type="primary" size="large" onClick={this.submitOrganizationEdit.bind(this)}>{i18next.t("general:Save")}</Button>
|
2021-02-13 12:15:19 +08:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default OrganizationEditPage;
|