Skip to content

Commit 423ff84

Browse files
authored
Merge pull request #594 from devtron-labs/feat/access-manager
feat: access manager
2 parents 5e82ec5 + 5199281 commit 423ff84

File tree

19 files changed

+115
-39
lines changed

19 files changed

+115
-39
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ src/Common/Drawer/Drawer.tsx
3030
src/Common/Grid/Grid.tsx
3131
src/Common/Helper.tsx
3232
src/Common/Hooks/UseClickOutside/UseClickOutside.tsx
33-
src/Common/Hooks/UseSuperAdmin/UseSuperAdmin.tsx
3433
src/Common/Hooks/UseWindowSize/UseWindowSize.tsx
3534
src/Common/ImageTags.tsx
3635
src/Common/InfoColorBar/InfoColourbar.tsx

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.8.6",
3+
"version": "1.8.7",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

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/AddCDButton/AddCDButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const TooltipContent = ({ tooltipContent }: TooltipContentProps) => {
2222
if (tooltipContent) {
2323
return (
2424
<div className="dc__white-space-pre-wrap">
25-
<p className="m-0 cn-0 fs-12 fw-6 lh-18">Click to add</p>
25+
<p className="m-0 fs-12 fw-6 lh-18">Click to add</p>
2626

2727
{tooltipContent}
2828
</div>

src/Common/CodeEditor/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export interface CodeEditorHeaderComposition {
101101
Clipboard?: React.FC<any>
102102
}
103103

104-
export type ActionTypes = 'changeLanguage' | 'setDiff' | 'setTheme' | 'setCode' | 'setDefaultCode' | 'setHeight'
104+
type ActionTypes = 'changeLanguage' | 'setDiff' | 'setTheme' | 'setCode' | 'setDefaultCode' | 'setHeight'
105105

106106
export interface Action {
107107
type: ActionTypes

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 renamed to src/Common/Hooks/UseGetUserRoles/UseGetUserRoles.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,39 @@
1414
* limitations under the License.
1515
*/
1616

17-
import React, { useEffect, useState } from 'react'
17+
import { useEffect, useState } from 'react'
1818
import { getUserRole } from '../../Common.service'
19-
import { useSuperAdminType } from './types'
19+
import { UseGetUserRolesType } from './types'
2020
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 {UseGetUserRolesType} isSuperAdmin, canManageAllAccess
2525
*/
26-
export const useSuperAdmin = (): useSuperAdminType => {
27-
const [isSuperAdmin, setSuperAdmin] = useState<boolean>(false)
26+
const useGetUserRoles = (): UseGetUserRolesType => {
27+
const [result, setResult] = useState<UseGetUserRolesType>({
28+
isSuperAdmin: false,
29+
canManageAllAccess: false,
30+
hasManagerPermissions: false,
31+
})
2832

2933
useEffect(() => {
3034
getUserRole()
31-
.then((response) => {
32-
setSuperAdmin(response.result.superAdmin ?? false)
35+
.then(({ result: apiResult }) => {
36+
const hasManagerPermissions = apiResult.roles.some((role) => role.startsWith('role:manager'))
37+
38+
setResult({
39+
isSuperAdmin: apiResult.superAdmin ?? false,
40+
canManageAllAccess: apiResult.canManageAllAccess ?? false,
41+
hasManagerPermissions,
42+
})
3343
})
3444
.catch((error) => {
3545
showError(error)
3646
})
3747
}, [])
3848

39-
return { isSuperAdmin }
49+
return result
4050
}
51+
52+
export default useGetUserRoles
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as useGetUserRoles } from './UseGetUserRoles'

0 commit comments

Comments
 (0)