Skip to content

Commit 80bf204

Browse files
committed
feat: add terminal access in multi select roles i
n devtron and helm apps
1 parent 8d24214 commit 80bf204

File tree

17 files changed

+69
-65
lines changed

17 files changed

+69
-65
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"homepage": "/dashboard",
66
"dependencies": {
7-
"@devtron-labs/devtron-fe-common-lib": "0.5.0",
7+
"@devtron-labs/devtron-fe-common-lib": "0.5.0-beta-2",
88
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
99
"@rjsf/core": "^5.13.3",
1010
"@rjsf/utils": "^5.13.3",

src/Pages/GlobalConfigurations/Authorization/Shared/components/AppPermissions/AppPermissionDetail.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616

1717
/* eslint-disable jsx-a11y/label-has-associated-control */
18+
import { ACCESS_TYPE_MAP } from '@devtron-labs/devtron-fe-common-lib'
1819
import { ReactComponent as AddIcon } from '../../../../../../assets/icons/ic-add.svg'
19-
import { ACCESS_TYPE_MAP } from '../../../../../../config'
2020
import { usePermissionConfiguration } from '../PermissionConfigurationForm'
2121
import DirectPermission from './DirectPermission'
2222
import { getPermissionDetailRowClass } from './utils'

src/Pages/GlobalConfigurations/Authorization/Shared/components/AppPermissions/AppPermissions.component.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ import {
2525
TabGroup,
2626
useAsync,
2727
useMainContext,
28+
ACCESS_TYPE_MAP,
2829
} from '@devtron-labs/devtron-fe-common-lib'
2930
import { EntityTypes, ActionTypes } from '../../../constants'
30-
import { ACCESS_TYPE_MAP, HELM_APP_UNASSIGNED_PROJECT, SELECT_ALL_VALUE, SERVER_MODE } from '../../../../../../config'
31+
import { HELM_APP_UNASSIGNED_PROJECT, SELECT_ALL_VALUE, SERVER_MODE } from '../../../../../../config'
3132
import { importComponentFromFELibrary, mapByKey } from '../../../../../../components/common'
3233
import K8sPermissions from '../K8sObjectPermissions/K8sPermissions.component'
3334
import { apiGroupAll } from '../K8sObjectPermissions/utils'

src/Pages/GlobalConfigurations/Authorization/Shared/components/AppPermissions/DirectPermission.tsx

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ import {
2323
getIsRequestAborted,
2424
LoadingIndicator,
2525
ReactSelectInputAction,
26+
ACCESS_TYPE_MAP,
2627
} from '@devtron-labs/devtron-fe-common-lib'
2728
import Select, { components } from 'react-select'
2829
import Tippy from '@tippyjs/react'
2930
import { sortBySelected, importComponentFromFELibrary } from '../../../../../../components/common'
3031
import { getAllWorkflowsForAppNames } from '../../../../../../services/service'
31-
import { ACCESS_TYPE_MAP, HELM_APP_UNASSIGNED_PROJECT, SELECT_ALL_VALUE } from '../../../../../../config'
32+
import { HELM_APP_UNASSIGNED_PROJECT, SELECT_ALL_VALUE } from '../../../../../../config'
3233
import { ReactComponent as TrashIcon } from '../../../../../../assets/icons/ic-delete-interactive.svg'
3334
import { GroupHeading, Option as singleOption } from '../../../../../../components/v2/common/ReactSelect.utils'
3435
import { useAuthorizationContext } from '../../../AuthorizationProvider'
@@ -37,6 +38,7 @@ import {
3738
authorizationSelectStyles,
3839
EntityTypes,
3940
ARTIFACT_PROMOTER_ACTION,
41+
TERMINAL_EXEC_ACTION,
4042
} from '../../../constants'
4143
import { AppOption, ClusterValueContainer, ProjectValueContainer, ValueContainer, WorkflowGroupHeading } from './common'
4244
import {
@@ -80,6 +82,7 @@ const DirectPermission = ({
8082
const multiRole = permission.action.value.split(',')
8183
const doesConfigApproverRoleExist = multiRole.includes(CONFIG_APPROVER_ACTION.value)
8284
const doesArtifactPromoterRoleExist = multiRole.includes(ARTIFACT_PROMOTER_ACTION.value)
85+
const doesTerminalAccessRoleExist = multiRole.includes(TERMINAL_EXEC_ACTION.value)
8386

8487
const primaryActionRoleIndex = getPrimaryRoleIndex(multiRole, [
8588
CONFIG_APPROVER_ACTION.value,
@@ -91,6 +94,7 @@ const DirectPermission = ({
9194
value: multiRole[primaryActionRoleIndex],
9295
configApprover: doesConfigApproverRoleExist || permission.action.configApprover,
9396
artifactPromoter: doesArtifactPromoterRoleExist || permission.action.artifactPromoter,
97+
terminalExec: doesTerminalAccessRoleExist || permission.action.terminalExec,
9498
}
9599

96100
const [openMenu, setOpenMenu] = useState<DirectPermissionFieldName | ''>('')
@@ -131,6 +135,9 @@ const DirectPermission = ({
131135
}
132136
}
133137

138+
const getSelectedRolesDisplay = (selectedPermissions: string[]) =>
139+
selectedPermissions.filter((selectedVal) => !!selectedVal).join(', ')
140+
134141
const metaRolesForAccessType = _getMetaRolesForAccessType()
135142
const listForAccessType = getListForAccessType(permission.accessType)
136143

@@ -175,10 +182,18 @@ const DirectPermission = ({
175182
...props,
176183
}}
177184
>
178-
{value === SELECT_ALL_VALUE ? 'Admin' : metaRolesForAccessType[value].value}
179-
{ApproverPermission &&
180-
(permission.approver || primaryActionRole.configApprover || primaryActionRole.artifactPromoter) &&
181-
', Approver'}
185+
{getSelectedRolesDisplay([
186+
value === SELECT_ALL_VALUE ? 'Admin' : metaRolesForAccessType[value].value,
187+
...(ApproverPermission
188+
? [
189+
(permission.approver ||
190+
primaryActionRole.configApprover ||
191+
primaryActionRole.artifactPromoter) &&
192+
'Approver',
193+
primaryActionRole.terminalExec && 'Terminal',
194+
]
195+
: []),
196+
])}
182197
{React.cloneElement(children[1])}
183198
</components.ValueContainer>
184199
)
@@ -195,19 +210,23 @@ const DirectPermission = ({
195210
const RoleMenuList = (props) => (
196211
<components.MenuList {...props}>
197212
{props.children}
198-
{ApproverPermission && permission.accessType === ACCESS_TYPE_MAP.DEVTRON_APPS && (
199-
<ApproverPermission
200-
optionProps={props}
201-
approver={permission.approver}
202-
configApprover={primaryActionRole.configApprover}
203-
artifactPromoter={primaryActionRole.artifactPromoter}
204-
handleDirectPermissionChange={(...rest) => {
205-
props.selectOption(props.selectProps.value)
206-
handleDirectPermissionChange(...rest)
207-
}}
208-
formatOptionLabel={formatOptionLabel}
209-
/>
210-
)}
213+
{ApproverPermission &&
214+
(permission.accessType === ACCESS_TYPE_MAP.DEVTRON_APPS ||
215+
permission.accessType === ACCESS_TYPE_MAP.HELM_APPS) && (
216+
<ApproverPermission
217+
optionProps={props}
218+
approver={permission.approver}
219+
configApprover={primaryActionRole.configApprover}
220+
artifactPromoter={primaryActionRole.artifactPromoter}
221+
terminalExec={primaryActionRole.terminalExec}
222+
handleDirectPermissionChange={(...rest) => {
223+
props.selectOption(props.selectProps.value)
224+
handleDirectPermissionChange(...rest)
225+
}}
226+
formatOptionLabel={formatOptionLabel}
227+
accessType={permission.accessType}
228+
/>
229+
)}
211230
</components.MenuList>
212231
)
213232

src/Pages/GlobalConfigurations/Authorization/Shared/components/AppPermissions/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ACCESS_TYPE_MAP, SELECT_ALL_VALUE } from '../../../../../../config'
17+
import { ACCESS_TYPE_MAP } from '@devtron-labs/devtron-fe-common-lib'
18+
import { SELECT_ALL_VALUE } from '../../../../../../config'
1819
import { ActionTypes, authorizationSelectStyles, EntityTypes } from '../../../constants'
1920
import { getDefaultStatusAndTimeout } from '../../../libUtils'
2021
import { DirectPermissionsRoleFilter } from '../../../types'

src/Pages/GlobalConfigurations/Authorization/Shared/components/AppPermissions/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ServerError } from '@devtron-labs/devtron-fe-common-lib'
17+
import { ServerError, ACCESS_TYPE_MAP } from '@devtron-labs/devtron-fe-common-lib'
1818
import { JobList } from '../../../../../../components/Jobs/Types'
19-
import { ACCESS_TYPE_MAP } from '../../../../../../config'
2019
import { DirectPermissionsRoleFilter } from '../../../types'
2120

2221
type AppsList = Map<number, { loading: boolean; result: { id: number; name: string }[]; error: ServerError }>

src/Pages/GlobalConfigurations/Authorization/Shared/components/AppPermissions/utils.ts

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

17-
import { OptionType } from '@devtron-labs/devtron-fe-common-lib'
17+
import { OptionType, ACCESS_TYPE_MAP } from '@devtron-labs/devtron-fe-common-lib'
1818
import { DEFAULT_ENV } from '../../../../../../components/app/details/triggerView/Constants'
1919
import { createClusterEnvGroup } from '../../../../../../components/common'
20-
import { ACCESS_TYPE_MAP, SELECT_ALL_VALUE, SERVER_MODE } from '../../../../../../config'
20+
import { SELECT_ALL_VALUE, SERVER_MODE } from '../../../../../../config'
2121
import { EntityTypes } from '../../../constants'
2222
import { ALL_EXISTING_AND_FUTURE_ENVIRONMENTS_VALUE } from './constants'
2323
import { DirectPermissionRow } from './types'

src/Pages/GlobalConfigurations/Authorization/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,4 @@ export const authorizationSelectStyles = {
100100
export const IMAGE_APPROVER_ACTION = importComponentFromFELibrary('IMAGE_APPROVER_ACTION', {}, 'function')
101101
export const CONFIG_APPROVER_ACTION = importComponentFromFELibrary('CONFIG_APPROVER_ACTION', {}, 'function')
102102
export const ARTIFACT_PROMOTER_ACTION = importComponentFromFELibrary('ARTIFACT_PROMOTER_ACTION', {}, 'function')
103+
export const TERMINAL_EXEC_ACTION = importComponentFromFELibrary('TERMINAL_EXEC_ACTION', {}, 'function')

src/Pages/GlobalConfigurations/Authorization/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import {
2424
UserRoleGroup,
2525
UserGroupType,
2626
UserGroupDTO,
27+
ACCESS_TYPE_MAP,
2728
} from '@devtron-labs/devtron-fe-common-lib'
28-
import { ACCESS_TYPE_MAP, SERVER_MODE } from '../../../config'
29+
import { SERVER_MODE } from '../../../config'
2930
import { ActionTypes, EntityTypes, PermissionType, UserRoleType } from './constants'
3031

3132
export interface UserAndGroupPermissionsWrapProps {
@@ -258,6 +259,7 @@ export interface DirectPermissionsRoleFilter extends RoleFilter, PermissionStatu
258259
value: string
259260
configApprover?: boolean
260261
artifactPromoter?: boolean
262+
terminalExec?: boolean
261263
}
262264
accessType: ACCESS_TYPE_MAP.DEVTRON_APPS | ACCESS_TYPE_MAP.HELM_APPS | ACCESS_TYPE_MAP.JOBS
263265
workflow?: OptionType[]

src/Pages/GlobalConfigurations/Authorization/utils.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@ import {
2323
ToastVariantType,
2424
UserStatus,
2525
UserStatusDto,
26+
ACCESS_TYPE_MAP,
2627
ZERO_TIME_STRING,
2728
} from '@devtron-labs/devtron-fe-common-lib'
28-
import {
29-
ACCESS_TYPE_MAP,
30-
Moment12HourFormat,
31-
REQUIRED_FIELDS_MISSING,
32-
SELECT_ALL_VALUE,
33-
SERVER_MODE,
34-
} from '../../../config'
29+
import { Moment12HourFormat, REQUIRED_FIELDS_MISSING, SELECT_ALL_VALUE, SERVER_MODE } from '../../../config'
3530
import {
3631
APIRoleFilter,
3732
APIRoleFilterDto,
@@ -55,6 +50,7 @@ import {
5550
EntityTypes,
5651
PermissionType,
5752
ViewChartGroupPermission,
53+
TERMINAL_EXEC_ACTION,
5854
} from './constants'
5955
import { AppIdWorkflowNamesMapping } from '../../../services/service.types'
6056
import { ALL_EXISTING_AND_FUTURE_ENVIRONMENTS_VALUE } from './Shared/components/AppPermissions/constants'
@@ -270,6 +266,9 @@ const getPermissionActionValue = (permission: DirectPermissionsRoleFilter) => {
270266
if (permission.action.artifactPromoter) {
271267
labels.push(ARTIFACT_PROMOTER_ACTION.value)
272268
}
269+
if (permission.action.terminalExec) {
270+
labels.push(TERMINAL_EXEC_ACTION.value)
271+
}
273272

274273
return labels.join(',')
275274
}
@@ -405,7 +404,7 @@ export const isDirectPermissionFormComplete = (directPermission, setDirectPermis
405404
}
406405

407406
const isRoleCustom = (roleValue: string) =>
408-
[CONFIG_APPROVER_ACTION.value, ARTIFACT_PROMOTER_ACTION.value].includes(roleValue)
407+
[CONFIG_APPROVER_ACTION.value, ARTIFACT_PROMOTER_ACTION.value, TERMINAL_EXEC_ACTION.value].includes(roleValue)
409408

410409
// eslint-disable-next-line @typescript-eslint/no-explicit-any
411410
export function parseData(dataList: any[], entity: string, accessType?: string) {
@@ -416,7 +415,7 @@ export function parseData(dataList: any[], entity: string, accessType?: string)
416415
(role) => role.accessType === ACCESS_TYPE_MAP.DEVTRON_APPS && !isRoleCustom(role.value),
417416
)
418417
}
419-
return dataList.filter((role) => role.accessType === ACCESS_TYPE_MAP.HELM_APPS)
418+
return dataList.filter((role) => role.accessType === ACCESS_TYPE_MAP.HELM_APPS && !isRoleCustom(role.value))
420419

421420
case EntityTypes.CLUSTER:
422421
case EntityTypes.CHART_GROUP:

0 commit comments

Comments
 (0)