Skip to content

Commit 5a65daf

Browse files
Merge pull request #3716 from uselagoon/fix-bulk-check-groups
fix: make sure that projects groups are collected when importing to organization
2 parents b470e13 + 4252600 commit 5a65daf

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

services/api-redis/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG UPSTREAM_REPO
22
ARG UPSTREAM_TAG
3-
FROM ${UPSTREAM_REPO:-uselagoon}/redis-5:${UPSTREAM_TAG:-latest}
3+
FROM ${UPSTREAM_REPO:-uselagoon}/redis-7:${UPSTREAM_TAG:-latest}
44

55
ARG LAGOON_VERSION
66
ENV LAGOON_VERSION=$LAGOON_VERSION

services/api/src/resources/organization/resolvers.ts

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,26 +1049,40 @@ export const deleteOrganization: ResolverFn = async (
10491049
return 'success';
10501050
};
10511051

1052-
const checkBulkProjectGroupAssociation = async (oid, pid, projectsToMove, groupsToMove, projectsInOtherOrgs, groupsInOtherOrgs, sqlClientPool, models) => {
1053-
const groupProjectIds = [];
1052+
// recursive check of a project and the groups of that project
1053+
const checkProjectGroups = async (groupProjectIds, projectIds, projectsGroups, models, sqlClientPool, pid) => {
10541054
const projectGroups = await groupHelpers(sqlClientPool).selectGroupsByProjectId(models, pid)
1055-
// get all the groups the requested project is in
1056-
for (const group of projectGroups) {
1057-
// for each group the project is in, get the list of projects that are also in this group
1058-
if (R.prop('lagoon-projects', group.attributes)) {
1059-
const groupProjects = R.prop('lagoon-projects', group.attributes).toString().split(',')
1060-
for (const project of groupProjects) {
1061-
groupProjectIds.push({group: group.name, project: project})
1055+
let index = projectIds.findIndex((item) => item === pid);
1056+
if (index === -1) {
1057+
projectIds.push(pid)
1058+
// get all the groups the requested project is in
1059+
for (const group of projectGroups) {
1060+
const groupProjectIdss = await groupHelpers(sqlClientPool).selectProjectIdsByGroupID(group.id)
1061+
// for each group the project is in, get the list of projects that are also in this group
1062+
for (const project of groupProjectIdss) {
1063+
let index = groupProjectIds.findIndex((item) => item.group === group.name);
1064+
if (index === -1) {
1065+
groupProjectIds.push({group: group.name, project: project})
1066+
projectsGroups.push(group)
1067+
}
1068+
// recurse the project
1069+
await checkProjectGroups(groupProjectIds, projectIds, projectsGroups, models, sqlClientPool, project)
10621070
}
10631071
}
10641072
}
1073+
}
1074+
1075+
const checkBulkProjectGroupAssociation = async (oid, pid, projectsToMove, groupsToMove, projectsInOtherOrgs, groupsInOtherOrgs, sqlClientPool, models) => {
1076+
const groupProjectIds = [];
1077+
const projectIds = [];
1078+
const projectsGroups = []
1079+
await checkProjectGroups(groupProjectIds, projectIds, projectsGroups, models, sqlClientPool, pid)
10651080

10661081
// for all the projects in the first projects group, iterate through the projects and the groups attached
10671082
// to these projects and try to build out a map of all the groups and projects that are linked by the primary project
10681083
if (groupProjectIds.length > 0) {
10691084
for (const pGroup of groupProjectIds) {
10701085
const project = await projectHelpers(sqlClientPool).getProjectById(pGroup.project)
1071-
const projectGroups = await groupHelpers(sqlClientPool).selectGroupsByProjectId(models, pid)
10721086
// check if the project is already in the requested organization
10731087
if (project.organization != oid && project.organization == null) {
10741088
let alreadyAdded = false
@@ -1096,32 +1110,32 @@ const checkBulkProjectGroupAssociation = async (oid, pid, projectsToMove, groups
10961110
}
10971111
}
10981112
}
1099-
for (const group of projectGroups) {
1100-
// for every group that the project is in, check if the group is already in the requested organization
1101-
if (group.organization != oid && group.organization == null) {
1113+
}
1114+
for (const group of projectsGroups) {
1115+
// for every group that the project is in, check if the group is already in the requested organization
1116+
if (group.organization != oid && group.organization == null) {
1117+
let alreadyAdded = false
1118+
for (const f of groupsToMove) {
1119+
if (f.id == group.id) {
1120+
alreadyAdded = true
1121+
}
1122+
}
1123+
if (!alreadyAdded) {
1124+
// if it isn't already in the requested organization, add it to the list of groups that should be moved
1125+
groupsToMove.push(group)
1126+
}
1127+
} else {
1128+
// if the group is in a completely different organization
1129+
if (group.organization != oid) {
11021130
let alreadyAdded = false
1103-
for (const f of groupsToMove) {
1131+
for (const f of groupsInOtherOrgs) {
11041132
if (f.id == group.id) {
11051133
alreadyAdded = true
11061134
}
11071135
}
11081136
if (!alreadyAdded) {
1109-
// if it isn't already in the requested organization, add it to the list of groups that should be moved
1110-
groupsToMove.push(group)
1111-
}
1112-
} else {
1113-
// if the group is in a completely different organization
1114-
if (group.organization != oid) {
1115-
let alreadyAdded = false
1116-
for (const f of groupsInOtherOrgs) {
1117-
if (f.id == group.id) {
1118-
alreadyAdded = true
1119-
}
1120-
}
1121-
if (!alreadyAdded) {
1122-
// add it to the lsit of projects that will cause this check to fail
1123-
groupsInOtherOrgs.push(group)
1124-
}
1137+
// add it to the lsit of projects that will cause this check to fail
1138+
groupsInOtherOrgs.push(group)
11251139
}
11261140
}
11271141
}

0 commit comments

Comments
 (0)