Skip to content

Commit bcc660e

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

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/common/helper.js

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

903920
let userGroups;
904921

@@ -909,8 +926,7 @@ async function _filterChallengesByGroupsAccess(currentUser, challenges) {
909926
);
910927
if (
911928
!challenge.groups ||
912-
_.get(challenge, "groups.length", 0) === 0 ||
913-
!needToCheckForGroupAccess
929+
_.get(challenge, "groups.length", 0) === 0
914930
) {
915931
res.push(challenge);
916932
} else if (currentUser) {

0 commit comments

Comments
 (0)