Skip to content

Commit

Permalink
fix: return groups user has access to in group payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Dec 7, 2023
1 parent 979b645 commit a5ce1d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 9 additions & 4 deletions services/api/src/resources/group/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ export const getGroupsByProjectId: ResolverFn = async (
_input,
{ hasPermission, sqlClientPool, models, keycloakGrant, keycloakGroups, keycloakUsersGroups, adminScopes }
) => {
const projectGroups = await models.GroupModel.loadGroupsByProjectIdFromGroups(pid, keycloakGroups);
// use the admin scope check instead of `hasPermission` for speed
if (adminScopes.groupViewAll) {
try {
const projectGroups = await models.GroupModel.loadGroupsByProjectIdFromGroups(pid, keycloakGroups);
return projectGroups;
} catch (err) {
if (!keycloakGrant) {
Expand All @@ -202,7 +202,6 @@ export const getGroupsByProjectId: ResolverFn = async (
}
}
} else {
const projectGroups = await models.GroupModel.loadGroupsByProjectIdFromGroups(pid, keycloakGroups);
const user = await models.UserModel.loadUserById(
keycloakGrant.access_token.content.sub
);
Expand Down Expand Up @@ -237,7 +236,14 @@ export const getGroupsByProjectId: ResolverFn = async (
}
}
}
const userProjectGroups = R.intersection(projectGroups, userGroups);
let userProjectGroups = []
for (const pg of projectGroups) {
for (const ug of userGroups) {
if (pg.id == ug.id) {
userProjectGroups.push(pg)
}
}
}

return userProjectGroups;
}
Expand All @@ -262,7 +268,6 @@ export const getGroupsByUserId: ResolverFn = async (
}
}
const currentUserGroups = keycloakUsersGroups;
// const bothUserGroups = R.intersection(queryUserGroups, currentUserGroups);

return currentUserGroups;
};
Expand Down
9 changes: 8 additions & 1 deletion services/api/src/resources/organization/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,14 @@ export const getGroupsByOrganizationsProject: ResolverFn = async (
}
}
}
const userProjectGroups = R.intersection(orgProjectGroups, userGroups);
let userProjectGroups = []
for (const pg of orgProjectGroups) {
for (const ug of userGroups) {
if (pg.id == ug.id) {
userProjectGroups.push(pg)
}
}
}

return userProjectGroups;
};
Expand Down

0 comments on commit a5ce1d8

Please sign in to comment.