Skip to content

Commit

Permalink
fix(mtd): fix synchronize_mtd before_request function
Browse files Browse the repository at this point in the history
Use `flask_login.current_user` ; rather than `g.current_user` that may not exist due to uncontrolled order of execution for before_request functions calls ; to retrieve the `id_role` specified for user MTD synchronization.
If not user authenticatd ; i.e. `flask_login.current_user.is_authenticated` is `False` ; no user MTD sync is made.
  • Loading branch information
VincentCauchois authored and jacquesfize committed Apr 15, 2024
1 parent be8624b commit b13aeda
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions backend/geonature/core/gn_meta/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@
@routes.before_request
def synchronize_mtd():
if request.endpoint in ["gn_meta.get_datasets", "gn_meta.get_acquisition_frameworks_list"]:
try:
sync_af_and_ds_by_user(id_role=g.current_user.id_role)
except Exception as e:
log.exception("Error while get JDD via MTD")
from flask_login import current_user

if current_user.is_authenticated:
try:
sync_af_and_ds_by_user(id_role=current_user.id_role)
except Exception as e:
log.exception("Error while get JDD via MTD")


@routes.route("/datasets", methods=["GET", "POST"])
Expand Down

0 comments on commit b13aeda

Please sign in to comment.