Remove isEnabled for model, adapter and enforcer, improve UI

This commit is contained in:
Yang Luo 2023-08-18 19:22:47 +08:00
parent a41f6880a2
commit abfc464155
11 changed files with 40 additions and 94 deletions

View File

@ -40,8 +40,6 @@ type Adapter struct {
Table string `xorm:"varchar(100)" json:"table"` Table string `xorm:"varchar(100)" json:"table"`
TableNamePrefix string `xorm:"varchar(100)" json:"tableNamePrefix"` TableNamePrefix string `xorm:"varchar(100)" json:"tableNamePrefix"`
IsEnabled bool `json:"isEnabled"`
*xormadapter.Adapter `xorm:"-" json:"-"` *xormadapter.Adapter `xorm:"-" json:"-"`
} }

View File

@ -32,9 +32,8 @@ type Enforcer struct {
DisplayName string `xorm:"varchar(100)" json:"displayName"` DisplayName string `xorm:"varchar(100)" json:"displayName"`
Description string `xorm:"varchar(100)" json:"description"` Description string `xorm:"varchar(100)" json:"description"`
Model string `xorm:"varchar(100)" json:"model"` Model string `xorm:"varchar(100)" json:"model"`
Adapter string `xorm:"varchar(100)" json:"adapter"` Adapter string `xorm:"varchar(100)" json:"adapter"`
IsEnabled bool `json:"isEnabled"`
ModelCfg map[string]string `xorm:"-" json:"modelCfg"` ModelCfg map[string]string `xorm:"-" json:"modelCfg"`
*casbin.Enforcer *casbin.Enforcer

View File

@ -318,7 +318,6 @@ func initBuiltInUserModel() {
Name: "user-model-built-in", Name: "user-model-built-in",
CreatedTime: util.GetCurrentTime(), CreatedTime: util.GetCurrentTime(),
DisplayName: "Built-in Model", DisplayName: "Built-in Model",
IsEnabled: true,
ModelText: `[request_definition] ModelText: `[request_definition]
r = sub, obj, act r = sub, obj, act
@ -376,7 +375,6 @@ m = (r.subOwner == p.subOwner || p.subOwner == "*") && \
Name: "api-model-built-in", Name: "api-model-built-in",
CreatedTime: util.GetCurrentTime(), CreatedTime: util.GetCurrentTime(),
DisplayName: "API Model", DisplayName: "API Model",
IsEnabled: true,
ModelText: modelText, ModelText: modelText,
} }
_, err = AddModel(model) _, err = AddModel(model)
@ -435,7 +433,6 @@ func initBuiltInUserAdapter() {
TableNamePrefix: conf.GetConfigString("tableNamePrefix"), TableNamePrefix: conf.GetConfigString("tableNamePrefix"),
Database: conf.GetConfigString("dbName"), Database: conf.GetConfigString("dbName"),
Table: "casbin_user_rule", Table: "casbin_user_rule",
IsEnabled: true,
} }
_, err = AddAdapter(adapter) _, err = AddAdapter(adapter)
if err != nil { if err != nil {
@ -462,7 +459,6 @@ func initBuiltInApiAdapter() {
TableNamePrefix: conf.GetConfigString("tableNamePrefix"), TableNamePrefix: conf.GetConfigString("tableNamePrefix"),
Database: conf.GetConfigString("dbName"), Database: conf.GetConfigString("dbName"),
Table: "casbin_api_rule", Table: "casbin_api_rule",
IsEnabled: true,
} }
_, err = AddAdapter(adapter) _, err = AddAdapter(adapter)
if err != nil { if err != nil {
@ -487,7 +483,6 @@ func initBuiltInUserEnforcer() {
DisplayName: "User Enforcer", DisplayName: "User Enforcer",
Model: "built-in/user-model-built-in", Model: "built-in/user-model-built-in",
Adapter: "built-in/user-adapter-built-in", Adapter: "built-in/user-adapter-built-in",
IsEnabled: true,
} }
_, err = AddEnforcer(enforcer) _, err = AddEnforcer(enforcer)
@ -513,7 +508,6 @@ func initBuiltInApiEnforcer() {
DisplayName: "API Enforcer", DisplayName: "API Enforcer",
Model: "built-in/api-model-built-in", Model: "built-in/api-model-built-in",
Adapter: "built-in/api-adapter-built-in", Adapter: "built-in/api-adapter-built-in",
IsEnabled: true,
} }
_, err = AddEnforcer(enforcer) _, err = AddEnforcer(enforcer)

View File

@ -30,7 +30,6 @@ type Model struct {
Description string `xorm:"varchar(100)" json:"description"` Description string `xorm:"varchar(100)" json:"description"`
ModelText string `xorm:"mediumtext" json:"modelText"` ModelText string `xorm:"mediumtext" json:"modelText"`
IsEnabled bool `json:"isEnabled"`
model.Model `xorm:"-" json:"-"` model.Model `xorm:"-" json:"-"`
} }

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import React from "react"; import React from "react";
import {Button, Card, Col, Input, InputNumber, Row, Select, Switch} from "antd"; import {Button, Card, Col, Input, InputNumber, Row, Select} from "antd";
import * as AdapterBackend from "./backend/AdapterBackend"; import * as AdapterBackend from "./backend/AdapterBackend";
import * as OrganizationBackend from "./backend/OrganizationBackend"; import * as OrganizationBackend from "./backend/OrganizationBackend";
import * as Setting from "./Setting"; import * as Setting from "./Setting";
@ -246,16 +246,6 @@ class AdapterEditPage extends React.Component {
}>{i18next.t("syncer:Test DB Connection")}</Button> }>{i18next.t("syncer:Test DB Connection")}</Button>
</Col> </Col>
</Row> </Row>
<Row style={{marginTop: "20px"}} >
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 19 : 2}>
{Setting.getLabel(i18next.t("general:Is enabled"), i18next.t("general:Is enabled - Tooltip"))} :
</Col>
<Col span={1} >
<Switch checked={this.state.adapter.isEnabled} onChange={checked => {
this.updateAdapterField("isEnabled", checked);
}} />
</Col>
</Row>
</Card> </Card>
); );
} }

