From 6dae1042a0f951b52e474bc68a2a7c80d86016ab Mon Sep 17 00:00:00 2001 From: Kyle Morel Date: Mon, 26 Aug 2024 11:33:48 -0700 Subject: [PATCH] Resolve rebase conflicts --- app/src/interfaces/IExpress.ts | 10 +++++++--- app/src/middleware/authentication.ts | 1 + app/src/middleware/requireSomeGroup.ts | 2 +- app/src/services/yars.ts | 4 ++-- app/src/types/CurrentContext.ts | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/interfaces/IExpress.ts b/app/src/interfaces/IExpress.ts index 5d839219..a849aee2 100644 --- a/app/src/interfaces/IExpress.ts +++ b/app/src/interfaces/IExpress.ts @@ -3,13 +3,17 @@ import * as core from 'express-serve-static-core'; import type { CurrentAuthorization } from '../types/CurrentAuthorization'; import type { CurrentContext } from '../types/CurrentContext'; +declare module 'express-serve-static-core' { + export interface Request { + currentAuthorization: CurrentAuthorization; + currentContext: CurrentContext; + } +} + interface Query extends core.Query {} interface Params extends core.ParamsDictionary {} - export interface Request

extends core.Request { - currentAuthorization?: CurrentAuthorization; - currentContext?: CurrentContext; params: P; query: Q; body: B; diff --git a/app/src/middleware/authentication.ts b/app/src/middleware/authentication.ts index 07e4cb6d..8138cfeb 100644 --- a/app/src/middleware/authentication.ts +++ b/app/src/middleware/authentication.ts @@ -55,6 +55,7 @@ export const currentContext = (initiative: Initiative) => { } if (isValid) { + currentContext.bearerToken = bearerToken; currentContext.tokenPayload = isValid as jwt.JwtPayload; const user = await userService.login(currentContext.tokenPayload); diff --git a/app/src/middleware/requireSomeGroup.ts b/app/src/middleware/requireSomeGroup.ts index d06bd254..908532d1 100644 --- a/app/src/middleware/requireSomeGroup.ts +++ b/app/src/middleware/requireSomeGroup.ts @@ -24,7 +24,7 @@ export const requireSomeGroup = async (req: Request, _res: Response, next: NextF // Auto assign all PROPONENT groups if user has none if (groups && groups.length === 0) { - await yarsService.assignGroup(sub, Initiative.HOUSING, GroupName.PROPONENT); + await yarsService.assignGroup(req.currentContext.bearerToken, sub, Initiative.HOUSING, GroupName.PROPONENT); groups = await yarsService.getSubjectGroups(sub); } diff --git a/app/src/services/yars.ts b/app/src/services/yars.ts index 2b5b9644..41c8f48e 100644 --- a/app/src/services/yars.ts +++ b/app/src/services/yars.ts @@ -9,13 +9,13 @@ const service = { * @function assignGroup * Assigns an identity to the given group * Assigns permissions to COMS based on the given group - * @param {string | null | undefined} bearerToken The bearer token of the authorized user + * @param {string | undefined} bearerToken The bearer token of the authorized user * @param {string} identityId Identity ID of the authorized user * @param {Initiative} initiative The initiative to associate with the group * @param {GroupName} group The group to add the user to * @returns {Promise<{identityId: string;roleId: number;}>} The result of running the create operation */ - assignGroup: async (sub: string, initiative: Initiative, group: GroupName) => { + assignGroup: async (bearerToken: string | undefined, sub: string, initiative: Initiative, group: GroupName) => { try { const i = await prisma.initiative.findFirstOrThrow({ where: { diff --git a/app/src/types/CurrentContext.ts b/app/src/types/CurrentContext.ts index 38a39f09..81d85586 100644 --- a/app/src/types/CurrentContext.ts +++ b/app/src/types/CurrentContext.ts @@ -4,8 +4,8 @@ import { AuthType, Initiative } from '../utils/enums/application'; export type CurrentContext = { authType?: AuthType; + bearerToken?: string; initiative?: Initiative; tokenPayload?: jwt.JwtPayload; - bearerToken: string | null; userId?: string; };