From c770e6cfa6a0c262669041281c675d212021248d Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sun, 8 Jul 2018 22:19:51 +0200 Subject: [PATCH] Create our own anonymous user class This is required so the anonymous user also has a time zone (which is required to render public events.) --- calsocial/__init__.py | 4 ++-- calsocial/security.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/calsocial/__init__.py b/calsocial/__init__.py index 2468a7a..35b143d 100644 --- a/calsocial/__init__.py +++ b/calsocial/__init__.py @@ -76,7 +76,7 @@ class CalendarSocialApp(Flask): def __init__(self, name, config=None): from .models import db, User, Role - from .security import security + from .security import security, AnonymousUser Flask.__init__(self, name) @@ -91,7 +91,7 @@ class CalendarSocialApp(Flask): babel.localeselector(get_locale) user_store = SQLAlchemyUserDatastore(db, User, Role) - security.init_app(self, datastore=user_store) + security.init_app(self, datastore=user_store, anonymous_user=AnonymousUser) self.context_processor(template_vars) diff --git a/calsocial/security.py b/calsocial/security.py index 39bd35b..2fcdcbf 100644 --- a/calsocial/security.py +++ b/calsocial/security.py @@ -17,6 +17,18 @@ """Security related things for Calendar.social """ -from flask_security import Security +from flask_security import Security, AnonymousUser as BaseAnonymousUser security = Security() + + +class AnonymousUser(BaseAnonymousUser): + """Anonymous user class for Calendar.social + """ + + @property + def timezone(self): + """The time zone of the anonymous user + """ + + return None