View File

@ -14,7 +14,7 @@
import React from "react"; import React from "react";
import {Link} from "react-router-dom"; import {Link} from "react-router-dom";
import {Button, Switch, Table} from "antd"; import {Button, Table} from "antd";
import moment from "moment"; import moment from "moment";
import * as Setting from "./Setting"; import * as Setting from "./Setting";
import * as AdapterBackend from "./backend/AdapterBackend"; import * as AdapterBackend from "./backend/AdapterBackend";
@ -38,7 +38,6 @@ class AdapterListPage extends BaseListPage {
databaseType: "mysql", databaseType: "mysql",
database: "dbName", database: "dbName",
table: "tableName", table: "tableName",
isEnabled: false,
}; };
} }
@ -183,18 +182,6 @@ class AdapterListPage extends BaseListPage {
width: "120px", width: "120px",
sorter: true, sorter: true,
}, },
{
title: i18next.t("general:Is enabled"),
dataIndex: "isEnabled",
key: "isEnabled",
width: "120px",
sorter: true,
render: (text, record, index) => {
return (
<Switch disabled checkedChildren="ON" unCheckedChildren="OFF" checked={text} />
);
},
},
{ {
title: i18next.t("general:Action"), title: i18next.t("general:Action"),
dataIndex: "", dataIndex: "",

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import React from "react"; import React from "react";
import {Button, Card, Col, Input, Row, Select, Switch} from "antd"; import {Button, Card, Col, Input, Row, Select} from "antd";
import * as AdapterBackend from "./backend/AdapterBackend"; import * as AdapterBackend from "./backend/AdapterBackend";
import * as EnforcerBackend from "./backend/EnforcerBackend"; import * as EnforcerBackend from "./backend/EnforcerBackend";
import * as ModelBackend from "./backend/ModelBackend"; import * as ModelBackend from "./backend/ModelBackend";
@ -194,16 +194,6 @@ class EnforcerEditPage extends React.Component {
<PolicyTable enforcer={this.state.enforcer} modelCfg={this.state.enforcer?.modelCfg} mode={this.state.mode} /> <PolicyTable enforcer={this.state.enforcer} modelCfg={this.state.enforcer?.modelCfg} mode={this.state.mode} />
</Col> </Col>
</Row> </Row>
<Row style={{marginTop: "20px"}} >
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 19 : 2}>
{Setting.getLabel(i18next.t("general:Is enabled"), i18next.t("general:Is enabled - Tooltip"))} :
</Col>
<Col span={1} >
<Switch checked={this.state.enforcer.isEnabled} onChange={checked => {
this.updateEnforcerField("isEnabled", checked);
}} />
</Col>
</Row>
</Card> </Card>
); );
} }

View File

