Move label display logic into the Label macro
This commit is contained in:
parent
58a0b2dd9d
commit
8aa302357b
@ -153,7 +153,6 @@ def view_new_application_step_3(application_id):
|
|||||||
application=application,
|
application=application,
|
||||||
members=members,
|
members=members,
|
||||||
new_member_form=new_member_form,
|
new_member_form=new_member_form,
|
||||||
label_info=LABEL_INFO,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,19 +21,6 @@ from atst.utils.localization import translate
|
|||||||
from atst.jobs import send_mail
|
from atst.jobs import send_mail
|
||||||
|
|
||||||
|
|
||||||
LABEL_INFO = {
|
|
||||||
"pending": {"icon": "envelope", "text": "invite pending", "type": "success",},
|
|
||||||
"expired": {"icon": "envelope", "text": "invite expired", "type": "error",},
|
|
||||||
"env_changes_pending": {
|
|
||||||
"icon": "exchange",
|
|
||||||
"text": "changes pending",
|
|
||||||
"type": "default",
|
|
||||||
},
|
|
||||||
"active": None,
|
|
||||||
"disabled": None,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_environments_obj_for_app(application):
|
def get_environments_obj_for_app(application):
|
||||||
return sorted(
|
return sorted(
|
||||||
[
|
[
|
||||||
@ -177,7 +164,6 @@ def render_settings_page(application, **kwargs):
|
|||||||
audit_events=audit_events,
|
audit_events=audit_events,
|
||||||
new_member_form=new_member_form,
|
new_member_form=new_member_form,
|
||||||
members=members,
|
members=members,
|
||||||
label_info=LABEL_INFO,
|
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
{%- endif %}
|
{%- endif %}
|
||||||
<br>
|
<br>
|
||||||
{% if env['pending'] -%}
|
{% if env['pending'] -%}
|
||||||
{{ Label('exchange', 'Changes Pending', classes='label--below')}}
|
{{ Label(type="changes_pending", classes='label--below')}}
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href='{{ url_for("applications.access_environment", environment_id=env.id)}}' target='_blank' rel='noopener noreferrer' class='application-list-item__environment__csp_link'>
|
<a href='{{ url_for("applications.access_environment", environment_id=env.id)}}' target='_blank' rel='noopener noreferrer' class='application-list-item__environment__csp_link'>
|
||||||
<span>{{ "portfolios.applications.csp_link" | translate }} {{ Icon('link', classes="icon--tiny") }}</span>
|
<span>{{ "portfolios.applications.csp_link" | translate }} {{ Icon('link', classes="icon--tiny") }}</span>
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
{% for member in members %}
|
{% for member in members %}
|
||||||
|
{% set invite_pending = member.role_status == 'invite_pending' %}
|
||||||
|
{% set invite_expired = member.role_status == 'invite_expired' %}
|
||||||
{%- if user_can(permissions.EDIT_APPLICATION_MEMBER) %}
|
{%- if user_can(permissions.EDIT_APPLICATION_MEMBER) %}
|
||||||
{% set modal_name = "edit_member-{}".format(loop.index) %}
|
{% set modal_name = "edit_member-{}".format(loop.index) %}
|
||||||
{% call Modal(modal_name, classes="form-content--app-mem") %}
|
{% call Modal(modal_name, classes="form-content--app-mem") %}
|
||||||
@ -52,7 +54,7 @@
|
|||||||
</base-form>
|
</base-form>
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
|
|
||||||
{%- if member.role_status == 'pending' or member.role_status == 'expired' %}
|
{%- if invite_pending or invite_expired %}
|
||||||
{% set resend_invite_modal = "resend_invite-{}".format(member.role_id) %}
|
{% set resend_invite_modal = "resend_invite-{}".format(member.role_id) %}
|
||||||
{% call Modal(resend_invite_modal, classes="form-content--app-mem") %}
|
{% call Modal(resend_invite_modal, classes="form-content--app-mem") %}
|
||||||
<div class="modal__form--header">
|
<div class="modal__form--header">
|
||||||
@ -73,7 +75,7 @@
|
|||||||
{% endif -%}
|
{% endif -%}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
|
||||||
{% if user_can(permissions.DELETE_APPLICATION_MEMBER) and (member.role_status == 'pending' or member.role_status == 'expired') -%}
|
{% if user_can(permissions.DELETE_APPLICATION_MEMBER) and (invite_pending or invite_expired) -%}
|
||||||
{% set revoke_invite_modal = "revoke_invite_{}".format(member.role_id) %}
|
{% set revoke_invite_modal = "revoke_invite_{}".format(member.role_id) %}
|
||||||
{% call Modal(name=revoke_invite_modal) %}
|
{% call Modal(name=revoke_invite_modal) %}
|
||||||
<form method="post" action="{{ url_for('applications.revoke_invite', application_id=application.id, application_role_id=member.role_id) }}">
|
<form method="post" action="{{ url_for('applications.revoke_invite', application_id=application.id, application_role_id=member.role_id) }}">
|
||||||
@ -104,13 +106,13 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for member in members %}
|
{% for member in members %}
|
||||||
{% set perms_modal = "edit_member-{}".format(loop.index) %}
|
{% set perms_modal = "edit_member-{}".format(loop.index) %}
|
||||||
|
{% set invite_pending = member.role_status == 'invite_pending' %}
|
||||||
|
{% set invite_expired = member.role_status == 'invite_expired' %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<strong>{{ member.user_name }}</strong>
|
<strong>{{ member.user_name }}</strong>
|
||||||
<br>
|
<br>
|
||||||
{% if label_info[member.role_status] -%}
|
{{ Label(type=member.role_status, classes='label--below') }}
|
||||||
{{ Label(classes='label--below', **label_info[member.role_status]) }}
|
|
||||||
{%- endif %}
|
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
@ -150,7 +152,7 @@
|
|||||||
<a v-on:click="openModal('{{ perms_modal }}')">
|
<a v-on:click="openModal('{{ perms_modal }}')">
|
||||||
{{ "portfolios.applications.members.menu.edit" | translate }}
|
{{ "portfolios.applications.members.menu.edit" | translate }}
|
||||||
</a>
|
</a>
|
||||||
{% if member.role_status == 'pending' or member.role_status == 'expired' -%}
|
{% if invite_pending or invite_expired -%}
|
||||||
{% set revoke_invite_modal = "revoke_invite_{}".format(member.role_id) %}
|
{% set revoke_invite_modal = "revoke_invite_{}".format(member.role_id) %}
|
||||||
{% set resend_invite_modal = "resend_invite-{}".format(member.role_id) %}
|
{% set resend_invite_modal = "resend_invite-{}".format(member.role_id) %}
|
||||||
<a v-on:click='openModal("{{ resend_invite_modal }}")'>
|
<a v-on:click='openModal("{{ resend_invite_modal }}")'>
|
||||||
|
@ -1,8 +1,19 @@
|
|||||||
{% from "components/icon.html" import Icon %}
|
{% from "components/icon.html" import Icon %}
|
||||||
|
|
||||||
{% macro Label(icon, text, type=None, classes="") -%}
|
{% macro Label(type=None, classes="") -%}
|
||||||
|
{% set label_info = {
|
||||||
|
"invite_pending": {"icon": "envelope", "text": "invite pending", "color": "success",},
|
||||||
|
"invite_expired": {"icon": "envelope", "text": "invite expired", "color": "error",},
|
||||||
|
"changes_pending": {
|
||||||
|
"icon": "exchange",
|
||||||
|
"text": "changes pending",
|
||||||
|
"color": "default",
|
||||||
|
},
|
||||||
|
} %}
|
||||||
|
|
||||||
<span class='label {% if type %}label--{{ type }}{% endif %} {{ classes }}'>
|
{% if type -%}
|
||||||
{{ Icon(icon) }} {{ text }}
|
<span class='label label--{{ label_info[type]["color"] }} {{ classes }}'>
|
||||||
</span>
|
{{ Icon(label_info[type]["icon"]) }} {{ label_info[type]["text"] }}
|
||||||
|
</span>
|
||||||
|
{%- endif %}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
@ -61,21 +61,18 @@ def test_environment_roles():
|
|||||||
|
|
||||||
|
|
||||||
def test_display_status():
|
def test_display_status():
|
||||||
app_role_expired_invite = ApplicationRoleFactory.create()
|
|
||||||
yesterday = datetime.date.today() - datetime.timedelta(days=1)
|
yesterday = datetime.date.today() - datetime.timedelta(days=1)
|
||||||
ApplicationInvitationFactory.create(
|
expired_invite = ApplicationInvitationFactory.create(expiration_time=yesterday)
|
||||||
role=app_role_expired_invite, expiration_time=yesterday
|
assert expired_invite.role.display_status == "invite_expired"
|
||||||
)
|
|
||||||
assert app_role_expired_invite.display_status == "expired"
|
|
||||||
|
|
||||||
app_role_pending = ApplicationRoleFactory.create()
|
app_role_pending = ApplicationRoleFactory.create()
|
||||||
invite = ApplicationInvitationFactory.create(
|
invite = ApplicationInvitationFactory.create(
|
||||||
role=app_role_pending, user=app_role_pending.user
|
role=app_role_pending, user=app_role_pending.user
|
||||||
)
|
)
|
||||||
assert app_role_pending.display_status == "pending"
|
assert app_role_pending.display_status == "invite_pending"
|
||||||
|
|
||||||
app_role_active = ApplicationRoleFactory.create(status=ApplicationRoleStatus.ACTIVE)
|
app_role_active = ApplicationRoleFactory.create(status=ApplicationRoleStatus.ACTIVE)
|
||||||
assert app_role_active.display_status == "active"
|
assert app_role_active.display_status == None
|
||||||
|
|
||||||
env_role_pending = EnvironmentRoleFactory.create(application_role=app_role_active)
|
env_role_pending = EnvironmentRoleFactory.create(application_role=app_role_active)
|
||||||
assert env_role_pending.application_role.display_status == "env_changes_pending"
|
assert env_role_pending.application_role.display_status == "changes_pending"
|
||||||
|
@ -23,11 +23,8 @@ from atst.routes.applications.settings import (
|
|||||||
filter_env_roles_form_data,
|
filter_env_roles_form_data,
|
||||||
filter_env_roles_data,
|
filter_env_roles_data,
|
||||||
get_environments_obj_for_app,
|
get_environments_obj_for_app,
|
||||||
<<<<<<< HEAD
|
|
||||||
handle_create_member,
|
handle_create_member,
|
||||||
handle_update_member,
|
handle_update_member,
|
||||||
=======
|
|
||||||
>>>>>>> Move display status logic to be a property of an ApplicationRole
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.utils import captured_templates
|
from tests.utils import captured_templates
|
||||||
|
Loading…
x
Reference in New Issue
Block a user