Skip to content

Commit

Permalink
Merge pull request #207 from IABTechLab/jyg-UID2-1736-show-correct-sh…
Browse files Browse the repository at this point in the history
…aring-types

Show participant is sharing with DSP when allow_sites is null
  • Loading branch information
lionell-pack-ttd authored Oct 11, 2023
2 parents fdc3183 + b1933f5 commit 5fb4823
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 29 deletions.
12 changes: 10 additions & 2 deletions src/api/routers/participantsRouter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AxiosError } from 'axios';
import express, { Response } from 'express';
import { z } from 'zod';

Expand Down Expand Up @@ -208,8 +209,15 @@ export function createParticipantsRouter() {
if (!participant?.siteId) {
return res.status(400).send('Site id is not set');
}
const sharingList = await getSharingList(participant.siteId);
return res.status(200).json(sharingList);
try {
const sharingList = await getSharingList(participant.siteId);
return res.status(200).json(sharingList);
} catch (err) {
if (err instanceof AxiosError && err.response?.status === 404) {
return res.status(404).send('This site does not have a keyset.');
}
throw err;
}
}
);

Expand Down
25 changes: 11 additions & 14 deletions src/api/services/adminServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@ const adminServiceClient = axios.create({
},
});

const DEFAULT_SHARING_SETTINGS: Pick<SharingListResponse, 'allowed_sites' | 'allowed_types'> = {
allowed_types: ['DSP'],
allowed_sites: [],
};

export const getSharingList = async (siteId: number): Promise<SharingListResponse> => {
try {
const response = await adminServiceClient.get<SharingListResponse>(
`/api/sharing/list/${siteId}`,
{
validateStatus: (status) => (status >= 200 && status < 300) || status === 404,
validateStatus: (status) => status >= 200 && status < 300,
}
);
return response.status === 200
return response.data.allowed_sites
? response.data
: {
allowed_sites: [],
allowed_types: [],
hash: 0,
};
: { ...response.data, ...DEFAULT_SHARING_SETTINGS };
} catch (error: unknown) {
const [logger] = getLoggers();
logger.error(`Get ACLs failed: ${error}`);
Expand All @@ -52,16 +53,12 @@ export const updateSharingList = async (
hash,
},
{
validateStatus: (status) => (status >= 200 && status < 300) || status === 404,
validateStatus: (status) => status >= 200 && status < 300,
}
);
return response.status === 200
return response.data.allowed_sites
? response.data
: {
allowed_sites: [],
allowed_types: [],
hash: 0,
};
: { ...response.data, ...DEFAULT_SHARING_SETTINGS };
} catch (error: unknown) {
const [logger] = getLoggers();
logger.error(`Update ACLs failed: ${error}`);
Expand Down
4 changes: 4 additions & 0 deletions src/web/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
.heading-details {
margin: 4px 0;
}

p[role='alert'] {
color: var(--theme-error);
}
}

.app-centralize {
Expand Down
57 changes: 46 additions & 11 deletions src/web/screens/sharingPermissions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useContext, useEffect, useState } from 'react';
import { ReactNode, useContext, useEffect, useState } from 'react';

import { ClientType } from '../../api/services/adminServiceHelpers';
import { Collapsible } from '../components/Core/Collapsible';
Expand All @@ -14,16 +14,29 @@ import {
GetSharingList,
UpdateSharingTypes,
} from '../services/participant';
import { ApiError } from '../utils/apiError';
import { useAsyncError } from '../utils/errorHandler';
import { PortalRoute } from './routeUtils';

import './sharingPermissions.scss';

function SharingPermissionPageContainer({ children }: { children: ReactNode }) {
return (
<div className='sharingPermissions'>
<h1>Sharing Permissions</h1>
{children}
</div>
);
}

function SharingPermissions() {
const [showNoKeySetError, setNoKeySetError] = useState(false);
const [showStatusPopup, setShowStatusPopup] = useState(false);
const { participant, setParticipant } = useContext(ParticipantContext);
const [sharedSiteIds, setSharedSiteIds] = useState<number[]>([]);
const [sharedTypes, setSharedTypes] = useState<ClientType[]>([]);
const [statusPopup, setStatusPopup] = useState<StatusNotificationType>();
const throwError = useAsyncError();

const handleSaveSharingType = async (selectedTypes: ClientType[]) => {
try {
Expand Down Expand Up @@ -91,19 +104,41 @@ function SharingPermissions() {
}
};

const loadSharingList = useCallback(async () => {
const response = await GetSharingList();
setSharedSiteIds(response.allowed_sites);
setSharedTypes(response.allowed_types ?? []);
}, []);

useEffect(() => {
const loadSharingList = async () => {
try {
const response = await GetSharingList();
setSharedSiteIds(response.allowed_sites);
setSharedTypes(response.allowed_types ?? []);
} catch (e: unknown) {
if (e instanceof ApiError) {
if (e.statusCode === 404) {
setNoKeySetError(true);
return;
}
throwError(e);
}
}
};
loadSharingList();
}, [loadSharingList]);
}, [throwError]);

if (showNoKeySetError) {
return (
<SharingPermissionPageContainer>
<p className='heading-details' role='alert'>
We&apos;re experiencing an issue on our end. Access to sharing permissions is currently
unavailable for you.
<br />
<br />
Please reach out to our support team for assistance.
</p>
</SharingPermissionPageContainer>
);
}

return (
<div className='sharingPermissions'>
<h1>Sharing Permissions</h1>
<SharingPermissionPageContainer>
<p className='heading-details'>
Adding a sharing permission allows the participant you’re sharing with to decrypt your UID2
tokens.
Expand Down Expand Up @@ -146,7 +181,7 @@ function SharingPermissions() {
message={statusPopup!.message}
/>
)}
</div>
</SharingPermissionPageContainer>
);
}

Expand Down
1 change: 0 additions & 1 deletion src/web/styles/themes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
--theme-label-background: #c0d6ff;
--theme-search-bar-background: rgb(112 133 212 / 15%);
--theme-scrollbar: #c0d6ff;
--theme-error: red;
--theme-disabled-button-text: #878787;
--theme-disabled-button: #d9d9d9;
--theme-label: rgb(120 204 0 / 40%);
Expand Down
2 changes: 1 addition & 1 deletion src/web/utils/apiError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function backendError(e: unknown, overrideMessage: string) {

return new ApiError(overrideMessage, {
errorHash: hash,
statusCode: e.status,
statusCode: e.status || e.response?.status,
});
}
return Error(overrideMessage);
Expand Down

0 comments on commit 5fb4823

Please sign in to comment.