Skip to content

Commit

Permalink
Fix groupByNameAndOrganization resolver errors when group not found
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketeerbkw committed Sep 9, 2024
1 parent 0797e9e commit 52c45e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
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

0 comments on commit 52c45e1

Please sign in to comment.