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 groupByNameAndOrganization resolver errors when group not found #3800

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions services/api/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ const {
getUsersByOrganizationId,
getUserByEmailAndOrganizationId,
getGroupRolesByUserIdAndOrganization,
getGroupsByNameAndOrganizationId,
getGroupByNameAndOrganizationId,
getOwnersByOrganizationId,
getProjectsByOrganizationId,
addExistingProjectToOrganization,
Expand Down Expand Up @@ -538,7 +538,7 @@ const resolvers = {
orgProjectByName: getProjectByName,
environmentsByKubernetes: getEnvironmentsByKubernetes,
groupByName: getGroupByName,
groupByNameAndOrganization: getGroupsByNameAndOrganizationId,
groupByNameAndOrganization: getGroupByNameAndOrganizationId,
usersByOrganization: getUsersByOrganizationId,
userByEmailAndOrganization: getUserByEmailAndOrganizationId,
problemSources: getProblemSources,
Expand Down
28 changes: 13 additions & 15 deletions services/api/src/resources/organization/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as R from 'ramda';
import { ResolverFn } from '../';
import { logger } from '../../loggers/logger';
import { query, isPatchEmpty, knex } from '../../util/db';
import { GroupNotFoundError } from '../../models/group';
import { Helpers as projectHelpers } from '../project/helpers';
import { Helpers} from './helpers';
import { Sql } from './sql';
Expand Down Expand Up @@ -489,25 +490,22 @@ export const getGroupRolesByUserIdAndOrganization: ResolverFn =async (
}

// list all groups by organization id
export const getGroupsByNameAndOrganizationId: ResolverFn = async (
root,
export const getGroupByNameAndOrganizationId: ResolverFn = async (
_,
{ name, organization },
{ hasPermission, models, keycloakGrant }
{ hasPermission, models }
) => {
try {
await hasPermission('organization', 'viewGroup', {
organization: organization,
});
await hasPermission('organization', 'viewGroup', {
organization: organization,
});

const group = await models.GroupModel.loadGroupByName(name);
const groupOrg = group.attributes?.['lagoon-organization']?.[0];
if (groupOrg && toNumber(groupOrg) == organization) {
return group
}
} catch (err) {
return [];
const group = await models.GroupModel.loadGroupByName(name);
const groupOrg = group.attributes?.['lagoon-organization']?.[0];
if (!groupOrg || toNumber(groupOrg) != organization) {
throw new GroupNotFoundError(`Group not found: ${name}`);
}
return [];

return group;
};

export const getGroupCountByOrganizationProject: ResolverFn = async (
Expand Down