From 390ae33ed15699c414fc22022fd88f20185389f9 Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Thu, 28 Sep 2023 16:21:57 +1000 Subject: [PATCH 1/5] Implements organizationByName resolver --- services/api/src/resolvers.js | 2 ++ .../src/resources/organization/resolvers.ts | 24 +++++++++++++++++++ .../api/src/resources/organization/sql.ts | 4 ++++ services/api/src/typeDefs.js | 1 + 4 files changed, 31 insertions(+) diff --git a/services/api/src/resolvers.js b/services/api/src/resolvers.js index 674add53ff..43caeab7b2 100644 --- a/services/api/src/resolvers.js +++ b/services/api/src/resolvers.js @@ -248,6 +248,7 @@ const { updateOrganization, deleteOrganization, getOrganizationById, + getOrganizationByName, addDeployTargetToOrganization, removeDeployTargetFromOrganization, getDeployTargetsByOrganizationId, @@ -577,6 +578,7 @@ const resolvers = { deployTargetConfigsByDeployTarget: getDeployTargetConfigsByDeployTarget, allOrganizations: getAllOrganizations, organizationById: getOrganizationById, + organizationByName: getOrganizationByName, getGroupProjectOrganizationAssociation, getProjectGroupOrganizationAssociation, getEnvVariablesByProjectEnvironmentName, diff --git a/services/api/src/resources/organization/resolvers.ts b/services/api/src/resources/organization/resolvers.ts index 67d9b0b4e0..f384dd6085 100644 --- a/services/api/src/resources/organization/resolvers.ts +++ b/services/api/src/resources/organization/resolvers.ts @@ -242,6 +242,30 @@ export const getOrganizationById: ResolverFn = async ( return orgResult; }; +export const getOrganizationByName: ResolverFn = async ( + organization, + args, + { sqlClientPool, hasPermission } +) => { + let orgName = args.organization; + if (organization) { + orgName = organization; + } + + await hasPermission('organization', 'view', { + organization: orgName, + }); + + const rows = await query(sqlClientPool, Sql.selectOrganizationByName(orgName)); + const orgResult = rows[0]; + + if (!orgResult) { + return null; + } + + return orgResult; +}; + export const getAllOrganizations: ResolverFn = async ( root, args, diff --git a/services/api/src/resources/organization/sql.ts b/services/api/src/resources/organization/sql.ts index 273558fd62..d05fca12dd 100644 --- a/services/api/src/resources/organization/sql.ts +++ b/services/api/src/resources/organization/sql.ts @@ -74,6 +74,10 @@ export const Sql = { knex('organization') .where('id', '=', id) .toString(), + selectOrganizationByName: (name: string) => + knex('organization') + .where('name', '=', name) + .toString(), selectOrganizationProjects: (id: number) => knex('project') .where('organization', '=', id) diff --git a/services/api/src/typeDefs.js b/services/api/src/typeDefs.js index 633b887e51..59197b47be 100644 --- a/services/api/src/typeDefs.js +++ b/services/api/src/typeDefs.js @@ -1416,6 +1416,7 @@ const typeDefs = gql` Get an organization by its ID """ organizationById(organization: Int!): Organization + organizationByName(organization: String!): Organization getGroupProjectOrganizationAssociation(input: AddGroupInput!): String getProjectGroupOrganizationAssociation(input: ProjectOrgGroupsInput!): String getEnvVariablesByProjectEnvironmentName(input: EnvVariableByProjectEnvironmentNameInput!): [EnvKeyValue] From 20ddfd89cc7a6e525df0edcee2e405bb51374677 Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Thu, 28 Sep 2023 16:23:57 +1000 Subject: [PATCH 2/5] Revert "Implements organizationByName resolver" This reverts commit 390ae33ed15699c414fc22022fd88f20185389f9. --- services/api/src/resolvers.js | 2 -- .../src/resources/organization/resolvers.ts | 24 ------------------- .../api/src/resources/organization/sql.ts | 4 ---- services/api/src/typeDefs.js | 1 - 4 files changed, 31 deletions(-) diff --git a/services/api/src/resolvers.js b/services/api/src/resolvers.js index 43caeab7b2..674add53ff 100644 --- a/services/api/src/resolvers.js +++ b/services/api/src/resolvers.js @@ -248,7 +248,6 @@ const { updateOrganization, deleteOrganization, getOrganizationById, - getOrganizationByName, addDeployTargetToOrganization, removeDeployTargetFromOrganization, getDeployTargetsByOrganizationId, @@ -578,7 +577,6 @@ const resolvers = { deployTargetConfigsByDeployTarget: getDeployTargetConfigsByDeployTarget, allOrganizations: getAllOrganizations, organizationById: getOrganizationById, - organizationByName: getOrganizationByName, getGroupProjectOrganizationAssociation, getProjectGroupOrganizationAssociation, getEnvVariablesByProjectEnvironmentName, diff --git a/services/api/src/resources/organization/resolvers.ts b/services/api/src/resources/organization/resolvers.ts index f384dd6085..67d9b0b4e0 100644 --- a/services/api/src/resources/organization/resolvers.ts +++ b/services/api/src/resources/organization/resolvers.ts @@ -242,30 +242,6 @@ export const getOrganizationById: ResolverFn = async ( return orgResult; }; -export const getOrganizationByName: ResolverFn = async ( - organization, - args, - { sqlClientPool, hasPermission } -) => { - let orgName = args.organization; - if (organization) { - orgName = organization; - } - - await hasPermission('organization', 'view', { - organization: orgName, - }); - - const rows = await query(sqlClientPool, Sql.selectOrganizationByName(orgName)); - const orgResult = rows[0]; - - if (!orgResult) { - return null; - } - - return orgResult; -}; - export const getAllOrganizations: ResolverFn = async ( root, args, diff --git a/services/api/src/resources/organization/sql.ts b/services/api/src/resources/organization/sql.ts index d05fca12dd..273558fd62 100644 --- a/services/api/src/resources/organization/sql.ts +++ b/services/api/src/resources/organization/sql.ts @@ -74,10 +74,6 @@ export const Sql = { knex('organization') .where('id', '=', id) .toString(), - selectOrganizationByName: (name: string) => - knex('organization') - .where('name', '=', name) - .toString(), selectOrganizationProjects: (id: number) => knex('project') .where('organization', '=', id) diff --git a/services/api/src/typeDefs.js b/services/api/src/typeDefs.js index 59197b47be..633b887e51 100644 --- a/services/api/src/typeDefs.js +++ b/services/api/src/typeDefs.js @@ -1416,7 +1416,6 @@ const typeDefs = gql` Get an organization by its ID """ organizationById(organization: Int!): Organization - organizationByName(organization: String!): Organization getGroupProjectOrganizationAssociation(input: AddGroupInput!): String getProjectGroupOrganizationAssociation(input: ProjectOrgGroupsInput!): String getEnvVariablesByProjectEnvironmentName(input: EnvVariableByProjectEnvironmentNameInput!): [EnvKeyValue] From 7c6d676c7153ecec79860e0e56858368754939c2 Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Thu, 28 Sep 2023 16:41:48 +1000 Subject: [PATCH 3/5] Resolver for getOrganizationsByName --- services/api/src/resolvers.js | 2 ++ .../src/resources/organization/resolvers.ts | 24 +++++++++++++++++++ .../api/src/resources/organization/sql.ts | 4 ++++ services/api/src/typeDefs.js | 1 + 4 files changed, 31 insertions(+) diff --git a/services/api/src/resolvers.js b/services/api/src/resolvers.js index 674add53ff..43caeab7b2 100644 --- a/services/api/src/resolvers.js +++ b/services/api/src/resolvers.js @@ -248,6 +248,7 @@ const { updateOrganization, deleteOrganization, getOrganizationById, + getOrganizationByName, addDeployTargetToOrganization, removeDeployTargetFromOrganization, getDeployTargetsByOrganizationId, @@ -577,6 +578,7 @@ const resolvers = { deployTargetConfigsByDeployTarget: getDeployTargetConfigsByDeployTarget, allOrganizations: getAllOrganizations, organizationById: getOrganizationById, + organizationByName: getOrganizationByName, getGroupProjectOrganizationAssociation, getProjectGroupOrganizationAssociation, getEnvVariablesByProjectEnvironmentName, diff --git a/services/api/src/resources/organization/resolvers.ts b/services/api/src/resources/organization/resolvers.ts index 67d9b0b4e0..f384dd6085 100644 --- a/services/api/src/resources/organization/resolvers.ts +++ b/services/api/src/resources/organization/resolvers.ts @@ -242,6 +242,30 @@ export const getOrganizationById: ResolverFn = async ( return orgResult; }; +export const getOrganizationByName: ResolverFn = async ( + organization, + args, + { sqlClientPool, hasPermission } +) => { + let orgName = args.organization; + if (organization) { + orgName = organization; + } + + await hasPermission('organization', 'view', { + organization: orgName, + }); + + const rows = await query(sqlClientPool, Sql.selectOrganizationByName(orgName)); + const orgResult = rows[0]; + + if (!orgResult) { + return null; + } + + return orgResult; +}; + export const getAllOrganizations: ResolverFn = async ( root, args, diff --git a/services/api/src/resources/organization/sql.ts b/services/api/src/resources/organization/sql.ts index 273558fd62..d05fca12dd 100644 --- a/services/api/src/resources/organization/sql.ts +++ b/services/api/src/resources/organization/sql.ts @@ -74,6 +74,10 @@ export const Sql = { knex('organization') .where('id', '=', id) .toString(), + selectOrganizationByName: (name: string) => + knex('organization') + .where('name', '=', name) + .toString(), selectOrganizationProjects: (id: number) => knex('project') .where('organization', '=', id) diff --git a/services/api/src/typeDefs.js b/services/api/src/typeDefs.js index 633b887e51..59197b47be 100644 --- a/services/api/src/typeDefs.js +++ b/services/api/src/typeDefs.js @@ -1416,6 +1416,7 @@ const typeDefs = gql` Get an organization by its ID """ organizationById(organization: Int!): Organization + organizationByName(organization: String!): Organization getGroupProjectOrganizationAssociation(input: AddGroupInput!): String getProjectGroupOrganizationAssociation(input: ProjectOrgGroupsInput!): String getEnvVariablesByProjectEnvironmentName(input: EnvVariableByProjectEnvironmentNameInput!): [EnvKeyValue] From 00ffbedf2b60aa01c33bc53457da9e40dcad4d5f Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Thu, 28 Sep 2023 17:00:33 +1000 Subject: [PATCH 4/5] Fixed hasPermission --- services/api/src/resources/organization/resolvers.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/api/src/resources/organization/resolvers.ts b/services/api/src/resources/organization/resolvers.ts index f384dd6085..78ff0dd770 100644 --- a/services/api/src/resources/organization/resolvers.ts +++ b/services/api/src/resources/organization/resolvers.ts @@ -252,10 +252,6 @@ export const getOrganizationByName: ResolverFn = async ( orgName = organization; } - await hasPermission('organization', 'view', { - organization: orgName, - }); - const rows = await query(sqlClientPool, Sql.selectOrganizationByName(orgName)); const orgResult = rows[0]; @@ -263,6 +259,10 @@ export const getOrganizationByName: ResolverFn = async ( return null; } + await hasPermission('organization', 'view', { + organization: orgResult.id, + }); + return orgResult; }; From 53c9f39b8dc91d8b17f2cc511725d832021acc88 Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Thu, 5 Oct 2023 17:20:28 +1100 Subject: [PATCH 5/5] Updated arg naming --- services/api/src/resources/organization/resolvers.ts | 8 ++++---- services/api/src/typeDefs.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/api/src/resources/organization/resolvers.ts b/services/api/src/resources/organization/resolvers.ts index 78ff0dd770..adb3582db9 100644 --- a/services/api/src/resources/organization/resolvers.ts +++ b/services/api/src/resources/organization/resolvers.ts @@ -243,13 +243,13 @@ export const getOrganizationById: ResolverFn = async ( }; export const getOrganizationByName: ResolverFn = async ( - organization, + name, args, { sqlClientPool, hasPermission } ) => { - let orgName = args.organization; - if (organization) { - orgName = organization; + let orgName = args.name; + if (name) { + orgName = name; } const rows = await query(sqlClientPool, Sql.selectOrganizationByName(orgName)); diff --git a/services/api/src/typeDefs.js b/services/api/src/typeDefs.js index 59197b47be..13ba89ede2 100644 --- a/services/api/src/typeDefs.js +++ b/services/api/src/typeDefs.js @@ -1416,7 +1416,7 @@ const typeDefs = gql` Get an organization by its ID """ organizationById(organization: Int!): Organization - organizationByName(organization: String!): Organization + organizationByName(name: String!): Organization getGroupProjectOrganizationAssociation(input: AddGroupInput!): String getProjectGroupOrganizationAssociation(input: ProjectOrgGroupsInput!): String getEnvVariablesByProjectEnvironmentName(input: EnvVariableByProjectEnvironmentNameInput!): [EnvKeyValue]