Move display status logic to be a property of an ApplicationRole
This commit is contained in:
parent
9f90f5abbd
commit
58a0b2dd9d
@ -110,6 +110,29 @@ class ApplicationRole(
|
||||
def is_active(self):
|
||||
return self.status == Status.ACTIVE
|
||||
|
||||
@property
|
||||
def display_status(self):
|
||||
if (
|
||||
self.is_pending
|
||||
and self.latest_invitation
|
||||
and self.latest_invitation.is_pending
|
||||
):
|
||||
return "invite_pending"
|
||||
|
||||
elif (
|
||||
self.is_pending
|
||||
and self.latest_invitation
|
||||
and self.latest_invitation.is_expired
|
||||
):
|
||||
return "invite_expired"
|
||||
|
||||
elif self.is_active and any(
|
||||
env_role.is_pending for env_role in self.environment_roles
|
||||
):
|
||||
return "changes_pending"
|
||||
|
||||
return None
|
||||
|
||||
|
||||
Index(
|
||||
"application_role_user_application",
|
||||
|
@ -111,20 +111,6 @@ def filter_env_roles_form_data(member, environments):
|
||||
return env_roles_form_data
|
||||
|
||||
|
||||
def get_app_role_status(app_role):
|
||||
status = app_role.status.value
|
||||
|
||||
if app_role.is_pending and app_role.latest_invitation.is_expired:
|
||||
status = "expired"
|
||||
|
||||
if app_role.is_active and any(
|
||||
env_role.is_pending for env_role in app_role.environment_roles
|
||||
):
|
||||
status = "env_changes_pending"
|
||||
|
||||
return status
|
||||
|
||||
|
||||
def get_members_data(application):
|
||||
members_data = []
|
||||
for member in application.members:
|
||||
@ -149,7 +135,7 @@ def get_members_data(application):
|
||||
"user_name": member.user_name,
|
||||
"permission_sets": permission_sets,
|
||||
"environment_roles": environment_roles,
|
||||
"role_status": get_app_role_status(member),
|
||||
"role_status": member.display_status,
|
||||
"form": form,
|
||||
"update_invite_form": update_invite_form,
|
||||
}
|
||||
|
@ -58,3 +58,24 @@ def test_environment_roles():
|
||||
)
|
||||
|
||||
assert not EnvironmentRoles.get_by_user_and_environment(user.id, environment2.id)
|
||||
|
||||
|
||||
def test_display_status():
|
||||
app_role_expired_invite = ApplicationRoleFactory.create()
|
||||
yesterday = datetime.date.today() - datetime.timedelta(days=1)
|
||||
ApplicationInvitationFactory.create(
|
||||
role=app_role_expired_invite, expiration_time=yesterday
|
||||
)
|
||||
assert app_role_expired_invite.display_status == "expired"
|
||||
|
||||
app_role_pending = ApplicationRoleFactory.create()
|
||||
invite = ApplicationInvitationFactory.create(
|
||||
role=app_role_pending, user=app_role_pending.user
|
||||
)
|
||||
assert app_role_pending.display_status == "pending"
|
||||
|
||||
app_role_active = ApplicationRoleFactory.create(status=ApplicationRoleStatus.ACTIVE)
|
||||
assert app_role_active.display_status == "active"
|
||||
|
||||
env_role_pending = EnvironmentRoleFactory.create(application_role=app_role_active)
|
||||
assert env_role_pending.application_role.display_status == "env_changes_pending"
|
||||
|
@ -23,8 +23,11 @@ from atst.routes.applications.settings import (
|
||||
filter_env_roles_form_data,
|
||||
filter_env_roles_data,
|
||||
get_environments_obj_for_app,
|
||||
<<<<<<< HEAD
|
||||
handle_create_member,
|
||||
handle_update_member,
|
||||
=======
|
||||
>>>>>>> Move display status logic to be a property of an ApplicationRole
|
||||
)
|
||||
|
||||
from tests.utils import captured_templates
|
||||
|
Loading…
x
Reference in New Issue
Block a user