Skip to content

Commit d44ecd3

Browse files
committed
improved messaging, fix url issue
2 parents 5b4aca8 + 9237283 commit d44ecd3

File tree

9 files changed

+52
-113
lines changed

9 files changed

+52
-113
lines changed

package-lock.json

Lines changed: 16 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@
255255
"minimatch": "3.1.2"
256256
},
257257
"qs": "6.14.1",
258-
"@isaacs/brace-expansion": "^5.0.1"
258+
"@isaacs/brace-expansion": "^5.0.1",
259+
"workbox-webpack-plugin": {
260+
"webpack-sources": "2.3.1"
261+
},
262+
"@jest/schemas": "29.6.3",
263+
"eslint-visitor-keys": "4.2.0"
259264
}
260265
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const isUid2Engineer = (email: string) =>
2+
email.toLowerCase().endsWith('@unifiedid.com');
3+
4+
export const isUid2Internal = (email: string) => {
5+
const lower = email.toLowerCase();
6+
return lower.endsWith('@unifiedid.com') || lower.endsWith('@thetradedesk.com');
7+
};

src/api/middleware/userRoleMiddleware.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export const uid2SupportRole = 'prod-uid2.0-support';
88
export const developerRole = 'developer';
99
export const developerElevatedRole = 'developer-elevated';
1010

