7

Make the static elements tracked users only

We cannot track anonymous users as the session expires after 10 minutes of
inactivity. This also avoids an issue where there is an error when the user's
session has expired and they navigate a page
This commit is contained in:
Todd Dembrey
2017-11-01 16:43:22 +00:00
parent b8bf27fb99
commit 1f4a4536ab
6 changed files with 86 additions and 40 deletions

View File

@ -175,7 +175,7 @@ class SessionSegmentsAdapter(BaseSegmentsAdapter):
# Run tests on all remaining enabled segments to verify applicability.
additional_segments = []
for segment in enabled_segments:
if segment.is_static and self.request.session.session_key in segment.sessions.values_list('session_key', flat=True):
if segment.is_static and segment.static_users.filter(id=self.request.user.id).exists():
additional_segments.append(segment)
elif not segment.is_static or not segment.is_full:
segment_rules = []
@ -186,11 +186,8 @@ class SessionSegmentsAdapter(BaseSegmentsAdapter):
match_any=segment.match_any)
if result and segment.is_static and not segment.is_full:
session = self.request.session.model.objects.get(
session_key=self.request.session.session_key,
expire_date__gt=timezone.now(),
)
segment.sessions.add(session)
if self.request.user.is_authenticated():
segment.static_users.add(self.request.user)
if result:
additional_segments.append(segment)