more granular invitation status and a display status for workspace members
This commit is contained in:
@@ -4,7 +4,7 @@ import secrets
|
||||
|
||||
from sqlalchemy import Column, ForeignKey, Enum as SQLAEnum, TIMESTAMP, String
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.orm import relationship, backref
|
||||
|
||||
from atst.models import Base, types
|
||||
from atst.models.mixins.timestamps import TimestampsMixin
|
||||
@@ -15,7 +15,8 @@ class Status(Enum):
|
||||
ACCEPTED = "accepted"
|
||||
REVOKED = "revoked"
|
||||
PENDING = "pending"
|
||||
REJECTED = "rejected"
|
||||
REJECTED_WRONG_USER = "rejected_wrong_user"
|
||||
REJECTED_EXPIRED = "rejected_expired"
|
||||
|
||||
|
||||
class Invitation(Base, TimestampsMixin, AuditableMixin):
|
||||
@@ -29,7 +30,10 @@ class Invitation(Base, TimestampsMixin, AuditableMixin):
|
||||
workspace_role_id = Column(
|
||||
UUID(as_uuid=True), ForeignKey("workspace_roles.id"), index=True
|
||||
)
|
||||
workspace_role = relationship("WorkspaceRole", backref="invitations")
|
||||
workspace_role = relationship(
|
||||
"WorkspaceRole",
|
||||
backref=backref("invitations", order_by="Invitation.time_created"),
|
||||
)
|
||||
|
||||
inviter_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), index=True)
|
||||
inviter = relationship("User", backref="sent_invites", foreign_keys=[inviter_id])
|
||||
@@ -59,7 +63,15 @@ class Invitation(Base, TimestampsMixin, AuditableMixin):
|
||||
|
||||
@property
|
||||
def is_rejected(self):
|
||||
return self.status == Status.REJECTED
|
||||
return self.status in [Status.REJECTED_WRONG_USER, Status.REJECTED_EXPIRED]
|
||||
|
||||
@property
|
||||
def is_rejected_expired(self):
|
||||
return self.status == Status.REJECTED_EXPIRED
|
||||
|
||||
@property
|
||||
def is_rejected_wrong_user(self):
|
||||
return self.status == Status.REJECTED_WRONG_USER
|
||||
|
||||
@property
|
||||
def is_expired(self):
|
||||
|
@@ -36,18 +36,26 @@ class WorkspaceRole(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
||||
self.role.name, self.workspace.name, self.user_id, self.id
|
||||
)
|
||||
|
||||
@property
|
||||
def latest_invitation(self):
|
||||
if self.invitations:
|
||||
return self.invitations[-1]
|
||||
|
||||
@property
|
||||
def display_status(self):
|
||||
import ipdb; ipdb.set_trace()
|
||||
if self.status == Status.ACTIVE:
|
||||
return "Active"
|
||||
else:
|
||||
if any(i.is_expired for i in self.invitations):
|
||||
return "Invitation Expired"
|
||||
elif any(i.is_rejected for i in self.invitations):
|
||||
return "Invitation Rejected"
|
||||
elif self.latest_invitation:
|
||||
if self.latest_invitation.is_rejected_expired:
|
||||
return "Invite expired"
|
||||
elif self.latest_invitation.is_rejected_wrong_user:
|
||||
return "Error on invite"
|
||||
elif self.latest_invitation.is_expired:
|
||||
return "Invite expired"
|
||||
else:
|
||||
return "Pending"
|
||||
else:
|
||||
return "Unknown errors"
|
||||
|
||||
|
||||
Index(
|
||||
|
Reference in New Issue
Block a user