Skip to content

Commit

Permalink
Update filter list endpoint for None tenant key (AOT-Technologies#1738)
Browse files Browse the repository at this point in the history
Update filter list endpoint to include default filter when tenant key is None
  • Loading branch information
auslin-aot authored Nov 17, 2023
1 parent e37e626 commit d448f64
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions forms-flow-api/src/formsflow_api/models/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ def find_user_filters(
admin: bool = False,
):
"""Find active filters of the user."""
query = cls._auth_query(roles, user, tenant, admin)
query = cls._auth_query(
roles, user, tenant, admin, filter_empty_tenant_key=True
)
query = query.filter(Filter.status == str(FilterStatus.ACTIVE.value))
return query.all()

@classmethod
def _auth_query(cls, roles, user, tenant, admin):
def _auth_query( # pylint: disable=too-many-arguments
cls, roles, user, tenant, admin, filter_empty_tenant_key=False
):
query = cls.query
if not admin:
role_condition = [Filter.roles.contains([role]) for role in roles]
Expand All @@ -90,7 +94,12 @@ def _auth_query(cls, roles, user, tenant, admin):
)
)
if tenant:
query = query.filter(Filter.tenant == tenant)
if filter_empty_tenant_key:
query = query.filter(
or_(Filter.tenant == tenant, Filter.tenant.is_(None))
)
else:
query = query.filter(Filter.tenant == tenant)
return query

@classmethod
Expand Down

0 comments on commit d448f64

Please sign in to comment.