Skip to content

Commit

Permalink
Merge pull request #1801 from dbauszus-glx/admin-roles-param
Browse files Browse the repository at this point in the history
Provide user roles param for admin requests.
  • Loading branch information
RobAndrewHurst authored Jan 10, 2025
2 parents 494e713 + e8af809 commit f5faa34
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mod/user/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The auth method checks either the request parameter token or user.session if ena
@property {Object} [headers.authorization] User authorization object.
@property {Object} req.params Request parameters.
@property {string} [params.token] JWT.
@property {string} [params.roles] An admin user may provide a comma seperated strings as roles param to test requests.
@property {Object} [req.cookies] Request cookies.
@returns {Promise<Object|Error>} Method resolves to either a user object or Error
Expand Down Expand Up @@ -94,6 +95,12 @@ module.exports = async function auth(req, res) {
return sessionCheck
}

// Assign roles from request param for admin user.
if (user?.admin === true && req.params.roles) {

user.roles = req.params.roles.split(',')
}

return user
}

Expand Down

0 comments on commit f5faa34

Please sign in to comment.