Skip to content

Commit 30fc001

Browse files
committed
Validate Group Ids are valid or not
1 parent 2501fac commit 30fc001

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/common/helper.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -896,9 +896,29 @@ async function validateChallengeTerms(terms = []) {
896896
async function _filterChallengesByGroupsAccess(currentUser, challenges) {
897897
const res = [];
898898
const needToCheckForGroupAccess = !currentUser
899-
? true
900-
: !currentUser.isMachine && !hasAdminRole(currentUser);
901-
if (!needToCheckForGroupAccess) return challenges;
899+
? true
900+
: !currentUser.isMachine && !hasAdminRole(currentUser);
901+
if(!needToCheckForGroupAccess)
902+
{
903+
for (const challenge of challenges) {
904+
if(challenge && challenge.groups && challenge.groups.length>0) {
905+
const promises = [];
906+
_.each(challenge.groups, (g) => {
907+
promises.push(
908+
(async () => {
909+
const group = await getGroupById(g);
910+
if ( !group || !group.status==='active') {
911+
throw new errors.BadRequestError("The groups provided are invalid "+g);
912+
}
913+
})()
914+
);
915+
});
916+
await Promise.all(promises);
917+
res.push(challenge);
918+
}
919+
}
920+
return res;
921+
}
902922

903923
let userGroups;
904924

0 commit comments

Comments
 (0)