Skip to content

Commit 5f84a68

Browse files
committed
feat: access manager
1 parent a219b58 commit 5f84a68

File tree

8 files changed

+60
-15
lines changed

8 files changed

+60
-15
lines changed

src/Assets/IconV2/ic-crown.svg

Lines changed: 3 additions & 0 deletions
Loading

src/Assets/IconV2/ic-user-key.svg

Lines changed: 4 additions & 0 deletions
Loading

src/Common/Common.service.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
CDMaterialType,
5050
GlobalVariableDTO,
5151
GlobalVariableOptionType,
52+
UserRole,
5253
} from './Types'
5354
import { ApiResourceType, STAGE_MAP } from '../Pages'
5455
import { RefVariableType, VariableTypeFormat } from './CIPipeline.Types'
@@ -70,13 +71,6 @@ export const getTeamListMin = (): Promise<TeamList> => {
7071
})
7172
}
7273

73-
interface UserRole extends ResponseType {
74-
result?: {
75-
roles: string[]
76-
superAdmin: boolean
77-
}
78-
}
79-
8074
export const SourceTypeMap = {
8175
BranchFixed: 'SOURCE_TYPE_BRANCH_FIXED',
8276
WEBHOOK: 'WEBHOOK',

src/Common/Hooks/UseSuperAdmin/UseSuperAdmin.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@ import { showError } from '../../Helper'
2121

2222
/**
2323
* @description It will return isSuperAdmin and would be set to false by default, might need few optimizations like dep, etc
24-
* @returns {useSuperAdminType} isSuperAdmin
24+
* @returns {useSuperAdminType} isSuperAdmin, canManageAllAccess
2525
*/
2626
export const useSuperAdmin = (): useSuperAdminType => {
27-
const [isSuperAdmin, setSuperAdmin] = useState<boolean>(false)
27+
const [result, setResult] = useState<useSuperAdminType>({ isSuperAdmin: false, canManageAllAccess: false })
2828

2929
useEffect(() => {
3030
getUserRole()
31-
.then((response) => {
32-
setSuperAdmin(response.result.superAdmin ?? false)
31+
.then(({ result }) => {
32+
setResult({
33+
isSuperAdmin: result.superAdmin ?? false,
34+
canManageAllAccess: result.canManageAllAccess ?? false,
35+
})
3336
})
3437
.catch((error) => {
3538
showError(error)
3639
})
3740
}, [])
3841

39-
return { isSuperAdmin }
42+
return result
4043
}

src/Common/Hooks/UseSuperAdmin/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@
1616

1717
export interface useSuperAdminType {
1818
isSuperAdmin: boolean
19+
/**
20+
* ENT Only
21+
* User can give access to all other users
22+
*/
23+
canManageAllAccess?: boolean
1924
}

src/Common/Types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,3 +1074,15 @@ export type GlobalVariableOptionType = Omit<GlobalVariableDTO, 'name'> & {
10741074
value: string
10751075
variableType: Extract<RefVariableType, RefVariableType.GLOBAL>
10761076
}
1077+
1078+
export interface UserRole extends ResponseType {
1079+
result?: {
1080+
roles: string[]
1081+
superAdmin: boolean
1082+
/**
1083+
* ENT Only
1084+
* Defines if a user is access manager and can manage all access
1085+
*/
1086+
canManageAllAccess?: boolean
1087+
}
1088+
}

src/Shared/Components/Icon/Icon.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ReactComponent as ICCircleLoader } from '@IconsV2/ic-circle-loader.svg'
1212
import { ReactComponent as ICClock } from '@IconsV2/ic-clock.svg'
1313
import { ReactComponent as ICCloseSmall } from '@IconsV2/ic-close-small.svg'
1414
import { ReactComponent as ICContainer } from '@IconsV2/ic-container.svg'
15+
import { ReactComponent as ICCrown } from '@IconsV2/ic-crown.svg'
1516
import { ReactComponent as ICDockerhub } from '@IconsV2/ic-dockerhub.svg'
1617
import { ReactComponent as ICEcr } from '@IconsV2/ic-ecr.svg'
1718
import { ReactComponent as ICEnv } from '@IconsV2/ic-env.svg'
@@ -41,6 +42,7 @@ import { ReactComponent as ICSuccess } from '@IconsV2/ic-success.svg'
4142
import { ReactComponent as ICSuspended } from '@IconsV2/ic-suspended.svg'
4243
import { ReactComponent as ICTimeoutTwoDash } from '@IconsV2/ic-timeout-two-dash.svg'
4344
import { ReactComponent as ICUnknown } from '@IconsV2/ic-unknown.svg'
45+
import { ReactComponent as ICUserKey } from '@IconsV2/ic-user-key.svg'
4446
import { ReactComponent as ICWarning } from '@IconsV2/ic-warning.svg'
4547

4648
// eslint-disable-next-line no-restricted-imports
@@ -60,6 +62,7 @@ export const iconMap = {
6062
'ic-clock': ICClock,
6163
'ic-close-small': ICCloseSmall,
6264
'ic-container': ICContainer,
65+
'ic-crown': ICCrown,
6366
'ic-dockerhub': ICDockerhub,
6467
'ic-ecr': ICEcr,
6568
'ic-env': ICEnv,
@@ -89,6 +92,7 @@ export const iconMap = {
8992
'ic-suspended': ICSuspended,
9093
'ic-timeout-two-dash': ICTimeoutTwoDash,
9194
'ic-unknown': ICUnknown,
95+
'ic-user-key': ICUserKey,
9296
'ic-warning': ICWarning,
9397
}
9498

src/Shared/types.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
PluginType,
3131
} from '../Common'
3232
import { BASE_CONFIGURATION_ENV_ID, EnvironmentTypeEnum, PatchOperationType } from './constants'
33+
import { SelectPickerOptionType } from './Components'
3334

3435
export enum EnvType {
3536
CHART = 'helm_charts',
@@ -761,10 +762,29 @@ export type MetaPossibleRoles = Record<
761762

762763
export interface CustomRoleAndMeta {
763764
customRoles: CustomRoles[]
764-
possibleRolesMeta: MetaPossibleRoles
765-
possibleRolesMetaForHelm: MetaPossibleRoles
765+
possibleRolesMetaForDevtron: MetaPossibleRoles
766+
possibleJobRoles: SelectPickerOptionType<string>[]
766767
possibleRolesMetaForCluster: MetaPossibleRoles
767-
possibleRolesMetaForJob: MetaPossibleRoles
768+
}
769+
770+
export interface UserRoleConfig {
771+
// can be '' if access manager has no base access
772+
baseRole: string
773+
/**
774+
* Only for devtron apps, ENT Only
775+
*/
776+
additionalRoles?: Set<string>
777+
/**
778+
* Only for devtron apps, ENT Only
779+
*/
780+
accessManagerRoles?: Set<string>
781+
}
782+
783+
export type RoleType = keyof UserRoleConfig
784+
785+
export type RoleSelectorOptionType = Pick<SelectPickerOptionType, 'label' | 'description'> & {
786+
value: string
787+
roleType: RoleType
768788
}
769789

770790
interface CommonTabArgsType {

0 commit comments

Comments
 (0)