diff --git a/backend/geonature/core/gn_meta/models/datasets.py b/backend/geonature/core/gn_meta/models/datasets.py index 7e93809419..91cba8f817 100644 --- a/backend/geonature/core/gn_meta/models/datasets.py +++ b/backend/geonature/core/gn_meta/models/datasets.py @@ -201,21 +201,21 @@ def filter_by_scope(cls, scope, *, query, user=None): elif scope in (1, 2): ors = [ cls.id_digitizer == user.id_role, - # cls.cor_dataset_actor.any(id_role=user.id_role), - # cls.acquisition_framework.has(id_digitizer=user.id_role), - # cls.acquisition_framework.has( - # TAcquisitionFramework.cor_af_actor.any(id_role=user.id_role), - # ), + cls.cor_dataset_actor.any(id_role=user.id_role), + cls.acquisition_framework.has(id_digitizer=user.id_role), + cls.acquisition_framework.has( + TAcquisitionFramework.cor_af_actor.any(id_role=user.id_role), + ), ] # if organism is None => do not filter on id_organism even if level = 2 - # if scope == 2 and user.id_organisme is not None: - # ors += [ - # cls.cor_dataset_actor.any(id_organism=user.id_organisme), - # cls.acquisition_framework.has( - # TAcquisitionFramework.cor_af_actor.any(id_organism=user.id_organisme), - # ), - # ] - # whereclause = or_(*ors) + if scope == 2 and user.id_organisme is not None: + ors += [ + cls.cor_dataset_actor.any(id_organism=user.id_organisme), + cls.acquisition_framework.has( + TAcquisitionFramework.cor_af_actor.any(id_organism=user.id_organisme), + ), + ] + whereclause = or_(*ors) return query.where(whereclause) @qfilter(query=True) diff --git a/backend/geonature/core/imports/checks/dataframe/core.py b/backend/geonature/core/imports/checks/dataframe/core.py index 5497170cb4..167e711333 100644 --- a/backend/geonature/core/imports/checks/dataframe/core.py +++ b/backend/geonature/core/imports/checks/dataframe/core.py @@ -265,8 +265,8 @@ def check_datasets( TDatasets.filter_by_creatable( user=imprt.authors[0], module_code=module_code, object_code=object_code ) - # .where(TDatasets.unique_dataset_id.in_(uuid)) - # .options(sa.orm.raiseload("*")) + .where(TDatasets.unique_dataset_id.in_(uuid)) + .options(sa.orm.raiseload("*")) ) .scalars() .all() diff --git a/backend/geonature/tests/imports/test_imports_synthese.py b/backend/geonature/tests/imports/test_imports_synthese.py index 66745e7cd4..0410d26885 100644 --- a/backend/geonature/tests/imports/test_imports_synthese.py +++ b/backend/geonature/tests/imports/test_imports_synthese.py @@ -125,6 +125,7 @@ def autogenerate(): @pytest.fixture() def import_dataset(datasets, import_file_name): + ds = datasets["own_dataset"] if import_file_name == "nomenclatures_file.csv": previous_data_origin = ds.nomenclature_data_origin @@ -176,20 +177,24 @@ def import_dataset(datasets, import_file_name): @pytest.fixture() -def uploaded_import(client, users): +def uploaded_import(client, datasets, users): set_logged_user(client, users["user"]) - filename = "valid_file.csv" - file = (open(tests_path / "files" / "synthese" / filename, "rb"), filename) - - r = client.post( - url_for("import.upload_file", destination="synthese"), - data={"file": file}, - ) - assert r.status_code == 200, r.data - unset_logged_user(client) - # db.session.refresh(uploaded_import) - # return uploaded_import + # Upload step + test_file_name = "valid_file.csv" + with open(tests_path / "files" / "synthese" / test_file_name, "rb") as f: + f.seek(0) + data = { + "file": (f, test_file_name), + "datasetId": datasets["own_dataset"].id_dataset, + } + r = client.post( + url_for("import.upload_file"), + data=data, + headers=Headers({"Content-Type": "multipart/form-data"}), + ) + assert r.status_code == 200, r.data + return db.session.get(TImports, r.get_json()["id_import"]) @pytest.fixture()