Skip to content

Commit

Permalink
Merge pull request #568 from IABTechLab/ans-UID2-3901-remove-approver…
Browse files Browse the repository at this point in the history
…s-table

Remove approvers table
  • Loading branch information
ashleysmithTTD authored Nov 5, 2024
2 parents c2e9444 + 1dbdf8a commit f6861ad
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 167 deletions.
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -297,26 +297,21 @@ 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 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 @displayName as nvarchar(256) = '<first name> <last name>'
declare @email as nvarchar(256) = '<Enter your email here>'
declare @email as nvarchar(256) = '[email protected]';
declare @uid2SupportRoleId as int = 3;
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, @uid2SupportRoleId
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.
Expand Down
23 changes: 0 additions & 23 deletions src/api/entities/Approver.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/api/routers/participants/participantsApproval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,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
);
Expand Down
15 changes: 0 additions & 15 deletions src/api/services/approversService.ts

This file was deleted.

15 changes: 4 additions & 11 deletions src/api/services/participantsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import {
mapClientTypeIdsToAdminEnums,
SharingListResponse,
} from './adminServiceHelpers';
import { findApproversByType, getApprovableParticipantTypeIds } from './approversService';
import {
constructAuditTrailObject,
performAsyncOperationWithAuditTrail,
} from './auditTrailService';
import { createEmailService } from './emailService';
import { EmailArgs } from './emailTypes';
import { getAllUid2SupportUsers } from './uid2SupportService';

export interface ParticipantRequest extends Request {
participant?: Participant;
Expand Down Expand Up @@ -68,12 +68,12 @@ export const sendNewParticipantEmail = async (
jobFunction: requestor.jobFunction,
};

const approvers = await findApproversByType(typeIds);
const uid2SupportUsers = await getAllUid2SupportUsers();
const emailArgs: EmailArgs = {
subject: 'New Participant Request',
templateData,
template: 'newParticipantReadyForReview',
to: approvers.map((a) => ({ name: a.displayName, email: a.email })),
to: uid2SupportUsers.map((user) => ({ name: user!.firstName, email: user!.email })),
};
emailService.sendEmail(emailArgs, traceId);
};
Expand All @@ -100,15 +100,8 @@ export const mapParticipantToApprovalRequest = (
};
};

export const getParticipantsAwaitingApproval = async (email: string): Promise<Participant[]> => {
const approvableParticipantTypeIds = await getApprovableParticipantTypeIds(email);
export const getParticipantsAwaitingApproval = async (): Promise<Participant[]> => {
const participantsAwaitingApproval = await Participant.query()
.whereIn(
'id',
Participant.relatedQuery('types')
.whereIn('participantTypeId', approvableParticipantTypeIds)
.select('participantId')
)
.withGraphFetched('[types, users]')
.where('status', ParticipantStatus.AwaitingApproval);
return participantsAwaitingApproval;
Expand Down
15 changes: 15 additions & 0 deletions src/api/services/uid2SupportService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { User } from '../entities/User';
import { UserRoleId } from '../entities/UserRole';
import { UserToParticipantRole } from '../entities/UserToParticipantRole';

export const getAllUid2SupportUsers = async () => {
const uid2SupportUserToParticipantRoles = await UserToParticipantRole.query()
.distinct('userId')
.where('userRoleId', UserRoleId.UID2Support);
const uid2SupportUsers = await Promise.all(
uid2SupportUserToParticipantRoles.map(async (user) => {
return User.query().findOne('id', user.userId);
})
);
return uid2SupportUsers.filter((user) => user !== undefined);
};
23 changes: 0 additions & 23 deletions src/api/tests/queryMocks.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -103,25 +102,3 @@ export const mockBusinessContact = (businessContact: Partial<BusinessContact> |
)
);
};

type PartialApproverOrNull = Partial<Approver> | 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: '[email protected]',
displayName: 'Test Admin',
participantTypeId: 1,
...a,
},
]
)
);
});
};
18 changes: 18 additions & 0 deletions src/database/migrations/20241104084200_DeleteApproversTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
await knex.schema.dropTableIfExists('approvers');
}

export async function down(knex: Knex): Promise<void> {
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');
});
}
78 changes: 0 additions & 78 deletions src/database/seeds/Approvers.ts

This file was deleted.

0 comments on commit f6861ad

Please sign in to comment.