11-
export const isUid2InternalEmail = (email: string) => email.toLowerCase().includes('@unifiedid.com');
12-
1311
// assign super user if user is developer-elevated in okta
1412
export const isSuperUser = (req: Request) => {
1513
const oktaGroups = (req.auth?.payload?.groups as string[] | undefined) ?? [];
@@ -30,7 +28,11 @@ export const isSuperUserCheck: Handler = async (req: ParticipantRequest, res, ne
3028
// assign uid2 support if user has prod-uid2.0-support in Microsoft Entra ID
3129
export const isUid2Support = async (req: Request) => {
3230
const authGroups = (req.auth?.payload?.groups as string[] | undefined) ?? [];
33-
if (isSuperUser(req) || authGroups.includes(developerRole) || authGroups.includes(uid2SupportRole)) {
31+
if (
32+
isSuperUser(req) ||
33+
authGroups.includes(developerRole) ||
34+
authGroups.includes(uid2SupportRole)
35+
) {
3436
return true;
3537
}
3638

@@ -57,8 +59,7 @@ export const isAdminOrUid2SupportCheck: Handler = async (req: ParticipantRequest
5759
const user = await findUserByEmail(userEmail);
5860
const userParticipant = user?.participants?.find((item) => item.id === participant?.id);
5961
const userIsAdminOrUid2Support =
60-
userParticipant?.currentUserRoleIds?.includes(UserRoleId.Admin) ||
61-
(await isUid2Support(req));
62+
userParticipant?.currentUserRoleIds?.includes(UserRoleId.Admin) || (await isUid2Support(req));
6263
if (!userIsAdminOrUid2Support) {
6364
return res.status(403).json({
6465
message: 'Unauthorized. You do not have the necessary permissions.',

src/api/middleware/usersMiddleware.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { NextFunction, Request, Response } from 'express';
22
import { z } from 'zod';
33

44
import { User, UserJobFunction } from '../entities/User';
5+
import { isUid2Engineer } from '../helpers/internalEmailHelpers';
56
import { getLoggers, getTraceId, TraceId } from '../helpers/loggingHelpers';
67
import { getAllParticipants, UserParticipantRequest } from '../services/participantsService';
78
import { findUserByEmail, UserRequest } from '../services/usersService';
8-
import { isSuperUser, isUid2InternalEmail, isUid2Support } from './userRoleMiddleware';
9+
import { isSuperUser, isUid2Support } from './userRoleMiddleware';
910

1011
type UserWithSupportRoles = User & { isUid2Support: boolean; isSuperUser: boolean };
1112

12-
const createUid2InternalUser = async (
13+
const createUid2EngineerUser = async (
1314
email: string,
1415
firstName: string,
1516
lastName: string
@@ -19,7 +20,7 @@ const createUid2InternalUser = async (
1920
firstName,
2021
lastName,
2122
jobFunction: UserJobFunction.Engineering,
22-
acceptedTerms: true,
23+
acceptedTerms: false,
2324
});
2425
};
2526

@@ -61,10 +62,10 @@ export const enrichCurrentUser = async (req: UserRequest, res: Response, next: N
6162
const userEmail = req.auth?.payload?.email as string;
6263
let user = await findUserByEmail(userEmail);
6364

64-
if (!user && isUid2InternalEmail(userEmail)) {
65+
if (!user && isUid2Engineer(userEmail)) {
6566
const firstName = req.auth?.payload?.given_name as string;
6667
const lastName = req.auth?.payload?.family_name as string;
67-
await createUid2InternalUser(userEmail, firstName, lastName);
68+
await createUid2EngineerUser(userEmail, firstName, lastName);
6869
user = await findUserByEmail(userEmail);
6970
}
7071

src/api/services/usersService.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { User, UserDTO } from '../entities/User';
55
import { UserRole, UserRoleDTO } from '../entities/UserRole';
66
import { UserToParticipantRole } from '../entities/UserToParticipantRole';
77
import { SSP_WEB_BASE_URL } from '../envars';
8+
import { isUid2Internal } from '../helpers/internalEmailHelpers';
89
import { TraceId } from '../helpers/loggingHelpers';
910
import { getKcAdminClient } from '../keycloakAdminClient';
1011
import { createEmailService } from './emailService';
@@ -151,7 +152,9 @@ export const createAndInviteKeycloakUser = async (
151152
const newUser = await createNewUser(kcAdminClient, firstName, lastName, email);
152153
await assignApiParticipantMemberRole(kcAdminClient, email);
153154

154-
await sendInviteEmailToNewUser(kcAdminClient, newUser);
155+
if (!isUid2Internal(email)) {
156+
await sendInviteEmailToNewUser(kcAdminClient, newUser);
157+
}
155158
};
156159

157160
const addAndInviteUserToParticipant = async (
@@ -165,7 +168,9 @@ const addAndInviteUserToParticipant = async (
165168
participantId: participant.id,
166169
userRoleId,
167170
});
168-
sendInviteEmailToExistingUser(participant.name, existingUser, traceId);
171+
if (!isUid2Internal(existingUser.email)) {
172+
sendInviteEmailToExistingUser(participant.name, existingUser, traceId);
173+
}
169174
};
170175

171176
const createUserInPortal = async (

src/web/components/Home/SharingPermissionCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function SharingPermissionCard({
4242
) : (
4343
<div className='no-sharing-permissions-banner'>
4444
<Banner
45-
message='You do not have access to this feature. To get access, please contact Support.'
45+
message='Use of sharing requires an API key or client-side key pair. Please reach out to our support team for assistance.'
4646
type='Info'
4747
fitContent
4848
/>

src/web/components/TeamMember/TeamMember.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import clsx from 'clsx';
22
import log from 'loglevel';
33
import { useCallback, useContext, useState } from 'react';
44

5+
import { isUid2Internal } from '../../../api/helpers/internalEmailHelpers';
56
import { UserWithParticipantRoles } from '../../../api/services/usersService';
67
import { ParticipantContext } from '../../contexts/ParticipantProvider';
78
import { UpdateTeamMemberForm } from '../../services/userAccount';
@@ -134,7 +135,7 @@ function TeamMember({
134135
<td className='action'>
135136
<div className='action-cell' data-testid='action-cell'>
136137
{!!errorMessage && <InlineMessage message={errorMessage} type='Error' />}
137-
{person.acceptedTerms || (
138+
{!person.acceptedTerms && !isUid2Internal(person.email) && (
138139
<button
139140
type='button'
140141
className={clsx('invite-button', {

src/web/utils/urlHelpers.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,7 @@ export const extractLocationFromPath = (path: string) => {
2525
return match ? match[1] : path.replace(/^\/?:?participantId\/?/, '');
2626
};
2727

28-
const PARTICIPANT_PATH_REGEX = /^\/?participant\/[^/]+\/?(.*)$/;
29-
3028
export function getPathWithParticipant(path: string, participantId: string | number | undefined) {
31-
if (participantId === undefined || participantId === null) {
32-
return path;
33-
}
34-
const match = PARTICIPANT_PATH_REGEX.exec(path);
35-
if (!match) {
36-
return path;
37-
}
38-
const location = (match[1] ?? '').replace(/^\//, '');
29+
const location = extractLocationFromPath(path).replace(/^\//, '');
3930
return `/participant/${participantId}/${location}`;
4031
}

0 commit comments

Comments
 (0)