Skip to content

Commit 3dcaf81

Browse files
authored
Merge pull request #259 from devtron-labs/feat/approval-config
feat: add support for any & specific approval type in cd pipeline
2 parents 5b441aa + 49012a7 commit 3dcaf81

File tree

7 files changed

+78
-6
lines changed

7 files changed

+78
-6
lines changed

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": "0.2.6-beta-2",
3+
"version": "0.2.6-beta-4",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/Types.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Placement } from 'tippy.js'
1919
import { ImageComment, ReleaseTag } from './ImageTags.Types'
2020
import { ACTION_STATE, DEPLOYMENT_WINDOW_TYPE, DockerConfigOverrideType, SortingOrder, TaskErrorObj } from '.'
2121
import { RegistryType } from '../Shared'
22+
import { UserGroupDTO } from '@Pages/GlobalConfigurations'
2223

2324
/**
2425
* Generic response type object with support for overriding the result type
@@ -319,9 +320,34 @@ export enum DeploymentNodeType {
319320
APPROVAL = 'APPROVAL',
320321
}
321322

323+
export enum ManualApprovalType {
324+
specific = 'SPECIFIC',
325+
any = 'ANY',
326+
notConfigured = 'NOT_CONFIGURED',
327+
}
328+
329+
// TODO: Need to verify this change for all impacting areas
322330
export interface UserApprovalConfigType {
331+
type: ManualApprovalType
323332
requiredCount: number
324-
}
333+
specificUsers: {
334+
identifiers: string[]
335+
}
336+
userGroups: (Pick<UserGroupDTO, 'identifier'> & {
337+
requiredCount: number
338+
})[]
339+
}
340+
341+
export type UserApprovalConfigPayloadType =
342+
| ({
343+
type: ManualApprovalType.any
344+
} & Pick<UserApprovalConfigType, 'requiredCount'>)
345+
| ({
346+
type: ManualApprovalType.specific
347+
} & Pick<UserApprovalConfigType, 'userGroups' | 'specificUsers'>)
348+
| {
349+
type: ManualApprovalType.notConfigured
350+
}
325351

326352
interface ApprovalUserDataType {
327353
dataId: number

src/Pages/GlobalConfigurations/Authorization/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
export * from './constants'
1818
export type { UserListFilterParams, UserRoleGroup, UserGroupDTO, UserGroupType } from './types'
1919
export * from './shared'
20+
export * from './service'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { get } from '@Common/index'
2+
import { SelectPickerCustomOptionType } from '@Shared/Components'
3+
import { API_TOKEN_PREFIX } from '@Shared/constants'
4+
import { stringComparatorBySortOrder } from '@Shared/Helpers'
5+
import { DefaultUserKey } from '@Shared/types'
6+
import { GroupBase } from 'react-select'
7+
8+
// FIXME: Common out the typing and url from dashboard
9+
export const getUserAndApiTokenOptions = async (): Promise<GroupBase<SelectPickerCustomOptionType<string>>[]> => {
10+
const [{ result: userResponse }, { result: apiTokenResponse }] = await Promise.all([
11+
get('user/v2'),
12+
get('api-token'),
13+
])
14+
15+
return [
16+
{
17+
label: 'Users',
18+
options: (userResponse?.users ?? [])
19+
.sort((a, b) => stringComparatorBySortOrder(a.email_id, b.email_id))
20+
.filter(({ email_id: emailId }) => emailId !== DefaultUserKey.system)
21+
.map(({ email_id: emailId }) => ({
22+
label: emailId,
23+
value: emailId,
24+
})),
25+
},
26+
{
27+
label: 'API Tokens',
28+
options: (apiTokenResponse ?? [])
29+
.sort((a, b) => stringComparatorBySortOrder(a.userIdentifier, b.userIdentifier))
30+
.map(({ userIdentifier }) => ({
31+
// Remove the API Token Prefix
32+
label: userIdentifier.startsWith(API_TOKEN_PREFIX) ? userIdentifier.split(':')[1] : userIdentifier,
33+
value: userIdentifier,
34+
})),
35+
},
36+
]
37+
}

src/Pages/GlobalConfigurations/Authorization/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ export interface UserGroupDTO {
6262
identifier: string
6363
/**
6464
* Associated description
65+
*
66+
* @default ''
6567
*/
6668
description?: string
69+
/**
70+
* Number of users assigned to the group
71+
*
72+
* @default 0
73+
*/
74+
usersCount?: number
6775
}
6876

69-
export interface UserGroupType extends Required<Pick<UserGroupDTO, 'description' | 'name'>> {
77+
export interface UserGroupType extends Required<Pick<UserGroupDTO, 'description' | 'name' | 'usersCount'>> {
7078
/**
7179
* Unique id of the user group
7280
*

src/Shared/Components/SelectPickerCustom/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export { default as SelectPickerCustom } from './SelectPicker.component'
1818
export { default as FilterSelectPickerCustom } from './FilterSelectPicker'
1919
export type {
2020
SelectPickerOptionType as SelectPickerCustomOptionType,
21-
SelectPickerVariantType as SelectPickerCustomVariantType,
2221
SelectPickerProps as SelectPickerCustomProps,
2322
FilterSelectPickerProps as FilterSelectPickerCustomProps,
2423
} from './type'
24+
export { SelectPickerVariantType as SelectPickerCustomVariantType } from './type'

0 commit comments

Comments
 (0)