Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide user roles param for admin requests. #1801

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading