Skip to content

Commit 2162fde

Browse files
do not create elevated roles
1 parent 444fe00 commit 2162fde

File tree

4 files changed

+17
-28
lines changed

4 files changed

+17
-28
lines changed

src/api/services/kcUsersService.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ import { RequiredActionAlias } from '@keycloak/keycloak-admin-client/lib/defs/re
33
import UserRepresentation from '@keycloak/keycloak-admin-client/lib/defs/userRepresentation';
44

55
import { SSP_KK_API_CLIENT_ID, SSP_KK_SSL_RESOURCE, SSP_WEB_BASE_URL } from '../envars.ts';
6+
import {
7+
developerElevatedRole,
8+
developerRole,
9+
uid2SupportRole,
10+
} from '../middleware/userRoleMiddleware';
611

712
export const API_PARTICIPANT_MEMBER_ROLE_NAME = 'api-participant-member';
813

9-
// Same group names as userRoleMiddleware (from JWT payload / Keycloak attributes.groups)
10-
const developerElevatedRole = 'developer-elevated';
11-
const developerRole = 'developer';
12-
const uid2SupportRole = 'prod-uid2.0-support';
13-
14-
export type ElevatedRole = 'SuperUser' | 'UID2 Support';
15-
1614
export const queryKeycloakUsersByEmail = async (
1715
kcAdminClient: KeycloakAdminClient,
1816
email: string
@@ -33,26 +31,19 @@ function toGroupsArray(groupsRaw: unknown): string[] {
3331
return [];
3432
}
3533

36-
/**
37-
* Resolves elevated role from Keycloak user attributes (key "groups"), not realm Groups.
38-
* Used when the viewed user has no portal participants but may have SuperUser/UID2 Support in IdP.
39-
*/
4034
export const getElevatedRoleByEmail = async (
4135
kcAdminClient: KeycloakAdminClient,
4236
email: string
43-
): Promise<ElevatedRole | null> => {
37+
): Promise<string | null> => {
4438
const users = await queryKeycloakUsersByEmail(kcAdminClient, email);
4539
if (!users.length) return null;
4640

4741
const attrs = users[0].attributes;
4842
const groups = toGroupsArray(attrs?.groups);
4943

50-
if (groups.includes(developerElevatedRole)) return 'SuperUser';
51-
if (
52-
groups.includes(developerRole) ||
53-
groups.includes(uid2SupportRole)
54-
) {
55-
return 'UID2 Support';
44+
if (groups.includes(developerElevatedRole)) return developerElevatedRole;
45+
if (groups.includes(developerRole) || groups.includes(uid2SupportRole)) {
46+
return uid2SupportRole;
5647
}
5748
return null;
5849
};

src/web/components/UserManagement/UserPartcipantsTable.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ParticipantDTO } from '../../../api/entities/Participant';
22
import { UserDTO } from '../../../api/entities/User';
33
import { UserRoleId } from '../../../api/entities/UserRole';
4+
import { developerElevatedRole, uid2SupportRole } from '../../../api/middleware/userRoleMiddleware';
45
import { SortableProvider } from '../../contexts/SortableTableProvider';
5-
import { ElevatedRole } from '../../services/participant';
66
import { TableNoDataPlaceholder } from '../Core/Tables/TableNoDataPlaceholder';
77

88
import './UserParticipantsTable.scss';
@@ -24,14 +24,14 @@ function UserParticipantRow({ participantName, roleName }: UserParticipantRowPro
2424
export type UserParticipantsTableProps = Readonly<{
2525
user: UserDTO;
2626
userParticipants: ParticipantDTO[];
27-
elevatedRole?: ElevatedRole | null;
27+
elevatedRole: string | null;
2828
}>;
2929

30-
function getEmptyParticipantsMessage(elevatedRole: ElevatedRole | null | undefined): string {
31-
if (elevatedRole === 'SuperUser') {
30+
function getEmptyParticipantsMessage(elevatedRole:string | null): string {
31+
if (elevatedRole === developerElevatedRole) {
3232
return 'This user has SuperUser role and has access to all participants.';
3333
}
34-
if (elevatedRole === 'UID2 Support') {
34+
if (elevatedRole === uid2SupportRole) {
3535
return 'This user has UID2 Support role and has access to all participants.';
3636
}
3737
return 'This user does not belong to any participant.';

src/web/components/UserManagement/UserParticipantsDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
22

33
import { ParticipantDTO } from '../../../api/entities/Participant';
44
import { UserDTO } from '../../../api/entities/User';
5-
import { ElevatedRole, GetUserParticipants } from '../../services/participant';
5+
import { GetUserParticipants } from '../../services/participant';
66
import { Dialog } from '../Core/Dialog/Dialog';
77
import { Loading } from '../Core/Loading/Loading';
88
import UserParticipantsTable from './UserPartcipantsTable';
@@ -14,7 +14,7 @@ type UserParticipantsDialogProps = Readonly<{
1414

1515
function UserParticipantsDialog({ user, onOpenChange }: UserParticipantsDialogProps) {
1616
const [userParticipants, setUserParticipants] = useState<ParticipantDTO[]>();
17-
const [elevatedRole, setElevatedRole] = useState<ElevatedRole | null>(null);
17+
const [elevatedRole, setElevatedRole] = useState<string | null>(null);
1818
const [isLoading, setIsLoading] = useState<boolean>(true);
1919

2020
useEffect(() => {

src/web/services/participant.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ export async function GetAllParticipants() {
4444
}
4545
}
4646

47-
export type ElevatedRole = 'SuperUser' | 'UID2 Support';
48-
4947
export type GetUserParticipantsResponse = {
5048
participants: ParticipantDTO[];
51-
elevatedRole: ElevatedRole | null;
49+
elevatedRole: string | null;
5250
};
5351

5452
export async function GetUserParticipants(userId: number): Promise<GetUserParticipantsResponse> {

0 commit comments

Comments
 (0)