diff --git a/atst/routes/applications/settings.py b/atst/routes/applications/settings.py
index f2d252a9..66131c15 100644
--- a/atst/routes/applications/settings.py
+++ b/atst/routes/applications/settings.py
@@ -1,4 +1,10 @@
-from flask import redirect, render_template, request as http_request, url_for, g
+from flask import (
+ redirect,
+ render_template,
+ request as http_request,
+ url_for,
+ g,
+)
from .blueprint import applications_bp
from atst.domain.exceptions import AlreadyExistsError
@@ -245,16 +251,36 @@ def handle_update_member(application_id, application_role_id, form_data):
# TODO: flash error message
+def handle_update_environment(form, application=None, environment=None):
+ if form.validate():
+ try:
+ if environment:
+ environment = Environments.update(
+ environment=environment, name=form.name.data
+ )
+ flash("application_environments_updated")
+ else:
+ environment = Environments.create(
+ g.current_user, application=application, name=form.name.data
+ )
+ flash("environment_added", environment_name=form.name.data)
+
+ return environment
+
+ except AlreadyExistsError:
+ flash("application_environments_name_error", name=form.name.data)
+ return False
+
+ else:
+ return False
+
+
@applications_bp.route("/applications/{{ 'portfolios.applications.settings.name_description' | translate }}
{% if user_can(permissions.EDIT_APPLICATION) %}
diff --git a/tests/routes/applications/test_settings.py b/tests/routes/applications/test_settings.py
index 08c979ad..597664d1 100644
--- a/tests/routes/applications/test_settings.py
+++ b/tests/routes/applications/test_settings.py
@@ -52,8 +52,6 @@ def test_updating_application_environments_success(client, user_session):
_external=True,
fragment="application-environments",
_anchor="application-environments",
- active_toggler=environment.id,
- active_toggler_section="edit",
)
assert environment.name == "new name a"
@@ -78,6 +76,24 @@ def test_update_environment_failure(client, user_session):
assert environment.name == "original name"
+def test_enforces_unique_env_name(client, user_session, session):
+ application = ApplicationFactory.create()
+ user = application.portfolio.owner
+ name = "New Environment"
+ environment = EnvironmentFactory.create(application=application, name=name)
+ form_data = {"name": name}
+ user_session(user)
+
+ session.begin_nested()
+ response = client.post(
+ url_for("applications.new_environment", application_id=application.id),
+ data=form_data,
+ )
+ session.rollback()
+
+ assert response.status_code == 400
+
+
def test_application_settings(client, user_session):
portfolio = PortfolioFactory.create()
application = Applications.create(
diff --git a/translations.yaml b/translations.yaml
index 6a678f48..e0277fff 100644
--- a/translations.yaml
+++ b/translations.yaml
@@ -116,6 +116,8 @@ flash:
deleted: 'You have successfully deleted the {application_name} application. To view the retained activity log, visit the portfolio administration page.'
name_error:
message: 'The application name {name} has already been used in this portfolio. Please enter a unique name.'
+ env_name_error:
+ message: 'The environment name {name} has already been used in this application. Please enter a unique name.'
delete_member_success: 'You have successfully deleted {member_name} from the portfolio.'
deleted_member: Portfolio member deleted
environment_added: 'The environment "{env_name}" has been added to the application.'
@@ -199,7 +201,7 @@ forms:
Select the DOD component(s) that will fund all Applications within this Portfolio.
- In JEDI, multiple DoD organizations can fund the same Portfolio.
+ In JEDI, multiple DoD organizations can fund the same Portfolio.
Select all that apply.