Skip to content

Commit

Permalink
removed all uses of participant status
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleysmithTTD committed Dec 5, 2024
1 parent 75d29be commit aa7ccb1
Show file tree
Hide file tree
Showing 23 changed files with 141 additions and 276 deletions.
8 changes: 2 additions & 6 deletions src/api/controllers/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from 'inversify-express-utils';

import { TYPES } from '../constant/types';
import { ParticipantStatus } from '../entities/Participant';
import { UserRoleId } from '../entities/UserRole';
import { getTraceId } from '../helpers/loggingHelpers';
import { getKcAdminClient } from '../keycloakAdminClient';
Expand Down Expand Up @@ -56,12 +55,9 @@ export class UserController {

@httpPut('/current/acceptTerms')
public async acceptTerms(@request() req: UserRequest, @response() res: Response): Promise<void> {
const doesUserHaveAnApprovedParticipant =
req.user?.participants?.some(
(participant) => participant.status === ParticipantStatus.Approved
) ?? false;
const doesUserHaveAParticipant = (req.user?.participants?.length ?? 0) >= 1 ?? false;

if (!doesUserHaveAnApprovedParticipant) {
if (!doesUserHaveAParticipant) {
res.status(403).json({
message: 'Unauthorized. You do not have the necessary permissions.',
errorHash: req.headers.traceId,
Expand Down
8 changes: 0 additions & 8 deletions src/api/entities/Participant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import { ParticipantType, ParticipantTypeDTO, ParticipantTypeSchema } from './Pa
import { type User, UserDTO, UserSchema } from './User';
import { UserToParticipantRole } from './UserToParticipantRole';

export enum ParticipantStatus {
AwaitingSigning = 'awaitingSigning',
AwaitingApproval = 'awaitingApproval',
Approved = 'approved',
}

export class Participant extends BaseModel {
static get tableName() {
return 'participants';
Expand Down Expand Up @@ -82,7 +76,6 @@ export class Participant extends BaseModel {
};
declare id: number;
declare name: string;
declare status: ParticipantStatus;
declare allowSharing: boolean;
declare completedRecommendations: boolean;
declare siteId?: number;
Expand All @@ -107,7 +100,6 @@ export type ParticipantDTO = Omit<ModelObjectOpt<Participant>, 'types' | 'users'
export const ParticipantSchema = z.object({
id: z.number(),
name: z.string(),
status: z.nativeEnum(ParticipantStatus),
types: z.array(ParticipantTypeSchema).optional(),
apiRoles: z.array(ApiRoleSchema).optional(),
users: z.array(UserSchema).optional(),
Expand Down
17 changes: 1 addition & 16 deletions src/api/routers/participants/participantsApproval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Response } from 'express';

import { getRoleNamesByIds } from '../../../web/utils/apiRoles';
import { AuditTrailEvents } from '../../entities/AuditTrail';
import { ParticipantApprovalPartial, ParticipantStatus } from '../../entities/Participant';
import { ParticipantApprovalPartial } from '../../entities/Participant';
import { getTraceId } from '../../helpers/loggingHelpers';
import { getKcAdminClient } from '../../keycloakAdminClient';
import { setSiteClientTypes } from '../../services/adminServiceClient';
Expand All @@ -17,27 +17,13 @@ import {
import { assignApiParticipantMemberRole } from '../../services/kcUsersService';
import {
getParticipantsApproved,
getParticipantsAwaitingApproval,
mapParticipantToApprovalRequest,
ParticipantRequest,
ParticipantRequestDTO,
sendParticipantApprovedEmail,
updateParticipantAndTypesAndApiRoles,
UserParticipantRequest,
} from '../../services/participantsService';
import { getAllUsersFromParticipant } from '../../services/usersService';

export const handleGetParticipantsAwaitingApproval = async (
req: ParticipantRequest,
res: Response
) => {
const participantsAwaitingApproval = await getParticipantsAwaitingApproval();
const result: ParticipantRequestDTO[] = participantsAwaitingApproval.map(
mapParticipantToApprovalRequest
);
return res.status(200).json(result);
};

export const handleGetApprovedParticipants = async (_req: ParticipantRequest, res: Response) => {
const participants = await getParticipantsApproved();
const result = participants.sort((a, b) => a.name.localeCompare(b.name));
Expand All @@ -49,7 +35,6 @@ export const handleApproveParticipant = async (req: UserParticipantRequest, res:
const traceId = getTraceId(req);
const data = {
...ParticipantApprovalPartial.parse(req.body),
status: ParticipantStatus.Approved,
approverId: user?.id,
dateApproved: new Date(),
};
Expand Down
3 changes: 1 addition & 2 deletions src/api/routers/participants/participantsCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { z } from 'zod';
import { getRoleNamesByIds } from '../../../web/utils/apiRoles';
import { ApiRole } from '../../entities/ApiRole';
import { AuditAction, AuditTrailEvents } from '../../entities/AuditTrail';
import { Participant, ParticipantStatus } from '../../entities/Participant';
import { Participant } from '../../entities/Participant';
import { User, UserCreationPartial } from '../../entities/User';
import { UserRoleId } from '../../entities/UserRole';
import { UserToParticipantRole } from '../../entities/UserToParticipantRole';
Expand Down Expand Up @@ -136,7 +136,6 @@ async function createParticipant(
await performAsyncOperationWithAuditTrail(auditTrailInsertObject, traceId, async () => {
const participantData = {
...parsedParticipantRequest,
status: ParticipantStatus.Approved,
approverId: requestingUser?.id,
dateApproved: new Date(),
};
Expand Down
4 changes: 1 addition & 3 deletions src/api/routers/participants/participantsKeyPairs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';

import { createResponseObject } from '../../../testHelpers/apiTestHelpers';
import { Participant, ParticipantStatus } from '../../entities/Participant';
import { Participant } from '../../entities/Participant';
import { SSP_ADMIN_SERVICE_BASE_URL } from '../../envars';
import { KeyPairDTO } from '../../services/adminServiceHelpers';
import { ParticipantRequest } from '../../services/participantsService';
Expand Down Expand Up @@ -96,7 +96,6 @@ describe('Get participant key pairs', () => {
id: 5,
allowSharing: true,
completedRecommendations: true,
status: ParticipantStatus.Approved,
apiRoles: [],
});

Expand All @@ -122,7 +121,6 @@ describe('Get participant key pairs', () => {
id: 5,
allowSharing: true,
completedRecommendations: true,
status: ParticipantStatus.Approved,
apiRoles: [],
siteId,
});
Expand Down
11 changes: 1 addition & 10 deletions src/api/routers/participants/participantsRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ import {
} from './participantsApiKeys';
import { handleGetParticipantApiRoles } from './participantsApiRoles';
import { handleGetParticipantAppNames, handleSetParticipantAppNames } from './participantsAppIds';
import {
handleApproveParticipant,
handleGetApprovedParticipants,
handleGetParticipantsAwaitingApproval,
} from './participantsApproval';
import { handleApproveParticipant, handleGetApprovedParticipants } from './participantsApproval';
import { handleGetAuditTrail } from './participantsAuditTrail';
import { handleCreateParticipant } from './participantsCreation';
import {
Expand All @@ -50,11 +46,6 @@ export function createParticipantsRouter() {

participantsRouter.get('/signed', handleGetSignedParticipants);

participantsRouter.get(
'/awaitingApproval',
isUid2SupportCheck,
handleGetParticipantsAwaitingApproval
);
participantsRouter.get('/approved', isUid2SupportCheck, handleGetApprovedParticipants);

participantsRouter.put('/', handleCreateParticipant);
Expand Down
24 changes: 3 additions & 21 deletions src/api/services/participantsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { z } from 'zod';
import { getRoleNamesByIds } from '../../web/utils/apiRoles';
import { ApiRole } from '../entities/ApiRole';
import { AuditAction, AuditTrailEvents } from '../entities/AuditTrail';
import {
Participant,
ParticipantApprovalPartial,
ParticipantDTO,
ParticipantStatus,
} from '../entities/Participant';
import { Participant, ParticipantApprovalPartial, ParticipantDTO } from '../entities/Participant';
import { ParticipantType } from '../entities/ParticipantType';
import { User, UserDTO } from '../entities/User';
import { SSP_WEB_BASE_URL } from '../envars';
Expand All @@ -27,7 +22,6 @@ import {
} from './auditTrailService';
import { createEmailService } from './emailService';
import { EmailArgs } from './emailTypes';
import { getAllUid2SupportUsers } from './uid2SupportService';

export interface ParticipantRequest extends Request {
participant?: Participant;
Expand All @@ -39,7 +33,7 @@ export interface UserParticipantRequest extends ParticipantRequest {

export type ParticipantRequestDTO = Pick<
ParticipantDTO,
'id' | 'name' | 'siteId' | 'types' | 'status' | 'apiRoles'
'id' | 'name' | 'siteId' | 'types' | 'apiRoles'
> & {
requestingUser: Pick<UserDTO, 'email'> &
Partial<Pick<UserDTO, 'jobFunction'>> & { fullName: string };
Expand All @@ -62,7 +56,6 @@ export const mapParticipantToApprovalRequest = (
siteId: participant.siteId,
types: participant.types,
apiRoles: participant.apiRoles,
status: participant.status,
requestingUser: {
email: firstUser ? firstUser.email : '',
jobFunction: firstUser?.jobFunction,
Expand All @@ -73,13 +66,6 @@ export const mapParticipantToApprovalRequest = (
};
};

export const getParticipantsAwaitingApproval = async (): Promise<Participant[]> => {
const participantsAwaitingApproval = await Participant.query()
.withGraphFetched('[types, users]')
.where('status', ParticipantStatus.AwaitingApproval);
return participantsAwaitingApproval;
};

type SiteIdType = NonNullable<ParticipantDTO['siteId']>;
export const getAttachedSiteIDs = async (): Promise<SiteIdType[]> => {
const sites = await Participant.query()
Expand All @@ -90,9 +76,7 @@ export const getAttachedSiteIDs = async (): Promise<SiteIdType[]> => {
};

export const getParticipantsApproved = async (): Promise<Participant[]> => {
return Participant.query()
.where('status', ParticipantStatus.Approved)
.withGraphFetched('[apiRoles, approver, types, users]');
return Participant.query().withGraphFetched('[apiRoles, approver, types, users]');
};

export const getParticipantsBySiteIds = async (siteIds: number[]) => {
Expand Down Expand Up @@ -167,7 +151,6 @@ export const updateParticipantApiRolesWithTransaction = async (
export const updateParticipantAndTypesAndApiRoles = async (
participant: Participant,
participantApprovalPartial: z.infer<typeof ParticipantApprovalPartial> & {
status: ParticipantStatus;
approverId: number | undefined;
dateApproved: Date;
}
Expand All @@ -176,7 +159,6 @@ export const updateParticipantAndTypesAndApiRoles = async (
await participant.$query(trx).patch({
name: participantApprovalPartial.name,
siteId: participantApprovalPartial.siteId,
status: participantApprovalPartial.status,
approverId: participantApprovalPartial.approverId,
dateApproved: participantApprovalPartial.dateApproved,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable('participants', (table) => {
table.dropColumn('status');
});
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable('participants', (table) => {
table.enu('status', ['initialize', 'awaitingApproval', 'approved']).notNullable();
});
}
8 changes: 1 addition & 7 deletions src/database/seeds/Participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Knex } from 'knex';
import { ModelObject } from 'objection';
import { Optional } from 'utility-types';

import { Participant, ParticipantStatus } from '../../api/entities/Participant';
import { Participant } from '../../api/entities/Participant';

type ParticipantsType = ModelObject<Participant>;
const sampleData: Optional<
Expand All @@ -12,7 +12,6 @@ const sampleData: Optional<
{
name: 'Publisher example',
allowSharing: true,
status: ParticipantStatus.Approved,
type: 'Publisher',
siteId: 124,
apiRoleNames: ['GENERATOR', 'SHARER'],
Expand All @@ -21,7 +20,6 @@ const sampleData: Optional<
},
{
name: 'DSP example',
status: ParticipantStatus.Approved,
type: 'DSP',
allowSharing: true,
siteId: 123,
Expand All @@ -31,7 +29,6 @@ const sampleData: Optional<
},
{
name: 'DP example',
status: ParticipantStatus.Approved,
allowSharing: true,
type: 'Data Provider',
siteId: 125,
Expand All @@ -42,7 +39,6 @@ const sampleData: Optional<
{
name: 'Advertiser example',
allowSharing: true,
status: ParticipantStatus.Approved,
type: 'Advertiser',
siteId: 126,
apiRoleNames: ['MAPPER', 'SHARER'],
Expand All @@ -52,7 +48,6 @@ const sampleData: Optional<
{
name: 'AwaitingSigning example',
allowSharing: true,
status: ParticipantStatus.AwaitingSigning,
type: 'Publisher',
apiRoleNames: ['GENERATOR', 'SHARER'],
completedRecommendations: false,
Expand All @@ -72,7 +67,6 @@ export async function CreateParticipant(
const participant = await knex('participants')
.insert({
name: details.name,
status: details.status,
siteId: details.siteId,
})
.returning('id');
Expand Down
2 changes: 0 additions & 2 deletions src/database/seeds/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Knex } from 'knex';
import { ModelObject } from 'objection';
import { Optional } from 'utility-types';

import { ParticipantStatus } from '../../api/entities/Participant';
import { User, UserJobFunction } from '../../api/entities/User';
import { UserRoleId } from '../../api/entities/UserRole';
import { CreateParticipant } from './Participants';
Expand All @@ -11,7 +10,6 @@ type UserType = ModelObject<User>;

const sampleParticipant = {
name: 'Awaiting Approval',
status: ParticipantStatus.AwaitingApproval,
allowSharing: true,
completedRecommendations: false,
crmAgreementNumber: '12345678',
Expand Down
5 changes: 1 addition & 4 deletions src/testHelpers/apiTestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Response } from 'express';
import { Knex } from 'knex';

import { ModelObjectOpt } from '../api/entities/ModelObjectOpt';
import { Participant, ParticipantStatus } from '../api/entities/Participant';
import { Participant } from '../api/entities/Participant';
import { User, UserJobFunction } from '../api/entities/User';
import { UserRoleId } from '../api/entities/UserRole';
import { UserToParticipantRole } from '../api/entities/UserToParticipantRole';
Expand Down Expand Up @@ -68,15 +68,13 @@ export async function createParticipant(
{
name = faker.company.name(),
allowSharing = true,
status = ParticipantStatus.Approved,
type = 'Publisher',
apiRoleNames = [],
completedRecommendations = false,
crmAgreementNumber = '12345678',
}: {
name?: string;
allowSharing?: boolean;
status?: ParticipantStatus;
type?: string;
completedRecommendations?: boolean;
apiRoleNames?: string[];
Expand All @@ -86,7 +84,6 @@ export async function createParticipant(
const data = {
name,
allowSharing,
status,
completedRecommendations,
crmAgreementNumber,
};
Expand Down
3 changes: 1 addition & 2 deletions src/testHelpers/dataMocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { faker } from '@faker-js/faker';

import { Participant, ParticipantDTO, ParticipantStatus } from '../api/entities/Participant';
import { Participant, ParticipantDTO } from '../api/entities/Participant';
import { UserJobFunction } from '../api/entities/User';
import { UserWithParticipantRoles } from '../api/services/usersService';

Expand Down Expand Up @@ -29,7 +29,6 @@ export const createMockUser = (participants: Participant[]): UserWithParticipant
export const createMockParticipant = (): ParticipantDTO => ({
id: faker.number.int(),
name: faker.company.name(),
status: ParticipantStatus.Approved,
allowSharing: true,
completedRecommendations: faker.datatype.boolean(),
crmAgreementNumber: '12345678',
Expand Down
4 changes: 1 addition & 3 deletions src/web/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useKeycloak } from '@react-keycloak/web';
import { StrictMode, useCallback, useContext } from 'react';
import { Outlet, useLocation } from 'react-router-dom';

import { ParticipantStatus } from '../api/entities/Participant';
import { EnvironmentBanner } from './components/Core/Banner/EnvironmentBanner';
import { ErrorView } from './components/Core/ErrorView/ErrorView';
import { Loading } from './components/Core/Loading/Loading';
Expand Down Expand Up @@ -34,8 +33,7 @@ function AppContent() {
return <NoParticipantAccessView user={LoggedInUser?.user} />;
}

const showUpdatesTour =
participant?.status === ParticipantStatus.Approved && !!LoggedInUser?.user?.acceptedTerms;
const showUpdatesTour = !!LoggedInUser?.user?.acceptedTerms;

return (
<>
Expand Down
Loading

0 comments on commit aa7ccb1

Please sign in to comment.