// Copyright 2023 The Casdoor 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.
import React from "react";
import {Button, Card, Col, Input, Row, Select, Switch} from "antd";
import * as GroupBackend from "./backend/GroupBackend";
import * as OrganizationBackend from "./backend/OrganizationBackend";
import * as Setting from "./Setting";
import i18next from "i18next";
class GroupEditPage extends React.Component {
constructor(props) {
super(props);
this.state = {
classes: props,
groupName: props.match.params.groupName,
organizationName: props.organizationName !== undefined ? props.organizationName : props.match.params.organizationName,
group: null,
users: [],
groups: [],
organizations: [],
mode: props.location.mode !== undefined ? props.location.mode : "edit",
};
}
UNSAFE_componentWillMount() {
this.getGroup();
this.getGroups(this.state.organizationName);
this.getOrganizations();
}
getGroup() {
GroupBackend.getGroup(this.state.organizationName, this.state.groupName)
.then((res) => {
if (res.status === "ok") {
this.setState({
group: res.data,
});
}
});
}
getGroups(organizationName) {
GroupBackend.getGroups(organizationName)
.then((res) => {
if (res.status === "ok") {
this.setState({
groups: res.data,
});
}
});
}
getOrganizations() {
OrganizationBackend.getOrganizationNames("admin")
.then((res) => {
if (res.status === "ok") {
this.setState({
organizations: res.data || [],
});
}
});
}
parseGroupField(key, value) {
if ([""].includes(key)) {
value = Setting.myParseInt(value);
}
return value;
}
updateGroupField(key, value) {
value = this.parseGroupField(key, value);
const group = this.state.group;
group[key] = value;
this.setState({
group: group,
});
}
getParentIdOptions() {
const groups = this.state.groups.filter((group) => group.name !== this.state.group.name);
const organization = this.state.organizations.find((organization) => organization.name === this.state.group.owner);
if (organization !== undefined) {
groups.push({name: organization.name, displayName: organization.displayName});
}
return groups.map((group) => ({label: group.displayName, value: group.name}));
}
renderGroup() {
return (