diff --git a/backend/geonature/core/gn_synthese/routes.py b/backend/geonature/core/gn_synthese/routes.py index 1792cc52ef..8e22aac2dd 100644 --- a/backend/geonature/core/gn_synthese/routes.py +++ b/backend/geonature/core/gn_synthese/routes.py @@ -1489,8 +1489,8 @@ def update_content_report(id_report): @routes.route("/reports", methods=["GET"]) -@permissions.check_cruved_scope("R", get_scope=True, module_code="SYNTHESE") -def list_all_reports(scope): +@permissions_required("R", module_code="SYNTHESE") +def list_all_reports(permissions): type_name = request.args.get("type") orderby = request.args.get("orderby", "creation_date") sort = request.args.get("sort") @@ -1530,10 +1530,11 @@ def list_all_reports(scope): # On vérifie les permissions en lecture sur la synthese query = select(Synthese.id_synthese).select_from(Synthese) - query = Synthese.filter_by_scope(scope=scope, user=g.current_user, query=query) - - res_ids_synthese = db.session.execute(query) - ids_synthese = [row[0] for row in res_ids_synthese] + synthese_query_obj = SyntheseQuery(Synthese, query, {}) + synthese_query_obj.filter_query_with_cruved(g.current_user, permissions) + res_ids_synthese = db.session.execute(synthese_query_obj.query) + result = res_ids_synthese.fetchall() + ids_synthese = [row[0] for row in result] req = req.filter(TReport.id_synthese.in_(ids_synthese)) SORT_COLUMNS = { diff --git a/backend/geonature/tests/test_reports.py b/backend/geonature/tests/test_reports.py index aaba5735c8..40fe0a145c 100644 --- a/backend/geonature/tests/test_reports.py +++ b/backend/geonature/tests/test_reports.py @@ -1,5 +1,6 @@ import json +from datetime import datetime import pytest from flask import url_for from sqlalchemy import func, select, exists @@ -215,15 +216,19 @@ def test_list_all_reports( # Verify sorting items = response.json["items"] + reverse_sort = sort == "desc" if orderby == "creation_date": - dates = [item["creation_date"] for item in items] - assert dates == sorted(dates, reverse=(sort == "desc")) + dates = [ + datetime.strptime(item["creation_date"], "%a, %d %b %Y %H:%M:%S %Z") + for item in items + ] + assert dates == sorted(dates, reverse=reverse_sort) elif orderby == "content": contents = [item["content"] for item in items] - assert contents == sorted(contents, reverse=(sort == "desc")) + assert contents == sorted(contents, reverse=reverse_sort) elif orderby == "user.nom_complet": names = [item["user"]["nom_complet"] for item in items] - assert names == sorted(names, reverse=(sort == "desc")) + assert names == sorted(names, reverse=reverse_sort) @pytest.mark.usefixtures("client_class", "notifications_enabled", "temporary_transaction")