Skip to content

Commit

Permalink
feat: log user session during feedback form injection
Browse files Browse the repository at this point in the history
  • Loading branch information
KenLSM committed Dec 19, 2024
1 parent b4b56d1 commit 3621c80
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
27 changes: 26 additions & 1 deletion src/app/routes/api/v3/forms/public-form.middleware.ts
Original file line number Diff line number Diff line change
@@ -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()
}
4 changes: 2 additions & 2 deletions src/app/routes/api/v3/forms/public-forms.form.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -60,7 +60,7 @@ PublicFormsSubmissionsRouter.route(
'/submissions/storage/email-mode-feedback',
).post(
limitRate({ max: rateLimitConfig.submissions }),
injectFeedbackFormUrl,
authAndInjectFeedbackFormUrl,
EncryptSubmissionController.handleStorageSubmission,
)

Expand Down

0 comments on commit 3621c80

Please sign in to comment.