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