Skip to content

Commit

Permalink
Merge pull request #3590 from uselagoon/filter-projects-with-buildimage
Browse files Browse the repository at this point in the history
feat: add buildimage boolean to allprojects and allkubernetes query
  • Loading branch information
tobybellwood authored Nov 26, 2023
2 parents 9e96d2f + 0b0715f commit 262239a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
12 changes: 9 additions & 3 deletions services/api/src/resources/openshift/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,21 @@ export const deleteOpenshift: ResolverFn = async (

export const getAllOpenshifts: ResolverFn = async (
root,
{ disabled },
{ disabled, buildImage },
{ sqlClientPool, hasPermission }
) => {
await hasPermission('openshift', 'viewAll');

let queryBuilder = knex('openshift');
if (buildImage) {
queryBuilder = queryBuilder.and.whereNot('build_image', '');
}

if (disabled != null) {
return query(sqlClientPool, knex('openshift').where('disabled', disabled).toString());
queryBuilder = queryBuilder.where('disabled', disabled);
}
return query(sqlClientPool, knex('openshift').toString());

return query(sqlClientPool, queryBuilder.toString());
};

export const getOpenshiftByProjectId: ResolverFn = async (
Expand Down
6 changes: 5 additions & 1 deletion services/api/src/resources/project/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const getProjectDeployKey: ResolverFn = async (

export const getAllProjects: ResolverFn = async (
root,
{ order, createdAfter, gitUrl },
{ order, createdAfter, gitUrl, buildImage },
{ sqlClientPool, hasPermission, models, keycloakGrant, keycloakUsersGroups }
) => {
let userProjectIds: number[];
Expand Down Expand Up @@ -99,6 +99,10 @@ export const getAllProjects: ResolverFn = async (
queryBuilder = queryBuilder.andWhere('git_url', gitUrl);
}

if (buildImage) {
queryBuilder = queryBuilder.and.whereNot('build_image', '');
}

if (userProjectIds) {
queryBuilder = queryBuilder.whereIn('id', userProjectIds);
}
Expand Down
6 changes: 3 additions & 3 deletions services/api/src/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1331,19 +1331,19 @@ const typeDefs = gql`
"""
Returns all Project Objects matching given filters (all if no filter defined)
"""
allProjects(createdAfter: String, gitUrl: String, order: ProjectOrderType): [Project]
allProjects(createdAfter: String, gitUrl: String, order: ProjectOrderType, buildImage: Boolean): [Project]
"""
Returns all Project Objects matching metadata filters
"""
projectsByMetadata(metadata: [MetadataKeyValue]): [Project]
"""
Returns all OpenShift Objects
"""
allOpenshifts(disabled: Boolean): [Openshift]
allOpenshifts(disabled: Boolean, buildImage: Boolean): [Openshift]
"""
Returns all Kubernetes Objects
"""
allKubernetes(disabled: Boolean): [Kubernetes]
allKubernetes(disabled: Boolean, buildImage: Boolean): [Kubernetes]
"""
Returns all Environments matching given filter (all if no filter defined)
"""
Expand Down

0 comments on commit 262239a

Please sign in to comment.