diff --git a/applications/workspaces/server/workspaces/persistence/crud_persistence.py b/applications/workspaces/server/workspaces/persistence/crud_persistence.py index 7af18590..97e2378e 100644 --- a/applications/workspaces/server/workspaces/persistence/crud_persistence.py +++ b/applications/workspaces/server/workspaces/persistence/crud_persistence.py @@ -52,6 +52,22 @@ def check(self): def search_qs(self, filter=None, q=None, tags=None, user_id=None, show_all=False, *args, **kwargs): q_base = self.model.query + + if filter and any(field for field, condition, value in filter if field.key == "publicable" and value): + pass + elif user_id is not None: + # Admins see all workspaces, non admin users can see only their own workspaces or shared with them + if not show_all: + q_base = q_base.filter_by(user_id=user_id) + q_base = q_base.union(q_base.filter( + WorkspaceEntity.collaborators.any(user_id=user_id))) + else: + q_base = q_base + else: + # No logged in user, show only public (in case was not specified) + q_base = q_base.filter(WorkspaceEntity.publicable == True) + + if filter is not None: if tags: q_base = q_base.filter( @@ -65,22 +81,7 @@ def search_qs(self, filter=None, q=None, tags=None, user_id=None, show_all=False q_base = q_base.join(self.model.tags).filter( func.lower(Tag.tag).in_(func.lower(t) for t in tags.split("+"))) - if filter and any(field for field, condition, value in filter if field.key == "publicable" and value): - q1 = q_base - - elif user_id is not None: - # Admins see all workspaces, non admin users can see only their own workspaces or shared with them - if not show_all: - q1 = q_base.filter_by(user_id=user_id) - q1 = q1.union(q_base.filter( - WorkspaceEntity.collaborators.any(user_id=user_id))) - else: - q1 = q_base - else: - # No logged in user, show only public (in case was not specified) - q1 = q_base.filter(WorkspaceEntity.publicable == True) - - return q1.order_by(desc(WorkspaceEntity.timestamp_updated)) + return q_base.order_by(desc(WorkspaceEntity.timestamp_updated)) def delete(self, id): super().delete(id)