Move display status logic to be a property of an ApplicationRole

This commit is contained in:
leigh-mil
2019-11-19 10:43:11 -05:00
parent 9f90f5abbd
commit 58a0b2dd9d
4 changed files with 48 additions and 15 deletions

View File

@@ -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",

View File

@@ -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,
}