Skip to content

Commit 943807a

Browse files
slavikmasafshen
andauthored
Allow searching for users with all roles in a tenant (#569)
* Allow searching for users with all roles in a tenant * fix package lock --------- Co-authored-by: Asaf Shen <asaf@descope.com>
1 parent 66de292 commit 943807a

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

lib/management/user.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,8 @@ describe('Management User', () => {
935935
fromModifiedTime: now,
936936
toModifiedTime: now,
937937
sort: [{ field: 'aa', desc: true }, { field: 'bb' }],
938-
tenantRoleIds: { tenant1: ['roleA', 'roleB'] },
939-
tenantRoleNames: { tenant2: ['admin', 'user'] },
938+
tenantRoleIds: { tenant1: { values: ['roleA', 'roleB'] } },
939+
tenantRoleNames: { tenant2: { values: ['admin', 'user'] } },
940940
});
941941

942942
expect(mockHttpClient.post).toHaveBeenCalledWith(
@@ -996,8 +996,8 @@ describe('Management User', () => {
996996
fromModifiedTime: now,
997997
toModifiedTime: now,
998998
sort: [{ field: 'aa', desc: true }, { field: 'bb' }],
999-
tenantRoleIds: { tenant1: ['roleA', 'roleB'] },
1000-
tenantRoleNames: { tenant2: ['admin', 'user'] },
999+
tenantRoleIds: { tenant1: { values: ['roleA', 'roleB'] } },
1000+
tenantRoleNames: { tenant2: { values: ['admin', 'user'] } },
10011001
});
10021002

10031003
expect(mockHttpClient.post).toHaveBeenCalledWith(

lib/management/user.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ type SearchSort = {
2929
desc?: boolean;
3030
};
3131

32+
type RolesList = {
33+
values: string[];
34+
and?: boolean;
35+
};
36+
3237
type SearchRequest = {
3338
page?: number;
3439
limit?: number;
@@ -49,8 +54,8 @@ type SearchRequest = {
4954
toCreatedTime?: number; // Search users created before this time (epoch in milliseconds)
5055
fromModifiedTime?: number; // Search users modified after this time (epoch in milliseconds)
5156
toModifiedTime?: number; // Search users modified before this time (epoch in milliseconds)
52-
tenantRoleIds?: Record<string, string[]>; // Search users based on tenants and role IDs
53-
tenantRoleNames?: Record<string, string[]>; // Search users based on tenants and role names
57+
tenantRoleIds?: Record<string, RolesList>; // Search users based on tenants and role IDs
58+
tenantRoleNames?: Record<string, RolesList>; // Search users based on tenants and role names
5459
};
5560

5661
type SingleUserResponse = {
@@ -61,17 +66,6 @@ type MultipleUsersResponse = {
6166
users: UserResponse[];
6267
};
6368

64-
function mapToValuesObject(
65-
input: Record<string, string[]> | undefined,
66-
): Record<string, { values: string[] }> | undefined {
67-
if (!input || Object.keys(input).length === 0) {
68-
return undefined;
69-
}
70-
return Object.fromEntries(
71-
Object.entries(input).map(([key, value]) => [key, { values: value }]),
72-
) as Record<string, { values: string[] }>;
73-
}
74-
7569
const withUser = (sdk: CoreSdk, managementKey?: string) => {
7670
/* Create User */
7771
function create(loginId: string, options?: UserOptions): Promise<SdkResponse<UserResponse>>;
@@ -609,8 +603,6 @@ const withUser = (sdk: CoreSdk, managementKey?: string) => {
609603
testUsersOnly: true,
610604
roleNames: searchReq.roles,
611605
roles: undefined,
612-
tenantRoleIds: mapToValuesObject(searchReq.tenantRoleIds),
613-
tenantRoleNames: mapToValuesObject(searchReq.tenantRoleNames),
614606
},
615607
{ token: managementKey },
616608
),
@@ -624,8 +616,6 @@ const withUser = (sdk: CoreSdk, managementKey?: string) => {
624616
...searchReq,
625617
roleNames: searchReq.roles,
626618
roles: undefined,
627-
tenantRoleIds: mapToValuesObject(searchReq.tenantRoleIds),
628-
tenantRoleNames: mapToValuesObject(searchReq.tenantRoleNames),
629619
},
630620
{ token: managementKey },
631621
),

0 commit comments

Comments
 (0)