-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add checkUserData utility function to check if user is an admin or he…
…lpdesk user and if they have no BAP combo keys, and use it in the empty BAP combo keys conditional in BAP /submissions endpoint to return an empty array instead of a 401 Unauthorized response for admin or helpdesk users
- Loading branch information
1 parent
9fe2a8d
commit 06d11fc
Showing
2 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const express = require("express"); | ||
|
||
/** | ||
* @typedef {Object} User | ||
* @property {string} mail | ||
* @property {string} memberof | ||
* @property {string} nameID | ||
* @property {string} nameIDFormat | ||
* @property {string} spNameQualifier | ||
* @property {string} sessionIndex | ||
* @property {number} iat | ||
* @property {number} exp | ||
*/ | ||
|
||
/** | ||
* Determines if the user is an admin or helpdesk user and if they have any BAP | ||
* combo keys. | ||
* | ||
* @param {Object} param | ||
* @param {express.Request} param.req | ||
*/ | ||
function checkUserData({ req }) { | ||
/** @type {{ bapComboKeys: string[]; user: User }} */ | ||
const { bapComboKeys, user } = req; | ||
|
||
const userRoles = user.memberof.split(","); | ||
const adminOrHelpdeskUser = | ||
userRoles.includes("csb_admin") || userRoles.includes("csb_helpdesk"); | ||
|
||
const noBapComboKeys = bapComboKeys?.length === 0; | ||
|
||
return { adminOrHelpdeskUser, noBapComboKeys }; | ||
} | ||
|
||
module.exports = { | ||
checkUserData, | ||
}; |