Skip to content

Commit 5290c05

Browse files
committed
Merge branch 'feat/user-groups' into feat/approve-material
2 parents 6bff1cf + 3dcaf81 commit 5290c05

File tree

7 files changed

+87
-9
lines changed

7 files changed

+87
-9
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-1",
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 & 2 deletions
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,8 +320,10 @@ export enum DeploymentNodeType {
319320
APPROVAL = 'APPROVAL',
320321
}
321322

322-
export interface UserApprovalConfigType {
323-
requiredCount: number
323+
export enum ManualApprovalType {
324+
specific = 'SPECIFIC',
325+
any = 'ANY',
326+
notConfigured = 'NOT_CONFIGURED',
324327
}
325328

326329
export interface UserGroupApproverType {
@@ -342,6 +345,28 @@ interface ImageApprovalPolicyType {
342345
// Assuming name of groups are unique
343346
validGroups: string[]
344347
}
348+
// TODO: Need to verify this change for all impacting areas
349+
export interface UserApprovalConfigType {
350+
type: ManualApprovalType
351+
requiredCount: number
352+
specificUsers: {
353+
identifiers: string[]
354+
}
355+
userGroups: (Pick<UserGroupDTO, 'identifier'> & {
356+
requiredCount: number
357+
})[]
358+
}
359+
360+
export type UserApprovalConfigPayloadType =
361+
| ({
362+
type: ManualApprovalType.any
363+
} & Pick<UserApprovalConfigType, 'requiredCount'>)
364+
| ({
365+
type: ManualApprovalType.specific
366+
} & Pick<UserApprovalConfigType, 'userGroups' | 'specificUsers'>)
367+
| {
368+
type: ManualApprovalType.notConfigured
369+
}
345370

346371
interface ApprovalUserDataType {
347372
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: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,26 @@ export interface UserGroupDTO {
5959
*
6060
* Follows the validation for app name
6161
*/
62-
userGroupId: string
62+
identifier: string
6363
/**
6464
* Associated description
65+
*
66+
* @default ''
6567
*/
66-
description: string
68+
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 UserGroupDTO {}
77+
export interface UserGroupType extends Required<Pick<UserGroupDTO, 'description' | 'name' | 'usersCount'>> {
78+
/**
79+
* Unique id of the user group
80+
*
81+
* Follows the validation for app name
82+
*/
83+
userGroupId: string
84+
}

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)