@ -14,7 +14,7 @@
import React from "react"; import React from "react";
import {Link} from "react-router-dom"; import {Link} from "react-router-dom";
import {Button, Switch, Table} from "antd"; import {Button, Table} from "antd";
import moment from "moment"; import moment from "moment";
import * as Setting from "./Setting"; import * as Setting from "./Setting";
import * as EnforcerBackend from "./backend/EnforcerBackend"; import * as EnforcerBackend from "./backend/EnforcerBackend";
@ -31,7 +31,6 @@ class EnforcerListPage extends BaseListPage {
name: `enforcer_${randomName}`, name: `enforcer_${randomName}`,
createdTime: moment().format(), createdTime: moment().format(),
displayName: `New Enforcer - ${randomName}`, displayName: `New Enforcer - ${randomName}`,
isEnabled: true,
}; };
} }
@ -152,18 +151,6 @@ class EnforcerListPage extends BaseListPage {
); );
}, },
}, },
{
title: i18next.t("general:Is enabled"),
dataIndex: "isEnabled",
key: "isEnabled",
width: "120px",
sorter: true,
render: (text, record, index) => {
return (
<Switch disabled checkedChildren="ON" unCheckedChildren="OFF" checked={text} />
);
},
},
{ {
title: i18next.t("general:Action"), title: i18next.t("general:Action"),
dataIndex: "", dataIndex: "",

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import React from "react"; import React from "react";
import {Button, Card, Col, Input, Row, Select, Switch} from "antd"; import {Button, Card, Col, Input, Row, Select} from "antd";
import * as ModelBackend from "./backend/ModelBackend"; import * as ModelBackend from "./backend/ModelBackend";
import * as OrganizationBackend from "./backend/OrganizationBackend"; import * as OrganizationBackend from "./backend/OrganizationBackend";
import * as Setting from "./Setting"; import * as Setting from "./Setting";
@ -161,16 +161,6 @@ class ModelEditPage extends React.Component {
</div> </div>
</Col> </Col>
</Row> </Row>
<Row style={{marginTop: "20px"}} >
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 19 : 2}>
{Setting.getLabel(i18next.t("general:Is enabled"), i18next.t("general:Is enabled - Tooltip"))} :
</Col>
<Col span={1} >
<Switch checked={this.state.model.isEnabled} onChange={checked => {
this.updateModelField("isEnabled", checked);
}} />
</Col>
</Row>
</Card> </Card>
); );
} }

View File

