From f928b776a688068e2e50b7fded4dac2b4f9e8b7f Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Fri, 25 Oct 2019 11:44:15 -0400 Subject: [PATCH] Properly set deleted data for UpdateMemberForm and display suspended env access text Styling for env name and role in update app member perms form --- atst/domain/environment_roles.py | 8 ++ atst/routes/applications/settings.py | 8 +- styles/sections/_application_edit.scss | 18 ++-- .../fragments/member_form_fields.html | 90 ++++++++----------- tests/domain/test_environment_roles.py | 23 +++-- tests/domain/test_environments.py | 4 +- 6 files changed, 80 insertions(+), 71 deletions(-) diff --git a/atst/domain/environment_roles.py b/atst/domain/environment_roles.py index 6e69ac96..4dfb29c5 100644 --- a/atst/domain/environment_roles.py +++ b/atst/domain/environment_roles.py @@ -126,3 +126,11 @@ class EnvironmentRoles(object): .one_or_none() ) return existing_env_role + + @classmethod + def get_all_for_application_member(cls, application_role_id): + return ( + db.session.query(EnvironmentRole) + .filter(EnvironmentRole.application_role_id == application_role_id) + .all() + ) diff --git a/atst/routes/applications/settings.py b/atst/routes/applications/settings.py index 37e45e50..65f6d00e 100644 --- a/atst/routes/applications/settings.py +++ b/atst/routes/applications/settings.py @@ -77,12 +77,16 @@ def filter_env_roles_form_data(member, environments): "environment_id": str(env.id), "environment_name": env.name, "role": NO_ACCESS, - "deleted": env.deleted, + "deleted": False, } - env_roles_set = set(env.roles).intersection(set(member.environment_roles)) + env_roles_set = set(env.roles).intersection( + set(EnvironmentRoles.get_all_for_application_member(member.id)) + ) + if len(env_roles_set) == 1: (env_role,) = env_roles_set env_data["role"] = env_role.role + env_data["deleted"] = env_role.deleted env_roles_form_data.append(env_data) diff --git a/styles/sections/_application_edit.scss b/styles/sections/_application_edit.scss index 1c1c395d..94afb41e 100644 --- a/styles/sections/_application_edit.scss +++ b/styles/sections/_application_edit.scss @@ -92,15 +92,21 @@ text-align: left; .usa-input { - margin: $gap 0 $gap 0; + margin: $gap * 2; - .usa-input__title-inline { - margin-top: $gap; - margin-left: $gap; + &__title-inline { + font-weight: $font-bold; } - .form-row { - margin: 0; + &__help { + margin-bottom: 0; + } + + .env-role__no-access { + .usa-input__title-inline, + .usa-input__help { + color: $color-gray; + } } } diff --git a/templates/applications/fragments/member_form_fields.html b/templates/applications/fragments/member_form_fields.html index eb4ba097..5c43c277 100644 --- a/templates/applications/fragments/member_form_fields.html +++ b/templates/applications/fragments/member_form_fields.html @@ -3,45 +3,30 @@ {% from "components/phone_input.html" import PhoneInput %} {% macro EnvRoleInput(field, member_role_id=None) %} - {% if field.role.data == "No Access" and not field.deleted.data -%} - -
-
-
-
- -
- {{ field.environment_name.data }} -
-

- {{ field.role.data }} -

-
-
-
- {{ field.role(**{"v-model": "value", "id": "{}-{}".format(field.role.name, member_role_id)}) }} -
-
-
+ {% set role = field.role.data if not field.deleted.data else "Access Suspended" %} +
+
+
+
+ {{ field.environment_name.data }} +
+

+ {{ role }} +

- - {% elif field.role.data != "No Access" and not field.deleted.data -%} -
-
- -
- {{ field.environment_name.data }} -
-

- {{ field.role.data }} -

-
-
-
+
+
+ {% if field.role.data == "No Access" and not field.deleted.data -%} + +
+ {{ field.role(**{"v-model": "value", "id": "{}-{}".format(field.role.name, member_role_id)}) }} +
+
+ {% elif field.role.data != "No Access" and not field.deleted.data -%} -
-
- -
- - {% set id = "{}-{}".format(field.deleted.name, member_role_id) %} - {{ field.deleted(id=id, checked=True, **{"v-model": "isChecked"}) }} - {{ field.deleted.label(for=id) | safe }} - -
-
-
+
+ + {% set id = "{}-{}".format(field.deleted.name, member_role_id) %} + {{ field.deleted(id=id, checked=True, **{"v-model": "isChecked"}) }} + {{ field.deleted.label(for=id) | safe }} + +
-
+ {% elif field.deleted.data -%} +

+ Suspended access cannot be modified. +

+ {%- endif %} + {{ field.environment_id() }}
- {%- endif %} - {{ field.environment_id() }} +
{% endmacro %} {% macro PermsFields(form, new=False, member_role_id=None) %} diff --git a/tests/domain/test_environment_roles.py b/tests/domain/test_environment_roles.py index 71bbbdf2..8f68207f 100644 --- a/tests/domain/test_environment_roles.py +++ b/tests/domain/test_environment_roles.py @@ -93,12 +93,21 @@ def test_disable_completed(application_role, environment): assert environment_role.status == EnvironmentRole.Status.DISABLED -def test_get_for_update(): - app_role = ApplicationRoleFactory.create() - env = EnvironmentFactory.create(application=app_role.application) - EnvironmentRoleFactory.create(application_role=app_role, environment=env, deleted=True) - role = EnvironmentRoles.get_for_update(app_role.id, env.id) +def test_get_for_update(application_role, environment): + EnvironmentRoleFactory.create( + application_role=application_role, environment=environment, deleted=True + ) + role = EnvironmentRoles.get_for_update(application_role.id, environment.id) assert role - assert role.application_role == app_role - assert role.environment == env + assert role.application_role == application_role + assert role.environment == environment assert role.deleted + + +def test_get_all_for_application_member(application_role, environment): + EnvironmentRoleFactory.create( + application_role=application_role, environment=environment, deleted=True + ) + + roles = EnvironmentRoles.get_all_for_application_member(application_role.id) + assert len(roles) == 1 diff --git a/tests/domain/test_environments.py b/tests/domain/test_environments.py index 112c33af..a3562741 100644 --- a/tests/domain/test_environments.py +++ b/tests/domain/test_environments.py @@ -61,9 +61,7 @@ def test_update_env_role_no_change(): def test_update_env_role_deleted_role(): env_role = EnvironmentRoleFactory.create(role=CSPRole.BASIC_ACCESS.value) - Environments.update_env_role( - env_role.environment, env_role.application_role, None - ) + Environments.update_env_role(env_role.environment, env_role.application_role, None) assert not Environments.update_env_role( env_role.environment, env_role.application_role, CSPRole.TECHNICAL_READ.value )