From f9cc6ed0642b86dd75af5a8bb851c530209bb474 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sun, 24 Sep 2023 10:17:18 +0800 Subject: [PATCH] Add groups to role --- object/role.go | 1 + web/src/RoleEditPage.js | 32 ++++++++++++++++++++++++++++++-- web/src/RoleListPage.js | 12 ++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/object/role.go b/object/role.go index 90622425..77e2a528 100644 --- a/object/role.go +++ b/object/role.go @@ -32,6 +32,7 @@ type Role struct { Description string `xorm:"varchar(100)" json:"description"` Users []string `xorm:"mediumtext" json:"users"` + Groups []string `xorm:"mediumtext" json:"groups"` Roles []string `xorm:"mediumtext" json:"roles"` Domains []string `xorm:"mediumtext" json:"domains"` IsEnabled bool `json:"isEnabled"` diff --git a/web/src/RoleEditPage.js b/web/src/RoleEditPage.js index 27f44ba0..3b292adf 100644 --- a/web/src/RoleEditPage.js +++ b/web/src/RoleEditPage.js @@ -14,11 +14,12 @@ import React from "react"; import {Button, Card, Col, Input, Row, Select, Switch} from "antd"; -import * as RoleBackend from "./backend/RoleBackend"; import * as OrganizationBackend from "./backend/OrganizationBackend"; +import * as UserBackend from "./backend/UserBackend"; +import * as GroupBackend from "./backend/GroupBackend"; +import * as RoleBackend from "./backend/RoleBackend"; import * as Setting from "./Setting"; import i18next from "i18next"; -import * as UserBackend from "./backend/UserBackend"; class RoleEditPage extends React.Component { constructor(props) { @@ -30,6 +31,7 @@ class RoleEditPage extends React.Component { role: null, organizations: [], users: [], + groups: [], roles: [], mode: props.location.mode !== undefined ? props.location.mode : "edit", }; @@ -57,6 +59,7 @@ class RoleEditPage extends React.Component { }); this.getUsers(this.state.organizationName); + this.getGroups(this.state.organizationName); this.getRoles(this.state.organizationName); }); } @@ -84,6 +87,20 @@ class RoleEditPage extends React.Component { }); } + getGroups(organizationName) { + GroupBackend.getGroups(organizationName) + .then((res) => { + if (res.status === "error") { + Setting.showMessage("error", res.msg); + return; + } + + this.setState({ + groups: res.data, + }); + }); + } + getRoles(organizationName) { RoleBackend.getRoles(organizationName) .then((res) => { @@ -176,6 +193,17 @@ class RoleEditPage extends React.Component { /> + + + {Setting.getLabel(i18next.t("role:Sub groups"), i18next.t("role:Sub groups - Tooltip"))} : + + +