Skip to content

Commit

Permalink
Merge pull request #1195 from lowcoder-org/super_admin_role
Browse files Browse the repository at this point in the history
added super admin role
  • Loading branch information
FalkWolsky authored Sep 27, 2024
2 parents fa14470 + 3582d7e commit 113c7b4
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 14 deletions.
7 changes: 5 additions & 2 deletions client/packages/lowcoder/src/constants/orgConstants.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { CommonSettingResponseData } from "api/commonSettingApi";
import { trans } from "i18n";

export const ADMIN_ROLE = "admin" || "super_admin";
export const ADMIN_ROLE = "admin";
export const SUPER_ADMIN_ROLE = "super_admin";
export const MEMBER_ROLE = "member";

export const NEW_ORG_PREFIX = trans("orgSettings.newOrg");

export const TacoRoles = [ADMIN_ROLE, MEMBER_ROLE] as const;
export const TacoRoles = [SUPER_ADMIN_ROLE, ADMIN_ROLE, MEMBER_ROLE] as const;
export type RoleIdType = typeof TacoRoles[number];
type RoleInfoType = Record<RoleIdType, { name: string; desc: string }>;

export const GroupRoleInfo: RoleInfoType = {
super_admin: { name: trans("memberSettings.superAdmin"), desc: trans("memberSettings.adminGroupRoleInfo") },
admin: { name: trans("memberSettings.admin"), desc: trans("memberSettings.adminGroupRoleInfo") },
member: { name: trans("memberSettings.member"), desc: trans("memberSettings.memberGroupRoleInfo"), },
};

