Don't show DISABLED workspace members

This commit is contained in:
richard-dds 2018-11-26 10:58:05 -05:00
parent 8dcde9da84
commit 27cf1783e3
3 changed files with 25 additions and 6 deletions

View File

@ -144,7 +144,10 @@ class Workspaces(object):
def revoke_access(cls, user, workspace_id, workspace_role_id): def revoke_access(cls, user, workspace_id, workspace_role_id):
workspace = WorkspacesQuery.get(workspace_id) workspace = WorkspacesQuery.get(workspace_id)
Authorization.check_workspace_permission( Authorization.check_workspace_permission(
user, workspace, Permissions.ASSIGN_AND_UNASSIGN_ATAT_ROLE, "revoke workspace access" user,
workspace,
Permissions.ASSIGN_AND_UNASSIGN_ATAT_ROLE,
"revoke workspace access",
) )
workspace_role = WorkspaceRoles.get_by_id(workspace_role_id) workspace_role = WorkspaceRoles.get_by_id(workspace_role_id)
workspace_role.status = WorkspaceRoleStatus.DISABLED workspace_role.status = WorkspaceRoleStatus.DISABLED

View File

@ -2,16 +2,16 @@ from sqlalchemy import Column, ForeignKey, String
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from itertools import chain from itertools import chain
from atst.models import Base from atst.models import Base, mixins, types
from atst.models.types import Id from atst.models.workspace_role import WorkspaceRole, Status as WorkspaceRoleStatus
from atst.models import mixins
from atst.utils import first_or_none from atst.utils import first_or_none
from atst.database import db
class Workspace(Base, mixins.TimestampsMixin, mixins.AuditableMixin): class Workspace(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
__tablename__ = "workspaces" __tablename__ = "workspaces"
id = Id() id = types.Id()
name = Column(String) name = Column(String)
request_id = Column(ForeignKey("requests.id"), nullable=False) request_id = Column(ForeignKey("requests.id"), nullable=False)
projects = relationship("Project", back_populates="workspace") projects = relationship("Project", back_populates="workspace")
@ -39,7 +39,12 @@ class Workspace(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
@property @property
def members(self): def members(self):
return self.roles return (
db.session.query(WorkspaceRole)
.filter(WorkspaceRole.workspace_id == self.id)
.filter(WorkspaceRole.status != WorkspaceRoleStatus.DISABLED)
.all()
)
@property @property
def displayname(self): def displayname(self):

View File

@ -309,3 +309,14 @@ def test_can_remove_workspace_access():
workspace_role = WorkspaceRoleFactory.create(workspace=workspace) workspace_role = WorkspaceRoleFactory.create(workspace=workspace)
Workspaces.revoke_access(workspace.owner, workspace.id, workspace_role.id) Workspaces.revoke_access(workspace.owner, workspace.id, workspace_role.id)
assert Workspaces.for_user(workspace_role.user) == [] assert Workspaces.for_user(workspace_role.user) == []
def test_disabled_members_dont_show_up(session):
workspace = WorkspaceFactory.create()
WorkspaceRoleFactory.create(workspace=workspace, status=WorkspaceRoleStatus.ACTIVE)
WorkspaceRoleFactory.create(
workspace=workspace, status=WorkspaceRoleStatus.DISABLED
)
# should only return workspace owner and ACTIVE member
assert len(workspace.members) == 2