From 037fe0916348e8c8165e8cd89a2f39464bd40d7c Mon Sep 17 00:00:00 2001 From: George Drummond Date: Mon, 29 Apr 2019 16:11:15 -0400 Subject: [PATCH 1/6] Delete environments from an application --- atst/routes/applications/settings.py | 18 +++++++++ atst/utils/flash.py | 5 +++ .../applications/edit_environments.html | 40 ++++++++++++++++++- tests/routes/applications/test_settings.py | 29 ++++++++++++++ 4 files changed, 91 insertions(+), 1 deletion(-) diff --git a/atst/routes/applications/settings.py b/atst/routes/applications/settings.py index e12a66f9..eebd3d32 100644 --- a/atst/routes/applications/settings.py +++ b/atst/routes/applications/settings.py @@ -179,3 +179,21 @@ def delete(application_id): "applications.portfolio_applications", portfolio_id=application.portfolio_id ) ) + + +@applications_bp.route("/environments//delete", methods=["POST"]) +@user_can(Permissions.DELETE_ENVIRONMENT, message="delete delete_environment") +def delete_environment(environment_id): + environment = Environments.get(environment_id) + Environments.delete(environment=environment, commit=True) + + flash("environment_deleted", environment_name=environment.name) + + return redirect( + url_for( + "applications.settings", + application_id=environment.application_id, + _anchor="application-environments", + fragment="application-environments", + ) + ) diff --git a/atst/utils/flash.py b/atst/utils/flash.py index 9fff1be2..9855628e 100644 --- a/atst/utils/flash.py +++ b/atst/utils/flash.py @@ -2,6 +2,11 @@ from flask import flash, render_template_string from atst.utils.localization import translate MESSAGES = { + "environment_deleted": { + "title_template": "{{ environment_name }} deleted", + "message_template": 'The environment "{{ environment_name }}" has been deleted', + "category": "success", + }, "application_environments_updated": { "title_template": "Application environments updated", "message_template": "Application environments have been updated", diff --git a/templates/fragments/applications/edit_environments.html b/templates/fragments/applications/edit_environments.html index cd27c2d3..ec021234 100644 --- a/templates/fragments/applications/edit_environments.html +++ b/templates/fragments/applications/edit_environments.html @@ -2,6 +2,7 @@ {% from "components/toggle_list.html" import ToggleButton, ToggleSection %} {% from "components/text_input.html" import TextInput %} {% from "components/save_button.html" import SaveButton %} +{% from "components/modal.html" import Modal %} {% macro RolePanel(users=[], role='no_access') %} {% if role == 'no_access' %} @@ -51,6 +52,7 @@ {% set member_count = env['members_form'].data['team_roles'] | length %} {% set members_by_role = env['members'] %} {% set unassigned = members_by_role['no_access'] %} + {% set delete_environment_modal_id = 'delete' %}
  • @@ -74,7 +76,7 @@
    - + {{ Icon('trash') }}
    @@ -122,6 +124,42 @@ {% endcall %}
  • + + {% call Modal(name=delete_environment_modal_id, dismissable=True) %} +

    Are you sure you want to delete this environment?

    + + {{ + Alert( + level="warning", + title="Warning! This action is permanent", + message="You will no longer be able to access this environment", + ) + }} + + +
    +
    + + +
    +
    +
    + {{ form.csrf_token }} + +
    + +
    +
    +
    + {% endcall %} {% endfor %} diff --git a/tests/routes/applications/test_settings.py b/tests/routes/applications/test_settings.py index 8bcf7bc7..01394afa 100644 --- a/tests/routes/applications/test_settings.py +++ b/tests/routes/applications/test_settings.py @@ -306,3 +306,32 @@ def test_delete_application(client, user_session): # app and envs are soft deleted assert len(port.applications) == 0 assert len(application.environments) == 0 + + +def test_delete_environment(client, user_session): + user = UserFactory.create() + portfolio = PortfolioFactory(owner=user) + application = ApplicationFactory.create(portfolio=portfolio) + environment = EnvironmentFactory.create(application=application) + + user_session(user) + + response = client.post( + url_for("applications.delete_environment", environment_id=environment.id) + ) + + # appropriate response and redirect + assert response.status_code == 302 + assert response.location == url_for( + "applications.settings", + application_id=application.id, + _anchor="application-environments", + _external=True, + fragment="application-environments", + ) + # appropriate flash message + message = get_flashed_messages()[0] + assert "deleted" in message["message"] + assert environment.name in message["message"] + # deletes environment + assert len(application.environments) == 0 From c1acdd81c9939d17b9fc146d6f6c40a3ad0d7d59 Mon Sep 17 00:00:00 2001 From: George Drummond Date: Mon, 6 May 2019 14:12:59 -0400 Subject: [PATCH 2/6] Fix message --- atst/routes/applications/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atst/routes/applications/settings.py b/atst/routes/applications/settings.py index eebd3d32..4b27ce08 100644 --- a/atst/routes/applications/settings.py +++ b/atst/routes/applications/settings.py @@ -182,7 +182,7 @@ def delete(application_id): @applications_bp.route("/environments//delete", methods=["POST"]) -@user_can(Permissions.DELETE_ENVIRONMENT, message="delete delete_environment") +@user_can(Permissions.DELETE_ENVIRONMENT, message="delete environment") def delete_environment(environment_id): environment = Environments.get(environment_id) Environments.delete(environment=environment, commit=True) From 4fe42ceebb87c8eecea18399743ad3fa2206964d Mon Sep 17 00:00:00 2001 From: George Drummond Date: Mon, 6 May 2019 14:18:09 -0400 Subject: [PATCH 3/6] Correct modal ID --- templates/fragments/applications/edit_environments.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/fragments/applications/edit_environments.html b/templates/fragments/applications/edit_environments.html index ec021234..348d6e37 100644 --- a/templates/fragments/applications/edit_environments.html +++ b/templates/fragments/applications/edit_environments.html @@ -52,7 +52,7 @@ {% set member_count = env['members_form'].data['team_roles'] | length %} {% set members_by_role = env['members'] %} {% set unassigned = members_by_role['no_access'] %} - {% set delete_environment_modal_id = 'delete' %} + {% set delete_environment_modal_id = "delete_modal_environment{}".format(env['id']) %}
  • @@ -154,7 +154,7 @@ From c3e4f2c6fe88fcacf85b6979a1c675e6037f6d67 Mon Sep 17 00:00:00 2001 From: George Drummond Date: Mon, 6 May 2019 14:33:06 -0400 Subject: [PATCH 4/6] Move to component --- templates/components/delete_confirmation.html | 25 +++++++++++++++ .../applications/edit_environments.html | 32 ++++++------------- 2 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 templates/components/delete_confirmation.html diff --git a/templates/components/delete_confirmation.html b/templates/components/delete_confirmation.html new file mode 100644 index 00000000..e5e9bfc5 --- /dev/null +++ b/templates/components/delete_confirmation.html @@ -0,0 +1,25 @@ +{% macro DeleteConfirmation(modal_id, delete_text, delete_action, form) %} + +
    +
    + + +
    +
    +
    + {{ form.csrf_token }} + +
    + +
    +
    +
    +{% endmacro %} diff --git a/templates/fragments/applications/edit_environments.html b/templates/fragments/applications/edit_environments.html index 348d6e37..b2c5349b 100644 --- a/templates/fragments/applications/edit_environments.html +++ b/templates/fragments/applications/edit_environments.html @@ -3,6 +3,7 @@ {% from "components/text_input.html" import TextInput %} {% from "components/save_button.html" import SaveButton %} {% from "components/modal.html" import Modal %} +{% from "components/delete_confirmation.html" import DeleteConfirmation %} {% macro RolePanel(users=[], role='no_access') %} {% if role == 'no_access' %} @@ -136,29 +137,14 @@ ) }} - -
    -
    - - -
    -
    -
    - {{ form.csrf_token }} - -
    - -
    -
    -
    + {{ + DeleteConfirmation( + modal_id=delete_modal_environment_id, + delete_text=('portfolios.applications.delete.button' | translate), + delete_action= url_for('applications.delete_environment', environment_id=env['id']), + form=form + ) + }} {% endcall %} {% endfor %} From ef23b1d776d465cbb1959fceb46fb2e14b329940 Mon Sep 17 00:00:00 2001 From: George Drummond Date: Mon, 6 May 2019 15:18:53 -0400 Subject: [PATCH 5/6] Move to a component --- .../applications/edit_environments.html | 10 +++--- .../portfolios/applications/settings.html | 34 ++++++------------- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/templates/fragments/applications/edit_environments.html b/templates/fragments/applications/edit_environments.html index b2c5349b..6e69a50c 100644 --- a/templates/fragments/applications/edit_environments.html +++ b/templates/fragments/applications/edit_environments.html @@ -1,9 +1,9 @@ -{% from "components/icon.html" import Icon %} -{% from "components/toggle_list.html" import ToggleButton, ToggleSection %} -{% from "components/text_input.html" import TextInput %} -{% from "components/save_button.html" import SaveButton %} -{% from "components/modal.html" import Modal %} {% from "components/delete_confirmation.html" import DeleteConfirmation %} +{% from "components/icon.html" import Icon %} +{% from "components/modal.html" import Modal %} +{% from "components/save_button.html" import SaveButton %} +{% from "components/text_input.html" import TextInput %} +{% from "components/toggle_list.html" import ToggleButton, ToggleSection %} {% macro RolePanel(users=[], role='no_access') %} {% if role == 'no_access' %} diff --git a/templates/portfolios/applications/settings.html b/templates/portfolios/applications/settings.html index 49739d2f..7de3e1b5 100644 --- a/templates/portfolios/applications/settings.html +++ b/templates/portfolios/applications/settings.html @@ -1,9 +1,10 @@ {% extends "portfolios/applications/base.html" %} {% from "components/alert.html" import Alert %} -{% from "components/text_input.html" import TextInput %} +{% from "components/delete_confirmation.html" import DeleteConfirmation %} {% from "components/icon.html" import Icon %} {% from "components/modal.html" import Modal %} +{% from "components/text_input.html" import TextInput %} {% set secondary_breadcrumb = 'portfolios.applications.existing_application_title' | translate({ "application_name": application.name }) %} @@ -94,29 +95,14 @@ ) }} - -
    -
    - - -
    -
    -
    - {{ form.csrf_token }} - -
    - -
    -
    -
    + {{ + DeleteConfirmation( + modal_id=delete_modal_environment_id, + delete_text=('portfolios.applications.delete.button' | translate), + delete_action= url_for('applications.delete', application_id=application.id), + form=form + ) + }} {% endcall %} {% endif %} From f314e9238dc70c622311aa8235af19e85dccf5c3 Mon Sep 17 00:00:00 2001 From: George Drummond Date: Mon, 6 May 2019 15:21:27 -0400 Subject: [PATCH 6/6] Fix button copy --- templates/fragments/applications/edit_environments.html | 2 +- translations.yaml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/fragments/applications/edit_environments.html b/templates/fragments/applications/edit_environments.html index 6e69a50c..ac190481 100644 --- a/templates/fragments/applications/edit_environments.html +++ b/templates/fragments/applications/edit_environments.html @@ -140,7 +140,7 @@ {{ DeleteConfirmation( modal_id=delete_modal_environment_id, - delete_text=('portfolios.applications.delete.button' | translate), + delete_text=('portfolios.applications.environments.delete.button' | translate), delete_action= url_for('applications.delete_environment', environment_id=env['id']), form=form ) diff --git a/translations.yaml b/translations.yaml index 4a74c9fd..78881ef2 100644 --- a/translations.yaml +++ b/translations.yaml @@ -413,6 +413,8 @@ portfolios: header: Are you sure you want to delete this application? environments: name: Name + delete: + button: Delete environment edit_name: Edit name environments_description: Each environment created within an application is logically separated from one another for easier management and security. environments_heading: Application environments