export const OrgRoleInfo: RoleInfoType = {
super_admin: { name: trans("memberSettings.superAdmin"), desc: trans("memberSettings.adminGroupRoleInfo") },
admin: { name: trans("memberSettings.admin"), desc: trans("memberSettings.adminOrgRoleInfo") },
member: { name: trans("memberSettings.member"), desc: trans("memberSettings.memberOrgRoleInfo") },
};
Expand Down
1 change: 1 addition & 0 deletions client/packages/lowcoder/src/i18n/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,7 @@ export const de = {
...en.memberSettings,

"admin": "Verwaltung",
"superAdmin": "Super Admin",
"adminGroupRoleInfo": "Admin kann Gruppenmitglieder und Ressourcen verwalten",
"adminOrgRoleInfo": "Admins besitzen alle Ressourcen und können Gruppen verwalten.",
"member": "Mitglied",
Expand Down
1 change: 1 addition & 0 deletions client/packages/lowcoder/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,7 @@ export const en = {

"memberSettings": {
"admin": "Admin",
"superAdmin": "Super Admin",
"adminGroupRoleInfo": "Admin Can Manage Group Members and Resources",
"adminOrgRoleInfo": "Admins Own All Resources and Can Manage Groups.",
"member": "Member",
Expand Down
1 change: 1 addition & 0 deletions client/packages/lowcoder/src/i18n/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,7 @@ export const es = {
...en.memberSettings,

"admin": "Admin",
"superAdmin": "Súper administrador",
"adminGroupRoleInfo": "El administrador puede gestionar los miembros y recursos del grupo",
"adminOrgRoleInfo": "Los administradores son propietarios de todos los recursos y pueden gestionar grupos.",
"member": "Miembro",
Expand Down
1 change: 1 addition & 0 deletions client/packages/lowcoder/src/i18n/locales/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,7 @@ export const it = {
...en.memberSettings,

"admin": "Admin",
"superAdmin": "Super amministratore",
"adminGroupRoleInfo": "L'amministratore può gestire i membri e le risorse del gruppo",
"adminOrgRoleInfo": "Gli amministratori possiedono tutte le risorse e possono gestire i gruppi.",
"member": "Membro",
Expand Down
1 change: 1 addition & 0 deletions client/packages/lowcoder/src/i18n/locales/pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,7 @@ export const pt = {
...en.memberSettings,

"admin": "Administrador",
"superAdmin": "Superadministrador",
"adminGroupRoleInfo": "O administrador pode gerenciar membros do grupo e recursos",
"adminOrgRoleInfo": "Os administradores possuem todos os recursos e podem gerenciar grupos.",
"member": "Membro",
Expand Down
1 change: 1 addition & 0 deletions client/packages/lowcoder/src/i18n/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,7 @@ export const ru = {
...en.memberSettings,

"admin": "Администратор",
"superAdmin": "Суперадминистратор",
"adminGroupRoleInfo": "Администратор может управлять членами группы и ресурсами",
"adminOrgRoleInfo": "Администраторы владеют всеми ресурсами и могут управлять группами.",
"member": "Член",
Expand Down
1 change: 1 addition & 0 deletions client/packages/lowcoder/src/i18n/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,7 @@ export const zh: typeof en = {
memberSettings: {
...en.memberSettings,
admin: "管理员",
superAdmin: "超级管理员",
adminGroupRoleInfo: "管理员可以管理群组成员和资源",
adminOrgRoleInfo: "拥有所有资源并可以管理群组.",
member: "成员",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ADMIN_ROLE } from "constants/orgConstants";
import { ADMIN_ROLE, SUPER_ADMIN_ROLE } from "constants/orgConstants";
import { AddIcon, CustomModal, DangerIcon, EditPopover } from "lowcoder-design";
import { useDispatch, useSelector } from "react-redux";
import { createOrgAction, deleteOrgAction } from "redux/reduxActions/orgActions";
Expand Down Expand Up @@ -128,7 +128,10 @@ type DataItemInfo = {
function OrganizationSetting() {
const user = useSelector(getUser);
const orgs = user.orgs;
const adminOrgs = orgs.filter((org) => user.orgRoleMap.get(org.id) === ADMIN_ROLE);
const adminOrgs = orgs.filter((org) => {
const role = user.orgRoleMap.get(org.id);
return role === ADMIN_ROLE || role === SUPER_ADMIN_ROLE;
});
const orgCreateStatus = useSelector(getOrgCreateStatus);
const dispatch = useDispatch();
const sysConfig = useSelector(selectSystemConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function GroupUsersPermission(props: GroupPermissionProp) {
key="role"
render={(value, record: GroupUser) => (
<CustomSelect
style={{ width: "96px", height: "32px" }}
style={{ width: "140px", height: "32px" }}
dropdownStyle={{ width: "149px" }}
defaultValue={record.role}
key={record.role}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ADMIN_ROLE, OrgRoleInfo, OrgUser, TacoRoles } from "constants/orgConstants";
import { ADMIN_ROLE, OrgRoleInfo, OrgUser, SUPER_ADMIN_ROLE, TacoRoles } from "constants/orgConstants";
import { User } from "constants/userConstants";
import {
ArrowIcon,
Expand Down Expand Up @@ -65,14 +65,16 @@ type UsersPermissionProp = {
function OrgUsersPermission(props: UsersPermissionProp) {
const { Column } = TableStyled;
const { orgId, orgUsers, orgUsersFetching, currentUser } = props;
const adminCount = orgUsers.filter((user) => user.role === ADMIN_ROLE).length;
const adminCount = orgUsers.filter(
(user) => user.role === ADMIN_ROLE || user.role === SUPER_ADMIN_ROLE,
).length;
const sysConfig = useSelector(selectSystemConfig);
const dispatch = useDispatch();
const sortedOrgUsers = useMemo(() => {
return [...orgUsers].sort((a, b) => {
if (a.role === ADMIN_ROLE) {
if (a.role === ADMIN_ROLE || a.role === SUPER_ADMIN_ROLE) {
return -1;
} else if (b.role === ADMIN_ROLE) {
} else if (b.role === ADMIN_ROLE || a.role === SUPER_ADMIN_ROLE) {
return 1;
} else {
return b.joinTime - a.joinTime;
Expand Down Expand Up @@ -178,7 +180,7 @@ function OrgUsersPermission(props: UsersPermissionProp) {
className="role-table-cell"
render={(value, record: OrgUser) => (
<CustomSelect
style={{ width: "96px", height: "32px" }}
style={{ width: "140px", height: "32px" }}
dropdownStyle={{ width: "149px" }}
defaultValue={record.role}
key={record.role}
Expand Down
9 changes: 5 additions & 4 deletions client/packages/lowcoder/src/util/permissionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { ADMIN_ROLE} from "constants/orgConstants";
import { ADMIN_ROLE, SUPER_ADMIN_ROLE} from "constants/orgConstants";
import { ApplicationMeta } from "constants/applicationConstants";
import { User } from "constants/userConstants";


export function currentOrgAdmin(user: User) {
return user.orgRoleMap.get(user.currentOrgId) === ADMIN_ROLE;
export function currentOrgAdmin(user: User) {
const role = user.orgRoleMap.get(user.currentOrgId);
return role === ADMIN_ROLE || role === SUPER_ADMIN_ROLE;
}

export function currentOrgAdminOrDev(user: User) {
return user.orgDev || currentOrgAdmin(user);
}

export function isGroupAdmin(userGroupRole: string | undefined) {
return userGroupRole === ADMIN_ROLE;
return userGroupRole === ADMIN_ROLE || userGroupRole === SUPER_ADMIN_ROLE;
}

export function canManageApp(user: User, application?: ApplicationMeta) {
Expand Down

0 comments on commit 113c7b4

Please sign in to comment.