Skip to content

Commit

Permalink
Merge pull request uselagoon#3716 from uselagoon/fix-bulk-check-groups
Browse files Browse the repository at this point in the history
fix: make sure that projects groups are collected when importing to organization
  • Loading branch information
shreddedbacon authored May 7, 2024
2 parents b470e13 + 4252600 commit 5a65daf
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 31 deletions.
2 changes: 1 addition & 1 deletion services/api-redis/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG UPSTREAM_REPO
ARG UPSTREAM_TAG
FROM ${UPSTREAM_REPO:-uselagoon}/redis-5:${UPSTREAM_TAG:-latest}
FROM ${UPSTREAM_REPO:-uselagoon}/redis-7:${UPSTREAM_TAG:-latest}

ARG LAGOON_VERSION
ENV LAGOON_VERSION=$LAGOON_VERSION
Expand Down
74 changes: 44 additions & 30 deletions services/api/src/resources/organization/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,26 +1049,40 @@ export const deleteOrganization: ResolverFn = async (
return 'success';
};

const checkBulkProjectGroupAssociation = async (oid, pid, projectsToMove, groupsToMove, projectsInOtherOrgs, groupsInOtherOrgs, sqlClientPool, models) => {
const groupProjectIds = [];
// recursive check of a project and the groups of that project
const checkProjectGroups = async (groupProjectIds, projectIds, projectsGroups, models, sqlClientPool, pid) => {
const projectGroups = await groupHelpers(sqlClientPool).selectGroupsByProjectId(models, pid)
// get all the groups the requested project is in
for (const group of projectGroups) {
// for each group the project is in, get the list of projects that are also in this group
if (R.prop('lagoon-projects', group.attributes)) {
const groupProjects = R.prop('lagoon-projects', group.attributes).toString().split(',')
for (const project of groupProjects) {
groupProjectIds.push({group: group.name, project: project})
let index = projectIds.findIndex((item) => item === pid);
if (index === -1) {
projectIds.push(pid)
// get all the groups the requested project is in
for (const group of projectGroups) {
const groupProjectIdss = await groupHelpers(sqlClientPool).selectProjectIdsByGroupID(group.id)
// for each group the project is in, get the list of projects that are also in this group
for (const project of groupProjectIdss) {
let index = groupProjectIds.findIndex((item) => item.group === group.name);
if (index === -1) {
groupProjectIds.push({group: group.name, project: project})
projectsGroups.push(group)
}
// recurse the project
await checkProjectGroups(groupProjectIds, projectIds, projectsGroups, models, sqlClientPool, project)
}
}
}
}

const checkBulkProjectGroupAssociation = async (oid, pid, projectsToMove, groupsToMove, projectsInOtherOrgs, groupsInOtherOrgs, sqlClientPool, models) => {
const groupProjectIds = [];
const projectIds = [];
const projectsGroups = []
await checkProjectGroups(groupProjectIds, projectIds, projectsGroups, models, sqlClientPool, pid)

// for all the projects in the first projects group, iterate through the projects and the groups attached
// to these projects and try to build out a map of all the groups and projects that are linked by the primary project
if (groupProjectIds.length > 0) {
for (const pGroup of groupProjectIds) {
const project = await projectHelpers(sqlClientPool).getProjectById(pGroup.project)
const projectGroups = await groupHelpers(sqlClientPool).selectGroupsByProjectId(models, pid)
// check if the project is already in the requested organization
if (project.organization != oid && project.organization == null) {
let alreadyAdded = false
Expand Down Expand Up @@ -1096,32 +1110,32 @@ const checkBulkProjectGroupAssociation = async (oid, pid, projectsToMove, groups
}
}
}
for (const group of projectGroups) {
// for every group that the project is in, check if the group is already in the requested organization
if (group.organization != oid && group.organization == null) {
}
for (const group of projectsGroups) {
// for every group that the project is in, check if the group is already in the requested organization
if (group.organization != oid && group.organization == null) {
let alreadyAdded = false
for (const f of groupsToMove) {
if (f.id == group.id) {
alreadyAdded = true
}
}
if (!alreadyAdded) {
// if it isn't already in the requested organization, add it to the list of groups that should be moved
groupsToMove.push(group)
}
} else {
// if the group is in a completely different organization
if (group.organization != oid) {
let alreadyAdded = false
for (const f of groupsToMove) {
for (const f of groupsInOtherOrgs) {
if (f.id == group.id) {
alreadyAdded = true
}
}
if (!alreadyAdded) {
// if it isn't already in the requested organization, add it to the list of groups that should be moved
groupsToMove.push(group)
}
} else {
// if the group is in a completely different organization
if (group.organization != oid) {
let alreadyAdded = false
for (const f of groupsInOtherOrgs) {
if (f.id == group.id) {
alreadyAdded = true
}
}
if (!alreadyAdded) {
// add it to the lsit of projects that will cause this check to fail
groupsInOtherOrgs.push(group)
}
// add it to the lsit of projects that will cause this check to fail
groupsInOtherOrgs.push(group)
}
}
}
Expand Down

0 comments on commit 5a65daf

Please sign in to comment.