From a2d91ef271269c9c5d252770157176ad32a90d0d Mon Sep 17 00:00:00 2001 From: Walter Lorenzetti Date: Tue, 14 Nov 2023 12:06:27 +0100 Subject: [PATCH] Fix get filter layer saved with anonymous user. (#654) Co-authored-by: wlorenzetti --- g3w-admin/qdjango/api/projects/serializers.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/g3w-admin/qdjango/api/projects/serializers.py b/g3w-admin/qdjango/api/projects/serializers.py index f742c61d4..0c0b98f73 100644 --- a/g3w-admin/qdjango/api/projects/serializers.py +++ b/g3w-admin/qdjango/api/projects/serializers.py @@ -423,12 +423,14 @@ def to_representation(self, instance): # Get FilterToken layer filters saved: # Build a layer_filters dict to pass FilterLayerSaved instance to LayerSerializer + # Only if user is not anonymous layer_filters = {} - filters = FilterLayerSaved.objects.filter(user=self.request.user, layer__project=instance) - for f in filters: - if f.layer.qgs_layer_id not in layer_filters: - layer_filters[f.layer.qgs_layer_id] = [] - layer_filters[f.layer.qgs_layer_id].append(f) + if not self.request.user.is_anonymous: + filters = FilterLayerSaved.objects.filter(user=self.request.user, layer__project=instance) + for f in filters: + if f.layer.qgs_layer_id not in layer_filters: + layer_filters[f.layer.qgs_layer_id] = [] + layer_filters[f.layer.qgs_layer_id].append(f) def readLeaf(layer, container):