@ -13,8 +13,9 @@
// limitations under the License. // limitations under the License.
import React from "react"; import React from "react";
import {Controlled as CodeMirror} from "react-codemirror2";
import {Link} from "react-router-dom"; import {Link} from "react-router-dom";
import {Button, Switch, Table} from "antd"; import {Button, Popover, Table} from "antd";
import moment from "moment"; import moment from "moment";
import * as Setting from "./Setting"; import * as Setting from "./Setting";
import * as ModelBackend from "./backend/ModelBackend"; import * as ModelBackend from "./backend/ModelBackend";
@ -47,7 +48,6 @@ class ModelListPage extends BaseListPage {
createdTime: moment().format(), createdTime: moment().format(),
displayName: `New Model - ${randomName}`, displayName: `New Model - ${randomName}`,
modelText: rbacModel, modelText: rbacModel,
isEnabled: true,
}; };
} }
@ -91,7 +91,7 @@ class ModelListPage extends BaseListPage {
title: i18next.t("general:Name"), title: i18next.t("general:Name"),
dataIndex: "name", dataIndex: "name",
key: "name", key: "name",
width: "150px", width: "180px",
fixed: "left", fixed: "left",
sorter: true, sorter: true,
...this.getColumnSearchProps("name"), ...this.getColumnSearchProps("name"),
@ -107,7 +107,7 @@ class ModelListPage extends BaseListPage {
title: i18next.t("general:Organization"), title: i18next.t("general:Organization"),
dataIndex: "owner", dataIndex: "owner",
key: "owner", key: "owner",
width: "120px", width: "180px",
sorter: true, sorter: true,
...this.getColumnSearchProps("owner"), ...this.getColumnSearchProps("owner"),
render: (text, record, index) => { render: (text, record, index) => {
@ -122,7 +122,7 @@ class ModelListPage extends BaseListPage {
title: i18next.t("general:Created time"), title: i18next.t("general:Created time"),
dataIndex: "createdTime", dataIndex: "createdTime",
key: "createdTime", key: "createdTime",
width: "160px", width: "180px",
sorter: true, sorter: true,
render: (text, record, index) => { render: (text, record, index) => {
return Setting.getFormattedDate(text); return Setting.getFormattedDate(text);
@ -137,14 +137,26 @@ class ModelListPage extends BaseListPage {
...this.getColumnSearchProps("displayName"), ...this.getColumnSearchProps("displayName"),
}, },
{ {
title: i18next.t("general:Is enabled"), title: i18next.t("model:Model text"),
dataIndex: "isEnabled", dataIndex: "modelText",
key: "isEnabled", key: "modelText",
width: "120px", // width: "180px",
sorter: true, sorter: true,
render: (text, record, index) => { render: (text, record, index) => {
return ( return (
<Switch disabled checkedChildren="ON" unCheckedChildren="OFF" checked={text} /> <Popover placement="topRight" content={() => {
return (
<CodeMirror
value={text}
options={{mode: "properties", theme: "default"}}
onBeforeChange={(editor, data, value) => {}}
/>
);
}} title="" trigger="hover">
{
Setting.getShortText(text, 100)
}
</Popover>
); );
}, },
}, },
@ -152,7 +164,7 @@ class ModelListPage extends BaseListPage {
title: i18next.t("general:Action"), title: i18next.t("general:Action"),
dataIndex: "", dataIndex: "",
key: "op", key: "op",
width: "170px", width: "180px",
fixed: (Setting.isMobile()) ? "false" : "right", fixed: (Setting.isMobile()) ? "false" : "right",
render: (text, record, index) => { render: (text, record, index) => {
return ( return (

View File

@ -14,7 +14,7 @@
import React from "react"; import React from "react";
import {DeleteOutlined, EditOutlined} from "@ant-design/icons"; import {DeleteOutlined, EditOutlined} from "@ant-design/icons";
import {Button, Input, Popconfirm, Select, Table, Tooltip} from "antd"; import {Button, Input, Select, Table, Tooltip} from "antd";
import * as Setting from "../Setting"; import * as Setting from "../Setting";
import * as AdapterBackend from "../backend/AdapterBackend"; import * as AdapterBackend from "../backend/AdapterBackend";
import i18next from "i18next"; import i18next from "i18next";
@ -176,7 +176,7 @@ class PolicyTable extends React.Component {
const editing = this.isEditing(index); const editing = this.isEditing(index);
return ( return (
editing ? editing ?
<Select options={Object.keys(this.props.modelCfg).map(item => Setting.getOption(item, item))} value={text} onChange={value => { <Select size={"small"} style={{width: "60px"}} options={Object.keys(this.props.modelCfg).reverse().map(item => Setting.getOption(item, item))} value={text} onChange={value => {
this.updateField(table, index, "Ptype", value); this.updateField(table, index, "Ptype", value);
}} /> }} />
: text : text
@ -196,7 +196,7 @@ class PolicyTable extends React.Component {
const editing = this.isEditing(index); const editing = this.isEditing(index);
return ( return (
editing ? editing ?
<Input value={text} onChange={e => { <Input size={"small"} value={text} onChange={e => {
this.updateField(table, index, columnKeys[i], e.target.value); this.updateField(table, index, columnKeys[i], e.target.value);
}} /> }} />
: text : text
@ -209,17 +209,17 @@ class PolicyTable extends React.Component {
title: i18next.t("general:Action"), title: i18next.t("general:Action"),
dataIndex: "", dataIndex: "",
key: "op", key: "op",
width: "100px", width: "130px",
render: (text, record, index) => { render: (text, record, index) => {
const editable = this.isEditing(index); const editable = this.isEditing(index);
return editable ? ( return editable ? (
<span> <span>
<Button style={{marginRight: 8}} onClick={() => this.save(table, index)}> <Button style={{marginRight: "10px"}} size={"small"} type={"primary"} onClick={() => this.save(table, index)}>
Save {i18next.t("general:Save")}
</Button>
<Button size={"small"} onClick={() => this.cancel(table, index)}>
{i18next.t("general:Cancel")}
</Button> </Button>
<Popconfirm title="Sure to cancel?" onConfirm={() => this.cancel(table, index)}>
<a>Cancel</a>
</Popconfirm>
</span> </span>
) : ( ) : (
<div> <div>
@ -257,7 +257,7 @@ class PolicyTable extends React.Component {
render() { render() {
return ( return (
<React.Fragment> <React.Fragment>
<Button type="primary" disabled={this.state.editingIndex !== ""} onClick={() => {this.getPolicies();}}> <Button style={{marginBottom: "10px", width: "150px"}} type="primary" disabled={this.state.editingIndex !== ""} onClick={() => {this.getPolicies();}}>
{i18next.t("general:Sync")} {i18next.t("general:Sync")}
</Button> </Button>
{ {