From 85c8399794c4bd2e0b0bae85e1ef320274d66b91 Mon Sep 17 00:00:00 2001 From: Joe <1264204425@qq.com> Date: Mon, 8 Jul 2024 17:07:43 +0800 Subject: [PATCH] feat: get datasets when user is None --- api/services/dataset_service.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/api/services/dataset_service.py b/api/services/dataset_service.py index 450c268b0d4041..b8a995e3b9c044 100644 --- a/api/services/dataset_service.py +++ b/api/services/dataset_service.py @@ -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}%')) @@ -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 )