Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
landonreed opened this issue Aug 9, 2018 · 0 comments
Open
Labels

Comments

@landonreed
Copy link
Member

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();
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant