Skip to content

Commit

Permalink
Merge pull request #836 from OpenSourceBrain/feature/824
Browse files Browse the repository at this point in the history
#824 - fix the tags search in my workspace
  • Loading branch information
filippomc authored Dec 6, 2023
2 parents 7e0becf + 474e216 commit 644911d
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down

0 comments on commit 644911d

Please sign in to comment.