Skip to content

Commit

Permalink
feat: get datasets when user is None
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouhaoJiang committed Jul 8, 2024
1 parent 5cc539a commit 85c8399
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions api/services/dataset_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,20 @@ def get_datasets(page, per_page, provider="vendor", tenant_id=None, user=None, s

query = Dataset.query.filter(Dataset.provider == provider, Dataset.tenant_id == tenant_id)

if user.current_role == TenantAccountRole.DATASET_OPERATOR:
dataset_permission = DatasetPermission.query.filter_by(
account_id=user.id,
tenant_id=tenant_id
).all()
if dataset_permission:
dataset_ids = [dp.dataset_id for dp in dataset_permission]
query = query.filter(Dataset.id.in_(dataset_ids))
else:
query = query.filter(db.false())
if user:
if user.current_role == TenantAccountRole.DATASET_OPERATOR:
dataset_permission = DatasetPermission.query.filter_by(
account_id=user.id,
tenant_id=tenant_id
).all()
if dataset_permission:
dataset_ids = [dp.dataset_id for dp in dataset_permission]
query = query.filter(Dataset.id.in_(dataset_ids))
else:
query = query.filter(db.false())
else:
permission_filter = Dataset.permission == 'all_team_members'
query = query.filter(permission_filter)

if search:
query = query.filter(Dataset.name.ilike(f'%{search}%'))
Expand All @@ -91,7 +95,7 @@ def get_datasets(page, per_page, provider="vendor", tenant_id=None, user=None, s
)

# check datasets permission,
if user.current_role != TenantAccountRole.DATASET_OPERATOR:
if user and user.current_role != TenantAccountRole.DATASET_OPERATOR:
datasets.items, datasets.total = DatasetService.filter_datasets_by_permission(
user, datasets, tenant_id
)
Expand Down

0 comments on commit 85c8399

Please sign in to comment.