From d401a0ecd844602af84604b0d550fba7b999c130 Mon Sep 17 00:00:00 2001 From: Ashley Smith Date: Mon, 4 Nov 2024 09:45:58 -0700 Subject: [PATCH 1/7] start of removing approvers references --- src/api/entities/Approver.ts | 42 ++++++++++++++-------------- src/api/services/approversService.ts | 24 ++++++++-------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/api/entities/Approver.ts b/src/api/entities/Approver.ts index b7f1011f9..6032f6169 100644 --- a/src/api/entities/Approver.ts +++ b/src/api/entities/Approver.ts @@ -1,23 +1,23 @@ -import { Model } from 'objection'; +// import { Model } from 'objection'; -import { BaseModel } from './BaseModel'; +// import { BaseModel } from './BaseModel'; -export class Approver extends BaseModel { - static get tableName() { - return 'approvers'; - } - static relationMappings = { - type: { - relation: Model.BelongsToOneRelation, - modelClass: 'ParticipantType', - join: { - from: 'approvers.participantTypeId', - to: 'participantsToTypes.id', - }, - }, - }; - declare id: number; - declare email: string; - declare participantTypeId: number; - declare displayName: string; -} +// export class Approver extends BaseModel { +// static get tableName() { +// return 'approvers'; +// } +// static relationMappings = { +// type: { +// relation: Model.BelongsToOneRelation, +// modelClass: 'ParticipantType', +// join: { +// from: 'approvers.participantTypeId', +// to: 'participantsToTypes.id', +// }, +// }, +// }; +// declare id: number; +// declare email: string; +// declare participantTypeId: number; +// declare displayName: string; +// } diff --git a/src/api/services/approversService.ts b/src/api/services/approversService.ts index 791f3eb6a..cc4942758 100644 --- a/src/api/services/approversService.ts +++ b/src/api/services/approversService.ts @@ -1,15 +1,15 @@ -import { Approver } from '../entities/Approver'; +// import { Approver } from '../entities/Approver'; -export const findApproversByType = async (typeIds: number[]) => { - return Approver.query().distinct('email').whereIn('participantTypeId', typeIds); -}; +// export const findApproversByType = async (typeIds: number[]) => { +// return Approver.query().distinct('email').whereIn('participantTypeId', typeIds); +// }; -export const isUserAnApprover = async (email: string) => { - const userInApproversTable = await Approver.query().findOne('email', email); - return userInApproversTable !== undefined; -}; +// export const isUserAnApprover = async (email: string) => { +// const userInApproversTable = await Approver.query().findOne('email', email); +// return userInApproversTable !== undefined; +// }; -export const getApprovableParticipantTypeIds = async (email: string) => { - const approvers = await Approver.query().distinct('participantTypeId').where('email', email); - return approvers.map((approver) => approver.participantTypeId); -}; +// export const getApprovableParticipantTypeIds = async (email: string) => { +// const approvers = await Approver.query().distinct('participantTypeId').where('email', email); +// return approvers.map((approver) => approver.participantTypeId); +// }; From ad7257a08ae38eb4d5df5c14ed1a2feb24b20981 Mon Sep 17 00:00:00 2001 From: Ashley Smith Date: Mon, 4 Nov 2024 09:46:41 -0700 Subject: [PATCH 2/7] wip remoivng approvers table --- src/api/services/participantsService.ts | 6 +- src/api/services/uid2SupportService.ts | 15 ++ .../20241104084200_DeleteApproversTable.ts | 18 +++ src/database/seeds/Approvers.ts | 148 +++++++++--------- 4 files changed, 111 insertions(+), 76 deletions(-) create mode 100644 src/api/services/uid2SupportService.ts create mode 100644 src/database/migrations/20241104084200_DeleteApproversTable.ts diff --git a/src/api/services/participantsService.ts b/src/api/services/participantsService.ts index 1113ae7d0..54727f2b3 100644 --- a/src/api/services/participantsService.ts +++ b/src/api/services/participantsService.ts @@ -24,6 +24,7 @@ import { } from './auditTrailService'; import { createEmailService } from './emailService'; import { EmailArgs } from './emailTypes'; +import { getAllUid2Support } from './uid2SupportService'; export interface ParticipantRequest extends Request { participant?: Participant; @@ -63,12 +64,13 @@ export const sendNewParticipantEmail = async ( jobFunction: requestor.jobFunction, }; - const approvers = await findApproversByType(typeIds); + //const approvers = await findApproversByType(typeIds); + const uid2SupportApprovers = await getAllUid2Support(); const emailArgs: EmailArgs = { subject: 'New Participant Request', templateData, template: 'newParticipantReadyForReview', - to: approvers.map((a) => ({ name: a.displayName, email: a.email })), + to: uid2SupportApprovers.map((a) => ({ name: a.firstName, email: a.email })), }; emailService.sendEmail(emailArgs, traceId); }; diff --git a/src/api/services/uid2SupportService.ts b/src/api/services/uid2SupportService.ts new file mode 100644 index 000000000..73600516e --- /dev/null +++ b/src/api/services/uid2SupportService.ts @@ -0,0 +1,15 @@ +import { User } from '../entities/User'; +import { UserRoleId } from '../entities/UserRole'; +import { UserToParticipantRole } from '../entities/UserToParticipantRole'; + +export const getAllUid2Support = async () => { + const uid2SupportUserToParticipantRoles = await UserToParticipantRole.query() + .distinct('userId') + .where('userRoleId', UserRoleId.UID2Support); + const uid2SupportUsers = await Promise.all( + uid2SupportUserToParticipantRoles.map(async (user) => { + return await User.query().findOne('id', user.userId); + }) + ); + return uid2SupportUsers.filter((user) => user !== undefined); +}; diff --git a/src/database/migrations/20241104084200_DeleteApproversTable.ts b/src/database/migrations/20241104084200_DeleteApproversTable.ts new file mode 100644 index 000000000..68cdc411a --- /dev/null +++ b/src/database/migrations/20241104084200_DeleteApproversTable.ts @@ -0,0 +1,18 @@ +import { Knex } from 'knex'; + +export async function up(knex: Knex): Promise { + await knex.schema.dropTableIfExists('approvers'); +} + +export async function down(knex: Knex): Promise { + await knex.schema.createTable('approvers', (table) => { + table.increments('id').primary(); + table.string('displayName', 256); + table.string('email', 256).notNullable(); + table + .integer('participantTypeId') + .references('id') + .inTable('participantTypes') + .onDelete('CASCADE'); + }); +} diff --git a/src/database/seeds/Approvers.ts b/src/database/seeds/Approvers.ts index b4d258214..37ea6e1ca 100644 --- a/src/database/seeds/Approvers.ts +++ b/src/database/seeds/Approvers.ts @@ -1,78 +1,78 @@ -import { Knex } from 'knex'; -import { ModelObject } from 'objection'; -import { Optional } from 'utility-types'; +// import { Knex } from 'knex'; +// import { ModelObject } from 'objection'; +// import { Optional } from 'utility-types'; -import { Approver } from '../../api/entities/Approver'; +// import { Approver } from '../../api/entities/Approver'; -type ApproverType = ModelObject; -const sampleData: Optional[] = [ - { - email: 'dsp_approver@example.com', - displayName: 'DSP Approver', - type: 'DSP', - }, - { - email: 'advertiser_approver@example.com', - displayName: 'Advertiser Approver', - type: 'Advertiser', - }, - { - email: 'publisher_approver@example.com', - displayName: 'Publisher Approver', - type: 'Publisher', - }, - { - email: 'dp_approver@example.com', - displayName: 'Data Provider Approver', - type: 'Data Provider', - }, - { - email: 'test@example.com', - displayName: 'Test Admin', - type: 'DSP', - }, - { - email: 'test@example.com', - displayName: 'Test Admin', - type: 'Advertiser', - }, - { - email: 'test@example.com', - displayName: 'Test Admin', - type: 'Publisher', - }, - { - email: 'test@example.com', - displayName: 'Test Admin', - type: 'Data Provider', - }, -]; +// type ApproverType = ModelObject; +// const sampleData: Optional[] = [ +// { +// email: 'dsp_approver@example.com', +// displayName: 'DSP Approver', +// type: 'DSP', +// }, +// { +// email: 'advertiser_approver@example.com', +// displayName: 'Advertiser Approver', +// type: 'Advertiser', +// }, +// { +// email: 'publisher_approver@example.com', +// displayName: 'Publisher Approver', +// type: 'Publisher', +// }, +// { +// email: 'dp_approver@example.com', +// displayName: 'Data Provider Approver', +// type: 'Data Provider', +// }, +// { +// email: 'test@example.com', +// displayName: 'Test Admin', +// type: 'DSP', +// }, +// { +// email: 'test@example.com', +// displayName: 'Test Admin', +// type: 'Advertiser', +// }, +// { +// email: 'test@example.com', +// displayName: 'Test Admin', +// type: 'Publisher', +// }, +// { +// email: 'test@example.com', +// displayName: 'Test Admin', +// type: 'Data Provider', +// }, +// ]; -export async function CreateApprover( - knex: Knex, - details: Optional -) { - const participantType = await knex('participantTypes').where('typeName', details.type); - return knex('approvers').insert<{ - email: number; - participantTypeId: number; - displayName: string; - }>({ - email: details.email, - participantTypeId: participantType[0].id as number, - displayName: details.displayName, - }); -} +// export async function CreateApprover( +// knex: Knex, +// details: Optional +// ) { +// const participantType = await knex('participantTypes').where('typeName', details.type); +// return knex('approvers').insert<{ +// email: number; +// participantTypeId: number; +// displayName: string; +// }>({ +// email: details.email, +// participantTypeId: participantType[0].id as number, +// displayName: details.displayName, +// }); +// } -export async function seed(knex: Knex): Promise { - // Deletes ALL existing entries - await knex('approvers') - .whereIn( - 'email', - sampleData.map((d) => d.email) - ) - .del(); - // Inserts seed entries - const promises = sampleData.map((sample) => CreateApprover(knex, sample)); - await Promise.all(promises); -} +// export async function seed(knex: Knex): Promise { +// // Deletes ALL existing entries +// await knex('approvers') +// .whereIn( +// 'email', +// sampleData.map((d) => d.email) +// ) +// .del(); +// // Inserts seed entries +// const promises = sampleData.map((sample) => CreateApprover(knex, sample)); +// await Promise.all(promises); +// } From 4da9e5c97875c2f95f455a70204b3d90fde9b3ed Mon Sep 17 00:00:00 2001 From: Ashley Smith Date: Mon, 4 Nov 2024 10:02:29 -0700 Subject: [PATCH 3/7] removing approvers table uses --- src/api/entities/Approver.ts | 23 -------- src/api/services/approversService.ts | 15 ----- src/api/services/participantsService.ts | 24 ++++---- src/api/services/uid2SupportService.ts | 2 +- src/api/tests/queryMocks.ts | 44 +++++++------- src/database/seeds/Approvers.ts | 78 ------------------------- 6 files changed, 35 insertions(+), 151 deletions(-) delete mode 100644 src/api/entities/Approver.ts delete mode 100644 src/api/services/approversService.ts delete mode 100644 src/database/seeds/Approvers.ts diff --git a/src/api/entities/Approver.ts b/src/api/entities/Approver.ts deleted file mode 100644 index 6032f6169..000000000 --- a/src/api/entities/Approver.ts +++ /dev/null @@ -1,23 +0,0 @@ -// import { Model } from 'objection'; - -// import { BaseModel } from './BaseModel'; - -// export class Approver extends BaseModel { -// static get tableName() { -// return 'approvers'; -// } -// static relationMappings = { -// type: { -// relation: Model.BelongsToOneRelation, -// modelClass: 'ParticipantType', -// join: { -// from: 'approvers.participantTypeId', -// to: 'participantsToTypes.id', -// }, -// }, -// }; -// declare id: number; -// declare email: string; -// declare participantTypeId: number; -// declare displayName: string; -// } diff --git a/src/api/services/approversService.ts b/src/api/services/approversService.ts deleted file mode 100644 index cc4942758..000000000 --- a/src/api/services/approversService.ts +++ /dev/null @@ -1,15 +0,0 @@ -// import { Approver } from '../entities/Approver'; - -// export const findApproversByType = async (typeIds: number[]) => { -// return Approver.query().distinct('email').whereIn('participantTypeId', typeIds); -// }; - -// export const isUserAnApprover = async (email: string) => { -// const userInApproversTable = await Approver.query().findOne('email', email); -// return userInApproversTable !== undefined; -// }; - -// export const getApprovableParticipantTypeIds = async (email: string) => { -// const approvers = await Approver.query().distinct('participantTypeId').where('email', email); -// return approvers.map((approver) => approver.participantTypeId); -// }; diff --git a/src/api/services/participantsService.ts b/src/api/services/participantsService.ts index 54727f2b3..51e280131 100644 --- a/src/api/services/participantsService.ts +++ b/src/api/services/participantsService.ts @@ -17,14 +17,14 @@ import { SSP_WEB_BASE_URL } from '../envars'; import { getTraceId } from '../helpers/loggingHelpers'; import { getSharingList, setSiteClientTypes, updateSharingList } from './adminServiceClient'; import { ClientType, SharingListResponse } from './adminServiceHelpers'; -import { findApproversByType, getApprovableParticipantTypeIds } from './approversService'; +//import { getApprovableParticipantTypeIds } from './approversService'; import { constructAuditTrailObject, performAsyncOperationWithAuditTrail, } from './auditTrailService'; import { createEmailService } from './emailService'; import { EmailArgs } from './emailTypes'; -import { getAllUid2Support } from './uid2SupportService'; +import { getAllUid2SupportUsers } from './uid2SupportService'; export interface ParticipantRequest extends Request { participant?: Participant; @@ -65,12 +65,12 @@ export const sendNewParticipantEmail = async ( }; //const approvers = await findApproversByType(typeIds); - const uid2SupportApprovers = await getAllUid2Support(); + const uid2SupportUsers = await getAllUid2SupportUsers(); const emailArgs: EmailArgs = { subject: 'New Participant Request', templateData, template: 'newParticipantReadyForReview', - to: uid2SupportApprovers.map((a) => ({ name: a.firstName, email: a.email })), + to: uid2SupportUsers.map((user) => ({ name: user!.firstName, email: user!.email })), }; emailService.sendEmail(emailArgs, traceId); }; @@ -98,14 +98,14 @@ export const mapParticipantToApprovalRequest = ( }; export const getParticipantsAwaitingApproval = async (email: string): Promise => { - const approvableParticipantTypeIds = await getApprovableParticipantTypeIds(email); + //const approvableParticipantTypeIds = await getApprovableParticipantTypeIds(email); const participantsAwaitingApproval = await Participant.query() - .whereIn( - 'id', - Participant.relatedQuery('types') - .whereIn('participantTypeId', approvableParticipantTypeIds) - .select('participantId') - ) + // .whereIn( + // 'id', + // Participant.relatedQuery('types') + // .whereIn('participantTypeId', approvableParticipantTypeIds) + // .select('participantId') + // ) .withGraphFetched('[types, users]') .where('status', ParticipantStatus.AwaitingApproval); return participantsAwaitingApproval; @@ -123,7 +123,7 @@ export const getAttachedSiteIDs = async (): Promise => { export const getParticipantsApproved = async (): Promise => { return Participant.query() .where('status', ParticipantStatus.Approved) - .withGraphFetched('[apiRoles, approver, types, users]'); + .withGraphFetched('[apiRoles, types, users]'); }; export const getParticipantsBySiteIds = async (siteIds: number[]) => { diff --git a/src/api/services/uid2SupportService.ts b/src/api/services/uid2SupportService.ts index 73600516e..b1280fb41 100644 --- a/src/api/services/uid2SupportService.ts +++ b/src/api/services/uid2SupportService.ts @@ -2,7 +2,7 @@ import { User } from '../entities/User'; import { UserRoleId } from '../entities/UserRole'; import { UserToParticipantRole } from '../entities/UserToParticipantRole'; -export const getAllUid2Support = async () => { +export const getAllUid2SupportUsers = async () => { const uid2SupportUserToParticipantRoles = await UserToParticipantRole.query() .distinct('userId') .where('userRoleId', UserRoleId.UID2Support); diff --git a/src/api/tests/queryMocks.ts b/src/api/tests/queryMocks.ts index 03ac95311..023aeeead 100644 --- a/src/api/tests/queryMocks.ts +++ b/src/api/tests/queryMocks.ts @@ -1,6 +1,6 @@ import { QueryBuilder } from 'objection'; -import { Approver } from '../entities/Approver'; +// import { Approver } from '../entities/Approver'; import { BusinessContact, ContactType } from '../entities/BusinessContact'; import { Participant } from '../entities/Participant'; import { User } from '../entities/User'; @@ -104,24 +104,24 @@ export const mockBusinessContact = (businessContact: Partial | ); }; -type PartialApproverOrNull = Partial | null; -export const mockApprover = (approver: PartialApproverOrNull | PartialApproverOrNull[] = {}) => { - const approvers = Array.isArray(approver) ? approver : [approver]; - approvers.forEach((a) => { - jest.spyOn(Approver, 'query').mockReturnValueOnce( - QueryBuilder.forClass(Approver).resolve( - a === null - ? undefined - : [ - { - id: 1, - email: 'test_user@example.com', - displayName: 'Test Admin', - participantTypeId: 1, - ...a, - }, - ] - ) - ); - }); -}; +// type PartialApproverOrNull = Partial | null; +// export const mockApprover = (approver: PartialApproverOrNull | PartialApproverOrNull[] = {}) => { +// const approvers = Array.isArray(approver) ? approver : [approver]; +// approvers.forEach((a) => { +// jest.spyOn(Approver, 'query').mockReturnValueOnce( +// QueryBuilder.forClass(Approver).resolve( +// a === null +// ? undefined +// : [ +// { +// id: 1, +// email: 'test_user@example.com', +// displayName: 'Test Admin', +// participantTypeId: 1, +// ...a, +// }, +// ] +// ) +// ); +// }); +// }; diff --git a/src/database/seeds/Approvers.ts b/src/database/seeds/Approvers.ts deleted file mode 100644 index 37ea6e1ca..000000000 --- a/src/database/seeds/Approvers.ts +++ /dev/null @@ -1,78 +0,0 @@ -// import { Knex } from 'knex'; -// import { ModelObject } from 'objection'; -// import { Optional } from 'utility-types'; - -// import { Approver } from '../../api/entities/Approver'; - -// type ApproverType = ModelObject; -// const sampleData: Optional[] = [ -// { -// email: 'dsp_approver@example.com', -// displayName: 'DSP Approver', -// type: 'DSP', -// }, -// { -// email: 'advertiser_approver@example.com', -// displayName: 'Advertiser Approver', -// type: 'Advertiser', -// }, -// { -// email: 'publisher_approver@example.com', -// displayName: 'Publisher Approver', -// type: 'Publisher', -// }, -// { -// email: 'dp_approver@example.com', -// displayName: 'Data Provider Approver', -// type: 'Data Provider', -// }, -// { -// email: 'test@example.com', -// displayName: 'Test Admin', -// type: 'DSP', -// }, -// { -// email: 'test@example.com', -// displayName: 'Test Admin', -// type: 'Advertiser', -// }, -// { -// email: 'test@example.com', -// displayName: 'Test Admin', -// type: 'Publisher', -// }, -// { -// email: 'test@example.com', -// displayName: 'Test Admin', -// type: 'Data Provider', -// }, -// ]; - -// export async function CreateApprover( -// knex: Knex, -// details: Optional -// ) { -// const participantType = await knex('participantTypes').where('typeName', details.type); -// return knex('approvers').insert<{ -// email: number; -// participantTypeId: number; -// displayName: string; -// }>({ -// email: details.email, -// participantTypeId: participantType[0].id as number, -// displayName: details.displayName, -// }); -// } - -// export async function seed(knex: Knex): Promise { -// // Deletes ALL existing entries -// await knex('approvers') -// .whereIn( -// 'email', -// sampleData.map((d) => d.email) -// ) -// .del(); -// // Inserts seed entries -// const promises = sampleData.map((sample) => CreateApprover(knex, sample)); -// await Promise.all(promises); -// } From 5be040b471f5e844338c7d0a1fa5db300f715046 Mon Sep 17 00:00:00 2001 From: Ashley Smith Date: Mon, 4 Nov 2024 10:33:19 -0700 Subject: [PATCH 4/7] email arg no longer needed --- src/api/routers/participants/participantsApproval.ts | 3 +-- src/api/services/participantsService.ts | 10 +++++----- src/api/services/uid2SupportService.ts | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/api/routers/participants/participantsApproval.ts b/src/api/routers/participants/participantsApproval.ts index 034e5cc39..687304e84 100644 --- a/src/api/routers/participants/participantsApproval.ts +++ b/src/api/routers/participants/participantsApproval.ts @@ -27,8 +27,7 @@ export const handleGetParticipantsAwaitingApproval = async ( req: ParticipantRequest, res: Response ) => { - const email = String(req.auth?.payload?.email); - const participantsAwaitingApproval = await getParticipantsAwaitingApproval(email); + const participantsAwaitingApproval = await getParticipantsAwaitingApproval(); const result: ParticipantRequestDTO[] = participantsAwaitingApproval.map( mapParticipantToApprovalRequest ); diff --git a/src/api/services/participantsService.ts b/src/api/services/participantsService.ts index 51e280131..fc358a645 100644 --- a/src/api/services/participantsService.ts +++ b/src/api/services/participantsService.ts @@ -17,7 +17,7 @@ import { SSP_WEB_BASE_URL } from '../envars'; import { getTraceId } from '../helpers/loggingHelpers'; import { getSharingList, setSiteClientTypes, updateSharingList } from './adminServiceClient'; import { ClientType, SharingListResponse } from './adminServiceHelpers'; -//import { getApprovableParticipantTypeIds } from './approversService'; +// import { getApprovableParticipantTypeIds } from './approversService'; import { constructAuditTrailObject, performAsyncOperationWithAuditTrail, @@ -64,7 +64,7 @@ export const sendNewParticipantEmail = async ( jobFunction: requestor.jobFunction, }; - //const approvers = await findApproversByType(typeIds); + // const approvers = await findApproversByType(typeIds); const uid2SupportUsers = await getAllUid2SupportUsers(); const emailArgs: EmailArgs = { subject: 'New Participant Request', @@ -97,8 +97,8 @@ export const mapParticipantToApprovalRequest = ( }; }; -export const getParticipantsAwaitingApproval = async (email: string): Promise => { - //const approvableParticipantTypeIds = await getApprovableParticipantTypeIds(email); +export const getParticipantsAwaitingApproval = async (): Promise => { + // const approvableParticipantTypeIds = await getApprovableParticipantTypeIds(email); const participantsAwaitingApproval = await Participant.query() // .whereIn( // 'id', @@ -123,7 +123,7 @@ export const getAttachedSiteIDs = async (): Promise => { export const getParticipantsApproved = async (): Promise => { return Participant.query() .where('status', ParticipantStatus.Approved) - .withGraphFetched('[apiRoles, types, users]'); + .withGraphFetched('[apiRoles, approver, types, users]'); }; export const getParticipantsBySiteIds = async (siteIds: number[]) => { diff --git a/src/api/services/uid2SupportService.ts b/src/api/services/uid2SupportService.ts index b1280fb41..5579ca7b0 100644 --- a/src/api/services/uid2SupportService.ts +++ b/src/api/services/uid2SupportService.ts @@ -8,7 +8,7 @@ export const getAllUid2SupportUsers = async () => { .where('userRoleId', UserRoleId.UID2Support); const uid2SupportUsers = await Promise.all( uid2SupportUserToParticipantRoles.map(async (user) => { - return await User.query().findOne('id', user.userId); + return User.query().findOne('id', user.userId); }) ); return uid2SupportUsers.filter((user) => user !== undefined); From 03f2ea1a58476a46f93244fca6866fe95051202f Mon Sep 17 00:00:00 2001 From: Ashley Smith Date: Mon, 4 Nov 2024 10:36:13 -0700 Subject: [PATCH 5/7] remove commented out code about approvers --- src/api/services/participantsService.ts | 9 --------- src/api/tests/queryMocks.ts | 23 ----------------------- 2 files changed, 32 deletions(-) diff --git a/src/api/services/participantsService.ts b/src/api/services/participantsService.ts index fc358a645..75aa03428 100644 --- a/src/api/services/participantsService.ts +++ b/src/api/services/participantsService.ts @@ -17,7 +17,6 @@ import { SSP_WEB_BASE_URL } from '../envars'; import { getTraceId } from '../helpers/loggingHelpers'; import { getSharingList, setSiteClientTypes, updateSharingList } from './adminServiceClient'; import { ClientType, SharingListResponse } from './adminServiceHelpers'; -// import { getApprovableParticipantTypeIds } from './approversService'; import { constructAuditTrailObject, performAsyncOperationWithAuditTrail, @@ -64,7 +63,6 @@ export const sendNewParticipantEmail = async ( jobFunction: requestor.jobFunction, }; - // const approvers = await findApproversByType(typeIds); const uid2SupportUsers = await getAllUid2SupportUsers(); const emailArgs: EmailArgs = { subject: 'New Participant Request', @@ -98,14 +96,7 @@ export const mapParticipantToApprovalRequest = ( }; export const getParticipantsAwaitingApproval = async (): Promise => { - // const approvableParticipantTypeIds = await getApprovableParticipantTypeIds(email); const participantsAwaitingApproval = await Participant.query() - // .whereIn( - // 'id', - // Participant.relatedQuery('types') - // .whereIn('participantTypeId', approvableParticipantTypeIds) - // .select('participantId') - // ) .withGraphFetched('[types, users]') .where('status', ParticipantStatus.AwaitingApproval); return participantsAwaitingApproval; diff --git a/src/api/tests/queryMocks.ts b/src/api/tests/queryMocks.ts index 023aeeead..353458404 100644 --- a/src/api/tests/queryMocks.ts +++ b/src/api/tests/queryMocks.ts @@ -1,6 +1,5 @@ import { QueryBuilder } from 'objection'; -// import { Approver } from '../entities/Approver'; import { BusinessContact, ContactType } from '../entities/BusinessContact'; import { Participant } from '../entities/Participant'; import { User } from '../entities/User'; @@ -103,25 +102,3 @@ export const mockBusinessContact = (businessContact: Partial | ) ); }; - -// type PartialApproverOrNull = Partial | null; -// export const mockApprover = (approver: PartialApproverOrNull | PartialApproverOrNull[] = {}) => { -// const approvers = Array.isArray(approver) ? approver : [approver]; -// approvers.forEach((a) => { -// jest.spyOn(Approver, 'query').mockReturnValueOnce( -// QueryBuilder.forClass(Approver).resolve( -// a === null -// ? undefined -// : [ -// { -// id: 1, -// email: 'test_user@example.com', -// displayName: 'Test Admin', -// participantTypeId: 1, -// ...a, -// }, -// ] -// ) -// ); -// }); -// }; From 4981e137b9623e26b4b2f55cb0cc5ec587f83240 Mon Sep 17 00:00:00 2001 From: Ashley Smith Date: Mon, 4 Nov 2024 15:56:20 -0700 Subject: [PATCH 6/7] read me sql query updated --- README.md | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 874283cad..4ec19fb38 100644 --- a/README.md +++ b/README.md @@ -297,26 +297,20 @@ The following steps describe the minimal steps required to successfully log in t 1. If using Visual Studio Code, you may need to set `FAST_REFRESH=false` in your .env file 1. Azure Data Studio is an adequate program for manipulating the SQL Server database -### Admin screens/routes +### UID2 Support Screens/Routes -Certain screens/routes are considered admin-only. Run the following to assign yourself as an admin: +Certain screens/routes are only able to view with the UID2 support role, such as the Manage Participants screen. Run the following to assign yourself the UID2 support role: ``` use [uid2_selfserve] -declare @displayName as nvarchar(256) = ' ' -declare @email as nvarchar(256) = '' +declare @email as nvarchar(256) = 'example@example.com'; -select * from dbo.approvers where email = @email - -insert into dbo.approvers (displayName, email, participantTypeId) -values -(@displayName, @email, 1), -(@displayName, @email, 2), -(@displayName, @email, 3), -(@displayName, @email, 4) - -select * from dbo.approvers where email = @email +insert into dbo.usersToParticipantRoles (userId, participantId, userRoleId) +select u.id, upr.participantId, 3 +from dbo.users u +join dbo.usersToParticipantRoles upr on u.id = upr.userId +where u.email = @email; ``` You will then want to assign some API Permissions to your participant in the `Manage Participants` screen. This will allow you to use the full functionality of the `API Keys` screen. From 1dbdf8a4c37b510701a9a85b5e932c487eb8d588 Mon Sep 17 00:00:00 2001 From: Ashley Smith Date: Tue, 5 Nov 2024 08:10:50 -0700 Subject: [PATCH 7/7] fixed broken link --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4ec19fb38..5a2f3d107 100644 --- a/README.md +++ b/README.md @@ -287,7 +287,7 @@ The following steps describe the minimal steps required to successfully log in t 1. Assign yourself the `api-participant-member` role by following these steps: [Assign Role to a Particular User](./KeycloakAdvancedSetup.md#assign-role-to-a-particular-user) 1. Run the Admin service locally by following [Connecting to local Admin service](#connecting-to-local-admin-service) -1. Optionally give your user access to the [Admin screens/routes](#admin-screensroutes) +1. Optionally give your user access to the [UID2 Support Screens/Routes](#uid2-support-screensroutes) 1. Return to the UI and you should be good to go! #### Notes for Mac OSX Development: @@ -299,15 +299,16 @@ The following steps describe the minimal steps required to successfully log in t ### UID2 Support Screens/Routes -Certain screens/routes are only able to view with the UID2 support role, such as the Manage Participants screen. Run the following to assign yourself the UID2 support role: +Certain screens/routes are only viewable with the UID2 support role, such as the screen to manage participants. Run the following to assign yourself the UID2 support role: ``` use [uid2_selfserve] declare @email as nvarchar(256) = 'example@example.com'; +declare @uid2SupportRoleId as int = 3; insert into dbo.usersToParticipantRoles (userId, participantId, userRoleId) -select u.id, upr.participantId, 3 +select u.id, upr.participantId, @uid2SupportRoleId from dbo.users u join dbo.usersToParticipantRoles upr on u.id = upr.userId where u.email = @email;