{this.updateRuleField("expressions", value);}} />
+ ) : null
+ }
{
diff --git a/web/src/Setting.js b/web/src/Setting.js
index 38267ff..807abfe 100644
--- a/web/src/Setting.js
+++ b/web/src/Setting.js
@@ -303,3 +303,7 @@ export function getDeduplicatedArray(sourceTable, filterTable, key) {
const res = sourceTable.filter(item => !filterTable.some(arrayItem => arrayItem[key] === item[key]));
return res;
}
+
+export function getItemId(item) {
+ return item.owner + "/" + item.name;
+}
diff --git a/web/src/components/CompoundRule.js b/web/src/components/CompoundRule.js
new file mode 100644
index 0000000..74f5208
--- /dev/null
+++ b/web/src/components/CompoundRule.js
@@ -0,0 +1,192 @@
+// Copyright 2023 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.
+
+import React from "react";
+import {DeleteOutlined, DownOutlined, UpOutlined} from "@ant-design/icons";
+import {Button, Col, Row, Select, Table, Tooltip} from "antd";
+import {getRules} from "../backend/RuleBackend";
+import * as Setting from "../Setting";
+import i18next from "i18next";
+
+const {Option} = Select;
+
+class CompoundRule extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ classes: props,
+ rules: [],
+ defaultRules: [
+ {
+ name: "Start",
+ operator: "begin",
+ value: "rule1",
+ },
+ {
+ name: "And",
+ operator: "and",
+ value: "rule2",
+ },
+ ],
+ };
+ if (this.props.table.length === 0) {
+ this.restore();
+ }
+ }
+
+ UNSAFE_componentWillMount() {
+ this.getRules();
+ }
+
+ getRules() {
+ getRules(this.props.owner).then((res) => {
+ const rules = [];
+ for (let i = 0; i < res.data.length; i++) {
+ if (Setting.getItemId(res.data[i]) === this.props.owner + "/" + this.props.ruleName) {
+ continue;
+ }
+ rules.push(Setting.getItemId(res.data[i]));
+ }
+ this.setState({
+ rules: rules,
+ });
+ });
+ }
+
+ updateTable(table) {
+ this.props.onUpdateTable(table);
+ }
+
+ updateField(table, index, key, value) {
+ table[index][key] = value;
+ this.updateTable(table);
+ }
+
+ addRow(table) {
+ const row = {name: `New Item - ${table.length}`, operator: "and", value: ""};
+ if (table === undefined) {
+ table = [];
+ }
+
+ table = Setting.addRow(table, row);
+ this.updateTable(table);
+ }
+
+ deleteRow(table, i) {
+ table = Setting.deleteRow(table, i);
+ this.updateTable(table);
+ }
+
+ upRow(table, i) {
+ table = Setting.swapRow(table, i - 1, i);
+ this.updateTable(table);
+ }
+
+ downRow(table, i) {
+ table = Setting.swapRow(table, i, i + 1);
+ this.updateTable(table);
+ }
+
+ restore() {
+ this.updateTable(this.state.defaultRules);
+ }
+
+ renderTable(table) {
+ const columns = [
+ {
+ title: i18next.t("rule:Logic"),
+ dataIndex: "operator",
+ key: "operator",
+ width: "180px",
+ render: (text, record, index) => {
+ const options = [];
+ if (index !== 0) {
+ options.push({value: "and", text: i18next.t("rule:and")});
+ options.push({value: "or", text: i18next.t("rule:or")});
+ } else {
+ options.push({value: "begin", text: i18next.t("rule:begin")});
+ }
+ return (
+
+ );
+ },
+ },
+ {
+ title: i18next.t("rule:Rule"),
+ dataIndex: "value",
+ key: "value",
+ render: (text, record, index) => (
+
+ ),
+ },
+ {
+ title: i18next.t("general:Action"),
+ key: "action",
+ width: "100px",
+ render: (text, record, index) => (
+
+
+ } size="small" onClick={() => this.upRow(table, index)} />
+
+
+ } size="small" onClick={() => this.downRow(table, index)} />
+
+
+ } size="small" onClick={() => this.deleteRow(table, index)} />
+
+
+ ),
+ },
+ ];
+ return (
+ (
+
+ {this.props.title}
+
+
+
+ )}
+ />
+ );
+ }
+
+ render() {
+ return (
+
+
+
+ {
+ this.renderTable(this.props.table)
+ }
+
+
+
+ );
+ }
+}
+
+export default CompoundRule;