Skip to content

Commit f976de1

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

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/common/helper.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,27 @@ async function _filterChallengesByGroupsAccess(currentUser, challenges) {
898898
const needToCheckForGroupAccess = !currentUser
899899
? true
900900
: !currentUser.isMachine && !hasAdminRole(currentUser);
901-
if (!needToCheckForGroupAccess) return challenges;
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)