From bbf7cb5685086578b6f27b8ed066c3cb49f1036f Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sat, 15 Aug 2009 11:35:54 +0000 Subject: [PATCH] show captcha validation only for anonymous users. svn path=/plone.app.discussion/trunk/; revision=28902 --- plone/app/discussion/browser/captcha.py | 6 +++++- plone/app/discussion/browser/comments.py | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plone/app/discussion/browser/captcha.py b/plone/app/discussion/browser/captcha.py index 666dd2e..6baa87b 100644 --- a/plone/app/discussion/browser/captcha.py +++ b/plone/app/discussion/browser/captcha.py @@ -1,5 +1,7 @@ from persistent import Persistent +from Products.CMFCore.utils import getToolByName + from z3c.form import validator from z3c.form.field import Fields @@ -59,9 +61,11 @@ if HAS_CAPTCHA or HAS_RECAPTCHA: registry = queryUtility(IRegistry) settings = registry.forInterface(IDiscussionSettings) self.captcha = settings.captcha + portal_membership = getToolByName(self.context, 'portal_membership') + self.isAnon = portal_membership.isAnonymousUser() def update(self): - if self.captcha != 'disabled': + if self.captcha != 'disabled' and self.isAnon: # Add captcha field if captcha is enabled in the registry self.add(ICaptcha, prefix="") if HAS_CAPTCHA and self.captcha == 'captcha': diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index ea2de18..3370154 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -79,9 +79,11 @@ class CommentForm(extensible.ExtensibleForm, form.Form): def handleComment(self, action): data, errors = self.extractData() + # Captcha check (only when captcha is enabled and user is anonymous) registry = queryUtility(IRegistry) settings = registry.forInterface(IDiscussionSettings) - if settings.captcha != 'disabled': + portal_membership = getToolByName(self.context, 'portal_membership') + if settings.captcha != 'disabled' and portal_membership.isAnonymousUser(): # Check captcha only if it is not disabled if data.has_key('captcha'): # Check captcha only if there is a value, otherwise