diff --git a/src/app/routes/api/v3/forms/public-form.middleware.ts b/src/app/routes/api/v3/forms/public-form.middleware.ts index 4811086f02..8cf77c2b89 100644 --- a/src/app/routes/api/v3/forms/public-form.middleware.ts +++ b/src/app/routes/api/v3/forms/public-form.middleware.ts @@ -1,9 +1,34 @@ +import { AuthedSessionData } from 'express-session' + import { killEmailMode } from '../../../../config/config' +import { createLoggerWithLabel } from '../../../../config/logger' import { ControllerHandler } from '../../../../modules/core/core.types' +import { createReqMeta } from '../../../../utils/request' + +const logger = createLoggerWithLabel(module) // TODO: (Kill Email Mode) Remove this route after kill email mode is fully implemented. -export const injectFeedbackFormUrl: ControllerHandler = (req, res, next) => { +export const authAndInjectFeedbackFormUrl: ControllerHandler = ( + req, + res, + next, +) => { const formId = killEmailMode.feedbackFormid req.params = { formId: formId } + const sessionUserId = (req.session as AuthedSessionData).user._id + + const logMeta = { + action: 'authAndInjectFeedbackFormUrl', + formId, + method: req.method, + sessionUserId, + ...createReqMeta(req), + } + + logger.info({ + message: 'Feedback form injected', + meta: logMeta, + }) + return next() } diff --git a/src/app/routes/api/v3/forms/public-forms.form.routes.ts b/src/app/routes/api/v3/forms/public-forms.form.routes.ts index 5563880fd3..b27d794bc2 100644 --- a/src/app/routes/api/v3/forms/public-forms.form.routes.ts +++ b/src/app/routes/api/v3/forms/public-forms.form.routes.ts @@ -3,7 +3,7 @@ import { Router } from 'express' import * as PublicFormController from '../../../../modules/form/public-form/public-form.controller' import * as WogaaController from '../../../../modules/wogaa/wogaa.controller' -import { injectFeedbackFormUrl } from './public-form.middleware' +import { authAndInjectFeedbackFormUrl } from './public-form.middleware' export const PublicFormsFormRouter = Router() @@ -50,6 +50,6 @@ PublicFormsFormRouter.route('/:formId([a-fA-F0-9]{24})/sample-submission').get( * @returns 500 when database error occurs */ PublicFormsFormRouter.route('/admin-use-email-feedback').get( - injectFeedbackFormUrl, + authAndInjectFeedbackFormUrl, PublicFormController.handleGetPublicForm, ) diff --git a/src/app/routes/api/v3/forms/public-forms.submissions.routes.ts b/src/app/routes/api/v3/forms/public-forms.submissions.routes.ts index e34aeeac56..35bddf5333 100644 --- a/src/app/routes/api/v3/forms/public-forms.submissions.routes.ts +++ b/src/app/routes/api/v3/forms/public-forms.submissions.routes.ts @@ -8,7 +8,7 @@ import * as SubmissionController from '../../../../modules/submission/submission import * as WogaaController from '../../../../modules/wogaa/wogaa.controller' import { limitRate } from '../../../../utils/limit-rate' -import { injectFeedbackFormUrl } from './public-form.middleware' +import { authAndInjectFeedbackFormUrl } from './public-form.middleware' export const PublicFormsSubmissionsRouter = Router() @@ -60,7 +60,7 @@ PublicFormsSubmissionsRouter.route( '/submissions/storage/email-mode-feedback', ).post( limitRate({ max: rateLimitConfig.submissions }), - injectFeedbackFormUrl, + authAndInjectFeedbackFormUrl, EncryptSubmissionController.handleStorageSubmission, )