Skip to content

Commit 14f7bfc

Browse files
committed
feat: add assign org role permission
1 parent e3647cb commit 14f7bfc

File tree

4 files changed

+162
-154
lines changed

4 files changed

+162
-154
lines changed

site/src/contexts/auth/permissions.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const checks = {
1717
viewAnyGroup: "viewAnyGroup",
1818
createGroup: "createGroup",
1919
viewAllLicenses: "viewAllLicenses",
20+
assignOrgRole: "assignOrgRole",
2021
} as const;
2122

2223
export const permissionsToCheck = {
@@ -131,6 +132,12 @@ export const permissionsToCheck = {
131132
},
132133
action: "read",
133134
},
135+
[checks.assignOrgRole]: {
136+
object: {
137+
resource_type: "assign_org_role",
138+
},
139+
action: "create",
140+
},
134141
} as const;
135142

136143
export type Permissions = Record<keyof typeof permissionsToCheck, boolean>;

site/src/pages/ManagementSettingsPage/CustomRolesPage/CustomRolesPage.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import CustomRolesPageView from "./CustomRolesPageView";
2222

2323
export const CustomRolesPage: FC = () => {
2424
const { permissions } = useAuthenticated();
25-
const { createGroup: canCreateGroup } = permissions;
25+
const { assignOrgRole: canAssignOrgRole } = permissions;
2626
const {
2727
multiple_organizations: organizationsEnabled,
28-
template_rbac: isTemplateRBACEnabled,
28+
custom_roles: isCustomRolesEnabled,
2929
} = useFeatureVisibility();
3030
const { experiments } = useDashboard();
3131
const location = useLocation();
@@ -62,7 +62,7 @@ export const CustomRolesPage: FC = () => {
6262
<PageHeader
6363
actions={
6464
<>
65-
{canCreateGroup && isTemplateRBACEnabled && (
65+
{canAssignOrgRole && isCustomRolesEnabled && (
6666
<Button
6767
component={RouterLink}
6868
startIcon={<GroupAdd />}
@@ -79,8 +79,8 @@ export const CustomRolesPage: FC = () => {
7979

8080
<CustomRolesPageView
8181
roles={organizationRolesQuery.data}
82-
canCreateGroup={canCreateGroup}
83-
isTemplateRBACEnabled={isTemplateRBACEnabled}
82+
canAssignOrgRole={canAssignOrgRole}
83+
isCustomRolesEnabled={isCustomRolesEnabled}
8484
/>
8585
</>
8686
);

site/src/pages/ManagementSettingsPage/CustomRolesPage/CustomRolesPageView.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ import { docs } from "utils/docs";
2929

3030
export type CustomRolesPageViewProps = {
3131
roles: Role[] | undefined;
32-
canCreateGroup: boolean;
33-
isTemplateRBACEnabled: boolean;
32+
canAssignOrgRole: boolean;
33+
isCustomRolesEnabled: boolean;
3434
};
3535

3636
// const filter = createFilterOptions<Role>();
3737

3838
export const CustomRolesPageView: FC<CustomRolesPageViewProps> = ({
3939
roles,
40-
canCreateGroup,
41-
isTemplateRBACEnabled,
40+
canAssignOrgRole,
41+
isCustomRolesEnabled,
4242
}) => {
4343
const isLoading = Boolean(roles === undefined);
4444
const isEmpty = Boolean(roles && roles.length === 0);
4545
// const [selectedRole, setSelectedRole] = useState<Role | null>(null);
46-
46+
console.log({ roles });
4747
return (
4848
<>
4949
<ChooseOne>
50-
<Cond condition={!isTemplateRBACEnabled}>
50+
<Cond condition={!isCustomRolesEnabled}>
5151
<Paywall
5252
message="Custom Roles"
5353
description="Organize users into groups with restricted access to templates. You need an Enterprise license to use this feature."
@@ -77,19 +77,19 @@ export const CustomRolesPageView: FC<CustomRolesPageViewProps> = ({
7777
<EmptyState
7878
message="No groups yet"
7979
description={
80-
canCreateGroup
81-
? "Create your first group"
82-
: "You don't have permission to create a group"
80+
canAssignOrgRole
81+
? "Create your first custom role"
82+
: "You don't have permission to create a custom role"
8383
}
8484
cta={
85-
canCreateGroup && (
85+
canAssignOrgRole && (
8686
<Button
8787
component={RouterLink}
8888
to="create"
8989
startIcon={<AddOutlined />}
9090
variant="contained"
9191
>
92-
Create group
92+
Create custom role
9393
</Button>
9494
)
9595
}

0 commit comments

Comments
 (0)