From fd74d2f7c1f1a2a5263cf0a5c16c80e51f94054f Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 3 Nov 2014 16:37:00 +0100 Subject: [PATCH] Add username to cache key in datasource renderer if OAuth2 is used (fixes #5849) --- README | 3 +++ src/cmsplugin_blurp/renderers/data_source.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/README b/README index 0ef3956..7bb31fa 100644 --- a/README +++ b/README @@ -162,6 +162,9 @@ A source definition is a dictionnary containing the following keys: as keyword arguments to the `reader()` or `DictReader()` constructors, depending on whether the `fieldnames` arguments is present, + - `user_context`, whether the user must be part of the cache key. For retro + compatibility If authentication mechanism is OAuth2, it defaults to True + otherwise to False. Exemple with the JSON parser ---------------------------- diff --git a/src/cmsplugin_blurp/renderers/data_source.py b/src/cmsplugin_blurp/renderers/data_source.py index 155dda6..7c67962 100644 --- a/src/cmsplugin_blurp/renderers/data_source.py +++ b/src/cmsplugin_blurp/renderers/data_source.py @@ -141,9 +141,14 @@ class Data(object): self.signature_key = source.get('signature_key') self.parser_type = source.get('parser_type', 'raw') self.content_type = source.get('content_type', self.MAPPING[self.parser_type]) + self.user_context = source.get('user_context', + config.get('user_context', self.auth_mech == 'oauth2')) pre_hash = 'datasource-{self.slug}-{self.url}-{self.limit}-' \ '{self.refresh}-{self.auth_mech}-{self.signature_key}' \ .format(self=self) + # If authentication is used + if self.user_context: + pre_hash += '-%s' % unicode(self.request.user).encode('utf-8') self.key = hashlib.md5(pre_hash).hexdigest() self.now = time.time() self.__content = self.__CACHE_SENTINEL