Refactor member status strings
Small refactor to reduce the duplication of arbitrary status strings.
This commit is contained in:
parent
2dd26e6cf1
commit
885f843e58
@ -1,7 +1,9 @@
|
|||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
|
|
||||||
from atst.database import db
|
from atst.database import db
|
||||||
from atst.models.workspace_role import WorkspaceRole, Status as WorkspaceRoleStatus
|
from atst.models.workspace_role import (
|
||||||
|
WorkspaceRole, Status as WorkspaceRoleStatus, MEMBER_STATUSES
|
||||||
|
)
|
||||||
from atst.models.user import User
|
from atst.models.user import User
|
||||||
|
|
||||||
from .roles import Roles
|
from .roles import Roles
|
||||||
@ -9,13 +11,9 @@ from .users import Users
|
|||||||
from .exceptions import NotFoundError
|
from .exceptions import NotFoundError
|
||||||
|
|
||||||
|
|
||||||
MEMBER_STATUSES = [
|
MEMBER_STATUS_CHOICES = [
|
||||||
{"name": "active", "display_name": "Active"},
|
dict(name=key, display_name=value)
|
||||||
{"name": "revoked", "display_name": "Revoked"},
|
for key, value in MEMBER_STATUSES.items()
|
||||||
{"name": "expired", "display_name": "Invite expired"},
|
|
||||||
{"name": "error", "display_name": "Error on invite"},
|
|
||||||
{"name": "pending", "display_name": "Pending"},
|
|
||||||
{"name": "unknown", "display_name": "Unknown errors"},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,16 @@ from atst.models.environment import Environment
|
|||||||
from atst.models.role import Role
|
from atst.models.role import Role
|
||||||
|
|
||||||
|
|
||||||
|
MEMBER_STATUSES = {
|
||||||
|
"active": "Active",
|
||||||
|
"revoked": "Revoked",
|
||||||
|
"expired": "Invite expired",
|
||||||
|
"error": "Error on invite",
|
||||||
|
"pending": "Pending",
|
||||||
|
"unknown": "Unknown errors",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Status(Enum):
|
class Status(Enum):
|
||||||
ACTIVE = "active"
|
ACTIVE = "active"
|
||||||
DISABLED = "disabled"
|
DISABLED = "disabled"
|
||||||
@ -72,21 +82,21 @@ class WorkspaceRole(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
|||||||
@property
|
@property
|
||||||
def display_status(self):
|
def display_status(self):
|
||||||
if self.status == Status.ACTIVE:
|
if self.status == Status.ACTIVE:
|
||||||
return "Active"
|
return MEMBER_STATUSES['active']
|
||||||
elif self.latest_invitation:
|
elif self.latest_invitation:
|
||||||
if self.latest_invitation.is_revoked:
|
if self.latest_invitation.is_revoked:
|
||||||
return "Revoked"
|
return MEMBER_STATUSES['revoked']
|
||||||
elif self.latest_invitation.is_rejected_wrong_user:
|
elif self.latest_invitation.is_rejected_wrong_user:
|
||||||
return "Error on invite"
|
return MEMBER_STATUSES['error']
|
||||||
elif (
|
elif (
|
||||||
self.latest_invitation.is_rejected_expired
|
self.latest_invitation.is_rejected_expired
|
||||||
or self.latest_invitation.is_expired
|
or self.latest_invitation.is_expired
|
||||||
):
|
):
|
||||||
return "Invite expired"
|
return MEMBER_STATUSES['expired']
|
||||||
else:
|
else:
|
||||||
return "Pending"
|
return MEMBER_STATUSES['pending']
|
||||||
else:
|
else:
|
||||||
return "Unknown errors"
|
return MEMBER_STATUSES['unknown']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def has_dod_id_error(self):
|
def has_dod_id_error(self):
|
||||||
|
@ -7,7 +7,7 @@ from atst.routes.workspaces.invitations import send_invite_email
|
|||||||
from atst.domain.exceptions import AlreadyExistsError
|
from atst.domain.exceptions import AlreadyExistsError
|
||||||
from atst.domain.projects import Projects
|
from atst.domain.projects import Projects
|
||||||
from atst.domain.workspaces import Workspaces
|
from atst.domain.workspaces import Workspaces
|
||||||
from atst.domain.workspace_roles import WorkspaceRoles, MEMBER_STATUSES
|
from atst.domain.workspace_roles import WorkspaceRoles, MEMBER_STATUS_CHOICES
|
||||||
from atst.domain.environments import Environments
|
from atst.domain.environments import Environments
|
||||||
from atst.domain.environment_roles import EnvironmentRoles
|
from atst.domain.environment_roles import EnvironmentRoles
|
||||||
from atst.forms.new_member import NewMemberForm
|
from atst.forms.new_member import NewMemberForm
|
||||||
@ -48,7 +48,7 @@ def workspace_members(workspace_id):
|
|||||||
"workspaces/members/index.html",
|
"workspaces/members/index.html",
|
||||||
workspace=workspace,
|
workspace=workspace,
|
||||||
role_choices=WORKSPACE_ROLE_DEFINITIONS,
|
role_choices=WORKSPACE_ROLE_DEFINITIONS,
|
||||||
status_choices=MEMBER_STATUSES,
|
status_choices=MEMBER_STATUS_CHOICES,
|
||||||
members=members_list,
|
members=members_list,
|
||||||
new_member=new_member,
|
new_member=new_member,
|
||||||
resent_invitation_to=resent_invitation_to,
|
resent_invitation_to=resent_invitation_to,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user