forked from ibi-group/datatools-server
-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
Description
Pre-MongoDB, when an organization was updated by removing a project from it, the application handled removing organizationId refs and updating the projectId list for the organization. That code has not been re-added in OrganizationController#updateOrganization, so this needs to be addressed. Below is the commented out code that has been removed for now.
// FIXME: Add back in hook after organization is updated.
JsonNode projects = entry.getValue();
Collection<Project> projectsToInsert = new ArrayList<>(projects.size());
Collection<Project> existingProjects = org.projects();
// set projects orgId for all valid projects in list
for (JsonNode project : projects) {
if (!project.has("id")) {
halt(400, "Project not supplied");
}
Project p = Project.retrieve(project.get("id").asText());
if (p == null) {
halt(404, "Project not found");
}
Organization previousOrg = p.retrieveOrganization();
if (previousOrg != null && !previousOrg.id.equals(org.id)) {
halt(400, SparkUtils.formatJSON(String.format("Project %s cannot be reassigned while belonging to org %s", p.id, previousOrg.id), 400));
}
projectsToInsert.add(p);
p.organizationId = org.id;
p.save();
}
// assign remaining previously assigned projects to null
existingProjects.removeAll(projectsToInsert);
for (Project p : existingProjects) {
p.organizationId = null;
p.save();
}