Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return groups user has access to in group payloads #3613

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 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,13 @@ export const getGroupsByProjectId: ResolverFn = async (
}
}
}
const userProjectGroups = R.intersection(projectGroups, userGroups);
let userProjectGroups = []
for (const ug of userGroups) {
const pg = projectGroups.find(i => i.id === ug.id)
if (pg) {
userProjectGroups.push(pg)
}
}

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

return currentUserGroups;
};
Expand Down
8 changes: 7 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,13 @@ export const getGroupsByOrganizationsProject: ResolverFn = async (
}
}
}
const userProjectGroups = R.intersection(orgProjectGroups, userGroups);
let userProjectGroups = []
for (const ug of userGroups) {
const pg = orgProjectGroups.find(i => i.id === ug.id)
if (pg) {
userProjectGroups.push(pg)
}
}

return userProjectGroups;
};
Expand Down