|
|
|
@ -73,6 +73,7 @@ function parseAuthHeader(headerValue) { |
|
|
|
|
* @returns {Object} |
|
|
|
|
*/ |
|
|
|
|
function getUserFromJwtPayload(jwtPayload) { |
|
|
|
|
|
|
|
|
|
const user = { |
|
|
|
|
id: jwtPayload.id, |
|
|
|
|
name: jwtPayload.name, |
|
|
|
@ -103,6 +104,7 @@ function checkStaffPermission(req, requestedPermissions) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check service permissions
|
|
|
|
|
const { permissions } = req.user; |
|
|
|
|
if (!Array.isArray(permissions) || permissions.length === 0) { |
|
|
|
@ -135,6 +137,7 @@ const getTokenInfo = (req) => { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
jwt.payload = jsonwentoken.decode(jwt.value, { json: true }); |
|
|
|
|
// console.log(jwt);
|
|
|
|
|
return jwt; |
|
|
|
|
}; |
|
|
|
|
/** |
|
|
|
@ -192,7 +195,7 @@ const loadInfo = async (req) => { |
|
|
|
|
req.tokenInfo = tokenInfo; |
|
|
|
|
req.authInfo = getAuthInfo(req); |
|
|
|
|
|
|
|
|
|
console.log(req.authInfo); |
|
|
|
|
// console.log(req.authInfo);
|
|
|
|
|
// load permission for staff
|
|
|
|
|
if (req.authInfo.accessLevel === ConsumerGroups.STAFF && user !== null) { |
|
|
|
|
req.user.permissions = await Configs.getStaffPermissions( |
|
|
|
@ -238,7 +241,7 @@ const checkPermission = async (req, permissions, additionalCheck) => { |
|
|
|
|
return null; |
|
|
|
|
case ConsumerGroups.STAFF: |
|
|
|
|
// remove user permission
|
|
|
|
|
console.log("1231231232"); |
|
|
|
|
// console.log("1231231232");
|
|
|
|
|
if (userPermissionIndex !== -1) { |
|
|
|
|
permissionsToCheck.splice(userPermissionIndex, 1); |
|
|
|
|
} |
|
|
|
@ -257,12 +260,12 @@ const checkPermission = async (req, permissions, additionalCheck) => { |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case ConsumerGroups.ADMINISTRATOR: |
|
|
|
|
if (adminPermissionIndex !== -1 && userPermissionIndex=== -1) { |
|
|
|
|
console.log("ConsumerGroups.ADMINISTRATOR"); |
|
|
|
|
return null |
|
|
|
|
}; |
|
|
|
|
break; |
|
|
|
|
// case ConsumerGroups.ADMINISTRATOR:
|
|
|
|
|
// if (adminPermissionIndex !== -1 && userPermissionIndex=== -1) {
|
|
|
|
|
// console.log("ConsumerGroups.ADMINISTRATOR");
|
|
|
|
|
// return null
|
|
|
|
|
// };
|
|
|
|
|
// break;
|
|
|
|
|
default: |
|
|
|
|
// reject guest access
|
|
|
|
|
return apiError; |
|
|
|
|