-
Notifications
You must be signed in to change notification settings - Fork 466
chore: permission types #6417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/edit-versioned-change-request
Are you sure you want to change the base?
chore: permission types #6417
Changes from all commits
a89df89
ae5582e
0313fd7
7b4029c
6bc28f1
512696b
2afaba5
5907ed3
a1825eb
39fa2a4
fc49c2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,11 @@ import intersection from 'lodash/intersection' | |
| import { cloneDeep } from 'lodash' | ||
| import Utils from 'common/utils/utils' | ||
| import Constants from 'common/constants' | ||
| import { | ||
| Permission as PermissionEnum, | ||
| PermissionDescriptions, | ||
| ProjectPermission, | ||
| } from 'common/types/permissions.types' | ||
|
|
||
| /** | ||
| * Props for the Permission component | ||
|
|
@@ -21,7 +26,7 @@ import Constants from 'common/constants' | |
| */ | ||
| type PermissionType = { | ||
| id: number | string | ||
| permission: string | ||
| permission: PermissionEnum | ||
|
Comment on lines
8
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: so the permission would directly be inferred and we can get invalid combinations directly |
||
| tags?: number[] | ||
| level: PermissionLevel | ||
| children: | ||
|
|
@@ -153,7 +158,18 @@ const Permission: FC<PermissionType> = ({ | |
| }) | ||
|
|
||
| const finalPermission = hasPermission || AccountStore.isAdmin() | ||
|
|
||
| let permissionDescriptionFunc: (perm: any) => any = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about renaming to something like |
||
| Constants.organisationPermissions | ||
| switch (level) { | ||
| case 'environment': | ||
| permissionDescriptionFunc = Constants.environmentPermissions | ||
| break | ||
| case 'project': | ||
| permissionDescriptionFunc = Constants.projectPermissions | ||
| break | ||
| default: | ||
| break | ||
| } | ||
| if (typeof children === 'function') { | ||
| const renderedChildren = children({ | ||
| isLoading, | ||
|
|
@@ -166,7 +182,10 @@ const Permission: FC<PermissionType> = ({ | |
|
|
||
| return Utils.renderWithPermission( | ||
| finalPermission, | ||
| permissionName || Constants.projectPermissions(permission), | ||
| permissionName || | ||
| permissionDescriptionFunc( | ||
| PermissionDescriptions[permission as ProjectPermission], | ||
| ), | ||
| renderedChildren, | ||
| ) | ||
| } | ||
|
|
@@ -178,7 +197,10 @@ const Permission: FC<PermissionType> = ({ | |
| if (showTooltip) { | ||
| return Utils.renderWithPermission( | ||
| finalPermission, | ||
| permissionName || Constants.projectPermissions(permission), | ||
| permissionName || | ||
| permissionDescriptionFunc( | ||
| PermissionDescriptions[permission as ProjectPermission], | ||
| ), | ||
|
Comment on lines
+200
to
+203
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we put this into a variable and re-use it in the 2 places? |
||
| children, | ||
| ) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // Organization Permissions | ||
| export enum OrganisationPermission { | ||
| CREATE_PROJECT = 'CREATE_PROJECT', | ||
| MANAGE_USERS = 'MANAGE_USERS', | ||
| MANAGE_USER_GROUPS = 'MANAGE_USER_GROUPS', | ||
| } | ||
| export const OrganisationPermissionDescriptions = { | ||
| [OrganisationPermission.CREATE_PROJECT]: 'Create project', | ||
| [OrganisationPermission.MANAGE_USERS]: 'Manage users', | ||
| [OrganisationPermission.MANAGE_USER_GROUPS]: 'Manage user groups', | ||
| } as const | ||
|
|
||
| export type OrganisationPermissionDescription = | ||
| | (typeof OrganisationPermissionDescriptions)[keyof typeof OrganisationPermissionDescriptions] | ||
| | typeof ADMIN_PERMISSION_DESCRIPTION | ||
|
|
||
| export const ADMIN_PERMISSION = 'ADMIN' as const | ||
| export const ADMIN_PERMISSION_DESCRIPTION = 'Administrator' as const | ||
|
|
||
| // Project Permissions | ||
| export enum ProjectPermission { | ||
| VIEW_PROJECT = 'VIEW_PROJECT', | ||
| CREATE_ENVIRONMENT = 'CREATE_ENVIRONMENT', | ||
| DELETE_FEATURE = 'DELETE_FEATURE', | ||
| CREATE_FEATURE = 'CREATE_FEATURE', | ||
| MANAGE_SEGMENTS = 'MANAGE_SEGMENTS', | ||
| VIEW_AUDIT_LOG = 'VIEW_AUDIT_LOG', | ||
| MANAGE_TAGS = 'MANAGE_TAGS', | ||
| MANAGE_PROJECT_LEVEL_CHANGE_REQUESTS = 'MANAGE_PROJECT_LEVEL_CHANGE_REQUESTS', | ||
| APPROVE_PROJECT_LEVEL_CHANGE_REQUESTS = 'APPROVE_PROJECT_LEVEL_CHANGE_REQUESTS', | ||
| CREATE_PROJECT_LEVEL_CHANGE_REQUESTS = 'CREATE_PROJECT_LEVEL_CHANGE_REQUESTS', | ||
| } | ||
| export const ProjectPermissionDescriptions = { | ||
| [ProjectPermission.VIEW_PROJECT]: 'View project', | ||
| [ProjectPermission.CREATE_ENVIRONMENT]: 'Create environment', | ||
| [ProjectPermission.DELETE_FEATURE]: 'Delete feature', | ||
| [ProjectPermission.CREATE_FEATURE]: 'Create feature', | ||
| [ProjectPermission.MANAGE_SEGMENTS]: 'Manage segments', | ||
| [ProjectPermission.VIEW_AUDIT_LOG]: 'View audit log', | ||
| [ProjectPermission.MANAGE_TAGS]: 'Manage tags', | ||
| [ProjectPermission.MANAGE_PROJECT_LEVEL_CHANGE_REQUESTS]: | ||
| 'Manage project level change requests', | ||
| [ProjectPermission.APPROVE_PROJECT_LEVEL_CHANGE_REQUESTS]: | ||
| 'Approve project level change requests', | ||
| [ProjectPermission.CREATE_PROJECT_LEVEL_CHANGE_REQUESTS]: | ||
| 'Create project level change requests', | ||
| } as const | ||
|
|
||
| export type ProjectPermissionDescription = | ||
| | (typeof ProjectPermissionDescriptions)[keyof typeof ProjectPermissionDescriptions] | ||
| | typeof ADMIN_PERMISSION_DESCRIPTION | ||
|
|
||
| // Environment Permissions | ||
| export enum EnvironmentPermission { | ||
| VIEW_ENVIRONMENT = 'VIEW_ENVIRONMENT', | ||
| UPDATE_FEATURE_STATE = 'UPDATE_FEATURE_STATE', | ||
| MANAGE_IDENTITIES = 'MANAGE_IDENTITIES', | ||
| CREATE_CHANGE_REQUEST = 'CREATE_CHANGE_REQUEST', | ||
| APPROVE_CHANGE_REQUEST = 'APPROVE_CHANGE_REQUEST', | ||
| VIEW_IDENTITIES = 'VIEW_IDENTITIES', | ||
| MANAGE_SEGMENT_OVERRIDES = 'MANAGE_SEGMENT_OVERRIDES', | ||
| } | ||
| export const EnvironmentPermissionDescriptions = { | ||
| [EnvironmentPermission.VIEW_ENVIRONMENT]: 'View environment', | ||
| [EnvironmentPermission.UPDATE_FEATURE_STATE]: 'Update feature state', | ||
| [EnvironmentPermission.MANAGE_IDENTITIES]: 'Manage identities', | ||
| [EnvironmentPermission.CREATE_CHANGE_REQUEST]: 'Create change request', | ||
| [EnvironmentPermission.APPROVE_CHANGE_REQUEST]: 'Approve change request', | ||
| [EnvironmentPermission.VIEW_IDENTITIES]: 'View identities', | ||
| [EnvironmentPermission.MANAGE_SEGMENT_OVERRIDES]: 'Manage segment overrides', | ||
| } as const | ||
|
|
||
| export type EnvironmentPermissionDescription = | ||
| | (typeof EnvironmentPermissionDescriptions)[keyof typeof EnvironmentPermissionDescriptions] | ||
| | typeof ADMIN_PERMISSION_DESCRIPTION | ||
|
|
||
| export type Permission = | ||
| | OrganisationPermission | ||
| | ProjectPermission | ||
| | EnvironmentPermission | ||
| | typeof ADMIN_PERMISSION | ||
|
|
||
| // Combined permission descriptions record | ||
| export const PermissionDescriptions = { | ||
| ...OrganisationPermissionDescriptions, | ||
| ...ProjectPermissionDescriptions, | ||
| ...EnvironmentPermissionDescriptions, | ||
| [ADMIN_PERMISSION]: ADMIN_PERMISSION_DESCRIPTION, | ||
| } as const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, can't we use directly the enum here and get the description within this function ?
const description = ProjectPermissionDescriptions[perm];