Skip to content

Handle project/organization references when an organization is updated #111

@landonreed

Description

@landonreed

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();
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions