Skip to content

Commit

Permalink
Filter out sites that have visible==false
Browse files Browse the repository at this point in the history
- Create a new method `getVisibleSiteList` in adminServiceClient.ts to call getSiteList() then filter out the appropraite sites before returning to the front end
- The method of filtering allows for existing sites that have `visible==null`, which is the default for sites that were created before the `visible` flag was introduced. The default for new sites is `visible==true`
- Use `getVisibleSiteList` in the base router and `/available` in the sites router. These routes are only used for non-admin functionality and does not break core functionality of the website when the current participant has a site that has visible set to false
- Ultimately this hides invisible sites from being included on the sharing permissions count on the home screen, as well as being hidden from the sharing permissions screen (i.e. in the bulk add control, the search and add control, and the sharing permissions table)
  • Loading branch information
alex-yau-ttd committed Nov 28, 2023
1 parent 2a7dec3 commit e97a87d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/api/routers/sitesRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SharingSiteDTO,
} from '../helpers/siteConvertingHelpers';
import { isApproverCheck } from '../middleware/approversMiddleware';
import { getSiteList } from '../services/adminServiceClient';
import { getSiteList, getVisibleSiteList } from '../services/adminServiceClient';
import { SiteDTO } from '../services/adminServiceHelpers';
import { getAttachedSiteIDs, getParticipantsBySiteIds } from '../services/participantsService';

Expand All @@ -21,8 +21,8 @@ export function createSitesRouter() {
});

sitesRouter.get('/available', async (_req, res) => {
const sites = await getSiteList();
const availableSites = sites.filter(canBeSharedWith);
const visibleSites = await getVisibleSiteList();
const availableSites = visibleSites.filter(canBeSharedWith);
const matchedParticipants = await getParticipantsBySiteIds(availableSites.map((s) => s.id));
const availableSharingSites: SharingSiteDTO[] = availableSites.map((site: SiteDTO) =>
convertSiteToSharingSiteDTO(site, matchedParticipants)
Expand All @@ -31,9 +31,9 @@ export function createSitesRouter() {
});

sitesRouter.get('/', async (_req, res) => {
const sites = await getSiteList();
const matchedParticipants = await getParticipantsBySiteIds(sites.map((s) => s.id));
const sharingSites: SharingSiteDTO[] = sites.map((site: SiteDTO) =>
const visibleSites = await getVisibleSiteList();
const matchedParticipants = await getParticipantsBySiteIds(visibleSites.map((s) => s.id));
const sharingSites: SharingSiteDTO[] = visibleSites.map((site: SiteDTO) =>
convertSiteToSharingSiteDTO(site, matchedParticipants)
);
return res.status(200).json(sharingSites);
Expand Down
5 changes: 5 additions & 0 deletions src/api/services/adminServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export const getSiteList = async (): Promise<SiteDTO[]> => {
return response.data;
};

export const getVisibleSiteList = async (): Promise<SiteDTO[]> => {
const siteList = await getSiteList();
return siteList.filter((x) => x.visible !== false);
};

export const getKeyPairsList = async (siteId: number): Promise<KeyPairDTO[]> => {
const response = await adminServiceClient.get<KeyPairDTO[]>(
`/api/v2/sites/${siteId}/client-side-keypairs`
Expand Down
1 change: 1 addition & 0 deletions src/api/services/adminServiceHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type SiteDTO = {
roles: ClientRole[];
clientTypes?: ClientType[];
client_count: number;
visible: boolean;
};

export type SharingListResponse = {
Expand Down
1 change: 1 addition & 0 deletions src/api/tests/siteConvertingHelpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('Sharing Permission Helper Tests', () => {
clientTypes: ['DSP'],
// eslint-disable-next-line camelcase
client_count: 1,
visible: true,
} as SiteDTO;
expect(canBeSharedWith(site)).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ import { HighlightedResult } from './ParticipantApprovalForm';

const createResult = (text: string, indices: [number, number][]) => {
const result: Fuse.FuseResult<SiteDTO> = {
// eslint-disable-next-line camelcase
item: { name: text, id: 1, enabled: true, roles: [], clientTypes: [], client_count: 1 },
item: {
name: text,
id: 1,
enabled: true,
roles: [],
clientTypes: [],
// eslint-disable-next-line camelcase
client_count: 1,
visible: false,
},
matches: [
{
indices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const response: SiteDTO[] = [
clientTypes: ['PUBLISHER'],
// eslint-disable-next-line camelcase
client_count: 1,
visible: true,
},
{
id: 4,
Expand All @@ -29,6 +30,7 @@ const response: SiteDTO[] = [
clientTypes: ['PUBLISHER'],
// eslint-disable-next-line camelcase
client_count: 1,
visible: false,
},
];

Expand Down

0 comments on commit e97a87d

Please sign in to comment.