diff --git a/g3w-admin/core/utils/decorators.py b/g3w-admin/core/utils/decorators.py index fa1b44dc9..94f7b1610 100644 --- a/g3w-admin/core/utils/decorators.py +++ b/g3w-admin/core/utils/decorators.py @@ -10,6 +10,7 @@ from django.contrib.auth import REDIRECT_FIELD_NAME from guardian.exceptions import GuardianError from guardian.utils import get_40x_or_None, get_anonymous_user +from qdjango.utils.session import reset_filtertoken import logging @@ -169,6 +170,9 @@ def _wrapped_view(request, *args, **kwargs): else: user_pk = request.user.pk + # Reset sessiontokenfilter + reset_filtertoken(request) + key = f"{key_prefix}{'_'.join([str(kwargs[k]) for k in key_args] + [str(user_pk)])}" logger.debug(f"[CACHING /api/config]: Key {key}") response = cache.get(key) diff --git a/g3w-admin/qdjango/api/projects/serializers.py b/g3w-admin/qdjango/api/projects/serializers.py index 23be91bfa..089d0272c 100644 --- a/g3w-admin/qdjango/api/projects/serializers.py +++ b/g3w-admin/qdjango/api/projects/serializers.py @@ -20,6 +20,7 @@ from qdjango.signals import load_qdjango_widget_layer from qdjango.apps import get_qgs_project from qdjango.utils.structure import QdjangoMetaLayer, datasourcearcgis2dict +from qdjango.utils.session import reset_filtertoken from qdjango.api.layers.serializers import FilterLayerSavedSerializer from core.utils.structure import mapLayerAttributes from core.configs import * @@ -224,19 +225,6 @@ def get_metadata(self, instance, qgs_project): return metadata - def reset_filtertoken(self): - """Check session token filter ad delete it""" - - try: - if settings.SESSION_COOKIE_NAME in self.request.COOKIES: - stf = SessionTokenFilter.objects.get( - sessionid=self.request.COOKIES[settings.SESSION_COOKIE_NAME]) - stf.delete() - except AttributeError: - return None - except SessionTokenFilter.DoesNotExist: - return None - def layer_is_empty(self, layer): """ Check if a vector layer is empty (not data) @@ -614,7 +602,7 @@ def readLeaf(layer, container): ret['messages'] = self.get_messages(instance) # reset tokenfilter by session - self.reset_filtertoken() + reset_filtertoken(self.request) # add edit url if user has grant if hasattr(self.request, 'user') and self.request.user.has_perm('qdjango.change_project', instance): diff --git a/g3w-admin/qdjango/utils/session.py b/g3w-admin/qdjango/utils/session.py new file mode 100644 index 000000000..b5ce7a27e --- /dev/null +++ b/g3w-admin/qdjango/utils/session.py @@ -0,0 +1,31 @@ +# coding=utf-8 +"""" Utility function for session +.. note:: This program is free software; you can redistribute it and/or modify + it under the terms of the Mozilla Public License 2.0. + +""" + +__author__ = 'lorenzetti@gis3w.it' +__date__ = '2024-11-15' +__copyright__ = 'Copyright 2015 - 2024, Gis3w' +__license__ = 'MPL 2.0' + +from django.conf import settings +from qdjango.models import SessionTokenFilter + +def reset_filtertoken(request): + """ + Check session token filter ad delete it + + :param request: Django request object + """ + + try: + if settings.SESSION_COOKIE_NAME in request.COOKIES: + stf = SessionTokenFilter.objects.get( + sessionid=request.COOKIES[settings.SESSION_COOKIE_NAME]) + stf.delete() + except AttributeError: + return None + except SessionTokenFilter.DoesNotExist: + return None \ No newline at end of file diff --git a/g3w-admin/qdjango/vector.py b/g3w-admin/qdjango/vector.py index 545337d43..2260dcacc 100644 --- a/g3w-admin/qdjango/vector.py +++ b/g3w-admin/qdjango/vector.py @@ -421,7 +421,7 @@ def _get_sessiontokenfilter(): """ Get or create an instance of SessionTokeFilter model - :return: A tuple with the instance of SessioneTokeFilter model and a boolean state for created or retreive + :return: A tuple with the instance of SessionTokeFilter model and a boolean state for created or retreive :rtype: tuple """ s, created = SessionTokenFilter.objects.get_or_create( @@ -545,7 +545,7 @@ def _check_url_params_name_fid(mode): s, created = _get_sessiontokenfilter() - # Check if a recordo for surrent layer is present for update or create it + # Check if a record for current layer is present for update or create it s.stf_layers.update_or_create( layer=fls.layer, defaults={