From e509d3bc2ba4d4437391ba4063e68db7e9dff1ee Mon Sep 17 00:00:00 2001 From: Carlos de la Guardia Date: Wed, 23 Sep 2015 11:45:17 -0500 Subject: [PATCH 1/4] Fix like for authenticated users when anonymous voting is enabled The id of the current user would never be used if anonymous voting was enabled, throwing off the my vote calls. --- cioppino/twothumbs/browser/like.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/cioppino/twothumbs/browser/like.py b/cioppino/twothumbs/browser/like.py index cc14bf1..7e29210 100644 --- a/cioppino/twothumbs/browser/like.py +++ b/cioppino/twothumbs/browser/like.py @@ -62,16 +62,18 @@ class LikeThisShizzleView(BrowserView): def __call__(self, REQUEST, RESPONSE): registry = getUtility(IRegistry) anonuid = None - if not registry.get('cioppino.twothumbs.anonymousvoting', False): - # First check if the user is allowed to rate - portal_state = getMultiAdapter((self.context, self.request), - name='plone_portal_state') - if portal_state.anonymous(): - return RESPONSE.redirect('%s/login?came_from=%s' % - (portal_state.portal_url(), - REQUEST['HTTP_REFERER']) - ) - else: + anonymous_voting = registry.get('cioppino.twothumbs.anonymousvoting', False) + portal_state = getMultiAdapter((self.context, self.request), + name='plone_portal_state') + + + if not anonymous_voting and portal_state.anonymous(): + return RESPONSE.redirect('%s/login?came_from=%s' % + (portal_state.portal_url(), + REQUEST['HTTP_REFERER']) + ) + + if anonymous_voting and portal_state.anonymous(): anonuid = self.request.cookies.get(COOKIENAME, None) if anonuid is None: anonuid = str(uuid4()) From 04db0dccb37d674c6c23e6493ee4ae9dae15ba8b Mon Sep 17 00:00:00 2001 From: Carlos de la Guardia Date: Wed, 23 Sep 2015 12:23:09 -0500 Subject: [PATCH 2/4] White space fixes are the best (not) --- cioppino/twothumbs/browser/like.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cioppino/twothumbs/browser/like.py b/cioppino/twothumbs/browser/like.py index 7e29210..709ff4c 100644 --- a/cioppino/twothumbs/browser/like.py +++ b/cioppino/twothumbs/browser/like.py @@ -66,13 +66,12 @@ def __call__(self, REQUEST, RESPONSE): portal_state = getMultiAdapter((self.context, self.request), name='plone_portal_state') - - if not anonymous_voting and portal_state.anonymous(): + if not anonymous_voting and portal_state.anonymous(): return RESPONSE.redirect('%s/login?came_from=%s' % (portal_state.portal_url(), REQUEST['HTTP_REFERER']) ) - + if anonymous_voting and portal_state.anonymous(): anonuid = self.request.cookies.get(COOKIENAME, None) if anonuid is None: From 110b59a9efc101665bb62cfb998dd2e803a4d2dc Mon Sep 17 00:00:00 2001 From: Carlos de la Guardia Date: Wed, 23 Sep 2015 12:43:40 -0500 Subject: [PATCH 3/4] Clean it up a bit. --- cioppino/twothumbs/browser/like.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/cioppino/twothumbs/browser/like.py b/cioppino/twothumbs/browser/like.py index 709ff4c..fc90acb 100644 --- a/cioppino/twothumbs/browser/like.py +++ b/cioppino/twothumbs/browser/like.py @@ -66,17 +66,17 @@ def __call__(self, REQUEST, RESPONSE): portal_state = getMultiAdapter((self.context, self.request), name='plone_portal_state') - if not anonymous_voting and portal_state.anonymous(): - return RESPONSE.redirect('%s/login?came_from=%s' % - (portal_state.portal_url(), - REQUEST['HTTP_REFERER']) - ) - - if anonymous_voting and portal_state.anonymous(): - anonuid = self.request.cookies.get(COOKIENAME, None) - if anonuid is None: - anonuid = str(uuid4()) - RESPONSE.setCookie(COOKIENAME, anonuid) + if portal_state.anonymous(): + if not anonymous_voting: + return RESPONSE.redirect('%s/login?came_from=%s' % + (portal_state.portal_url(), + REQUEST['HTTP_REFERER']) + ) + else: + anonuid = self.request.cookies.get(COOKIENAME, None) + if anonuid is None: + anonuid = str(uuid4()) + RESPONSE.setCookie(COOKIENAME, anonuid) form = self.request.form action = None From 0311e356b9118301498fbf997e4378d40c8e2721 Mon Sep 17 00:00:00 2001 From: Carlos de la Guardia Date: Wed, 23 Sep 2015 12:54:04 -0500 Subject: [PATCH 4/4] Update change log --- docs/HISTORY.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/HISTORY.rst b/docs/HISTORY.rst index fb18eb0..0fbd821 100644 --- a/docs/HISTORY.rst +++ b/docs/HISTORY.rst @@ -6,6 +6,8 @@ Changelog - HTML render fixes. [andreasma] +- Fix bug in like view that prevented authenticated user id from being used + in votes when anonymous voting was enabled [cguardia] 1.8 (2014-11-07)