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