Skip to content

Commit

Permalink
code review rework
Browse files Browse the repository at this point in the history
  • Loading branch information
ssundahlTTD committed Dec 4, 2023
1 parent 4c5befb commit 74d0f43
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 38 deletions.
3 changes: 3 additions & 0 deletions DeploymentSteps.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Don't delete old sections - just leave them towards the bottom of the file, and
## Next (pending changes for the next coming release)

1. Admin must be deployed before the portal to include the Role changes needed for setting client types (sas-UID2-1782-approved-types-to-admin)

## 0.7.5

2. Keycloak needs to update realm display name to UID2 Portal

## 0.6.0
Expand Down
22 changes: 9 additions & 13 deletions src/api/routers/usersRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,15 @@ export function createUsersRouter() {
});

usersRouter.get('/current/participant', async (req: UserRequest, res) => {
try {
const currentParticipant = await Participant.query().findOne({ id: req.user!.participantId });
const sites = await getSiteList();
const currentSite = sites.find((x) => x.id === currentParticipant?.siteId);
const allParticipantTypes = await ParticipantType.query();
const result = {
...currentParticipant,
types: mapClientTypeToParticipantType(currentSite?.clientTypes || [], allParticipantTypes),
};
return res.status(200).json(result);
} catch (error: unknown) {
console.log(error);
}
const currentParticipant = await Participant.query().findOne({ id: req.user!.participantId });
const sites = await getSiteList();
const currentSite = sites.find((x) => x.id === currentParticipant?.siteId);
const allParticipantTypes = await ParticipantType.query();
const result = {
...currentParticipant,
types: mapClientTypeToParticipantType(currentSite?.clientTypes || [], allParticipantTypes),
};
return res.status(200).json(result);
});

usersRouter.use('/:userId', enrichWithUserFromParams);
Expand Down
33 changes: 8 additions & 25 deletions src/api/services/adminServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { z } from 'zod';
import { ParticipantApprovalPartial } from '../entities/Participant';
import { SSP_ADMIN_SERVICE_BASE_URL, SSP_ADMIN_SERVICE_CLIENT_KEY } from '../envars';
import { getLoggers } from '../helpers/loggingHelpers';
import { ClientType, KeyPairDTO, SharingListResponse, SiteDTO } from './adminServiceHelpers';
import {
ClientType,
KeyPairDTO,
mapClientTypesToAdminEnums,
SharingListResponse,
SiteDTO,
} from './adminServiceHelpers';

const adminServiceClient = axios.create({
baseURL: SSP_ADMIN_SERVICE_BASE_URL,
Expand All @@ -22,29 +28,6 @@ const DEFAULT_SHARING_SETTINGS: Pick<SharingListResponse, 'allowed_sites' | 'all
allowed_sites: [],
};

const mapClientTypesToAdminEnums = (
participantApprovalPartial: z.infer<typeof ParticipantApprovalPartial>
): string[] => {
return participantApprovalPartial.types.map((type) => {
let adminEnum = 'UNKNOWN';
switch (type.id) {
case 1:
adminEnum = 'DSP';
break;
case 2:
adminEnum = 'ADVERTISER';
break;
case 3:
adminEnum = 'DATA_PROVIDER';
break;
case 4:
adminEnum = 'PUBLISHER';
break;
}
return adminEnum;
});
};

export const getSharingList = async (
siteId: number,
traceId: string
Expand Down Expand Up @@ -131,7 +114,7 @@ export const addKeyPair = async (
if (error instanceof AxiosError) {
errorMessage = error.response?.data.message as string;
}
errorLogger.error(`Get ACLs failed: ${errorMessage}`, traceId);
errorLogger.error(`Add keypair failed: ${errorMessage}`, traceId);
throw error;
}
};
Expand Down
26 changes: 26 additions & 0 deletions src/api/services/adminServiceHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { z } from 'zod';

import { ParticipantApprovalPartial } from '../entities/Participant';
import { ParticipantTypeData, ParticipantTypeDTO } from '../entities/ParticipantType';

type ClientRole = 'ID_READER' | 'GENERATOR' | 'MAPPER' | 'OPTOUT' | 'SHARER';
Expand Down Expand Up @@ -54,3 +57,26 @@ export function GetRecommendedRoles(roles: ParticipantTypeDTO[]) {
const recommendedRolesWithDuplicates = roles.flatMap((r) => AllowedSiteRoles[r.typeName]);
return [...new Set(recommendedRolesWithDuplicates)];
}

export const mapClientTypesToAdminEnums = (
participantApprovalPartial: z.infer<typeof ParticipantApprovalPartial>
): string[] => {
return participantApprovalPartial.types.map((type) => {
let adminEnum = 'UNKNOWN';
switch (type.id) {
case 1:
adminEnum = 'DSP';
break;
case 2:
adminEnum = 'ADVERTISER';
break;
case 3:
adminEnum = 'DATA_PROVIDER';
break;
case 4:
adminEnum = 'PUBLISHER';
break;
}
return adminEnum;
});
};

0 comments on commit 74d0f43

Please sign in to comment.