Skip to content

Commit

Permalink
Skipped validation for IDIR users (Impersonate). (#286)
Browse files Browse the repository at this point in the history
Co-authored-by: weskubo-cgi <[email protected]>
  • Loading branch information
weskubo-cgi and weskubo-cgi authored Jul 11, 2024
1 parent 8bdf208 commit c5f3bc7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion backend/src/middlewares/validateContact.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const log = require('../components/logger')
const { isIdirUser } = require('../components/utils')

/**
* Validates that the request contact is the current user
Expand All @@ -9,9 +10,10 @@ module.exports = function () {
return async function (req, res, next) {
log.verbose(`validating contact`)

if (isIdirUser(req)) return next()

const contactId = req?.params.contactId
if (!contactId) return next()

const valid = contactId === req.session?.passport?.user.contactId

valid ? next() : res.sendStatus(403)
Expand Down
4 changes: 3 additions & 1 deletion backend/src/middlewares/validateFacility.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const log = require('../components/logger')
const { isIdirUser } = require('../components/utils')

/**
* Validates that the user is authorized to work with the specified Facility.
Expand All @@ -8,8 +9,9 @@ const log = require('../components/logger')
module.exports = function (portalAccess = true) {
return async function (req, res, next) {
log.verbose(`validating facility`)
const facilityId = req.params.facilityId ?? req.query.facilityId ?? req.body.facilityId
if (isIdirUser(req)) return next()

const facilityId = req.params.facilityId ?? req.query.facilityId ?? req.body.facilityId
if (!facilityId) return next()

let valid
Expand Down
5 changes: 5 additions & 0 deletions backend/src/middlewares/validateOrganization.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const log = require('../components/logger')
const { isIdirUser } = require('../components/utils')

/**
* Validates that the user is authorized to work with the specified Organization.
Expand All @@ -8,8 +9,12 @@ const log = require('../components/logger')
module.exports = function () {
return async function (req, res, next) {
log.verbose(`validating organization`)

if (isIdirUser(req)) return next()

const organizationId = req.params.organizationId ?? req.query.organizationId ?? req.body.organizationId
if (!organizationId) return next()

const valid = organizationId === req.session?.passport?.user?.organizationId

valid ? next() : res.sendStatus(403)
Expand Down

0 comments on commit c5f3bc7

Please sign in to comment.