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

[Feature] Update environment controller and remove ability to update environments from putOrganization #2494

Open
mknowlton89 opened this issue May 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@mknowlton89
Copy link
Collaborator

mknowlton89 commented May 8, 2024

Description of Feature

As part of an on-going effort to reduce to capabilities of organizations.controller, we should not allow an org to update an org's environments via the organization.controller's putOrganization method.

We should block that functionality and instead add it explicitly to the environment.controller. Currently, we're missing a putEnvironment method (currently only supports updating multiple environments).

It is also missing a deleteEnvironment method.

When we do this work, we should also split out the PermissionsClass.canCreateOrUpdateEnvironment method into separate canCreate and canUpdate methods, with the canUpdate method taking the shape of other canUpdate methods where we take in the existing environment, check to make sure the user has permission to update it, as well as the updates and make sure that after the updates, the user still have permission to edit.

Sample code for the canUpdate method (has not been tested, so just use as a starting point)

  public canUpdateEnvironment = (
    existing: Pick<Environment, "projects" | "id">,
    updates: Pick<Environment, "projects" | "id">
  ): boolean => {
    const existingProjects = existing.projects?.length
      ? existing.projects
      : [""];
    if (
      !existingProjects.every((project) =>
        this.hasPermission("manageEnvironments", project, [existing.id])
      )
    ) {
      return false;
    }

    if ("projects" in updates) {
      const updatedProjects = updates.projects?.length
        ? updates.projects
        : [""];

      if (
        !updatedProjects.every((project) => {
          this.hasPermission("manageEnvironments", project, [updates.id]);
        })
      ) {
        return false;
      }
    }
    return true;
  };

Related Issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant