From 1b3bcdbdbad0f38a384bd142a2cb69b641cfbd52 Mon Sep 17 00:00:00 2001 From: ksuess Date: Thu, 21 Mar 2024 15:05:59 +0100 Subject: [PATCH] [fc] Repository: plone.app.discussion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Branch: refs/heads/3.4.x Date: 2024-03-21T15:05:59+01:00 Author: Katja Süss (ksuess) Commit: https://github.com/plone/plone.app.discussion/commit/f3b50d753ffd5cd7da767b9d211bfe2d19360854 Apply validation for all captchas (version 3.4.x) (#233) Files changed: A news/233.bugfix M plone/app/discussion/browser/validator.py --- last_commit.txt | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/last_commit.txt b/last_commit.txt index 77134584e2..80e577e00b 100644 --- a/last_commit.txt +++ b/last_commit.txt @@ -2,20 +2,15 @@ Repository: plone.app.discussion Branch: refs/heads/3.4.x -Date: 2024-03-18T12:00:02+01:00 +Date: 2024-03-21T15:05:59+01:00 Author: Katja Süss (ksuess) -Commit: https://github.com/plone/plone.app.discussion/commit/f610d19f4fcf483c4b9d1ee0d0805dbd2cd77915 +Commit: https://github.com/plone/plone.app.discussion/commit/f3b50d753ffd5cd7da767b9d211bfe2d19360854 -Support for HCaptcha via plone.formwidget.hcaptcha in plone.app.discussion 3.4.x (#229) +Apply validation for all captchas (version 3.4.x) (#233) Files changed: -A news/230.feature -M README.rst -M plone/app/discussion/browser/captcha.py +A news/233.bugfix M plone/app/discussion/browser/validator.py -M plone/app/discussion/configure.zcml -M plone/app/discussion/interfaces.py -M plone/app/discussion/vocabularies.py -b'diff --git a/README.rst b/README.rst\nindex 352ae6bf..bf596aed 100644\n--- a/README.rst\n+++ b/README.rst\n@@ -105,6 +105,10 @@ Add-on Products\n `_\n (provides a "human" captcha widget based on a list of questions/answers)\n \n+- `plone.formwidget.hcaptcha\n+ `_\n+ (for spam protection by `HCaptcha `_ )\n+\n \n Documentation\n =============\ndiff --git a/news/230.feature b/news/230.feature\nnew file mode 100644\nindex 00000000..72cc6f78\n--- /dev/null\n+++ b/news/230.feature\n@@ -0,0 +1 @@\n+Provide HCaptcha if plone.formwidget.hcaptcha is installed. @ksuess\n\\ No newline at end of file\ndiff --git a/plone/app/discussion/browser/captcha.py b/plone/app/discussion/browser/captcha.py\nindex 090fce95..34c7b61d 100644\n--- a/plone/app/discussion/browser/captcha.py\n+++ b/plone/app/discussion/browser/captcha.py\n@@ -61,6 +61,10 @@ def update(self):\n from plone.formwidget.recaptcha import ReCaptchaFieldWidget\n self.form.fields[\'captcha\'].widgetFactory = \\\n ReCaptchaFieldWidget\n+ elif self.captcha == "hcaptcha":\n+ from plone.formwidget.hcaptcha import HCaptchaFieldWidget\n+\n+ self.form.fields["captcha"].widgetFactory = HCaptchaFieldWidget\n elif self.captcha == \'norobots\':\n from collective.z3cform.norobots import NorobotsFieldWidget\n self.form.fields[\'captcha\'].widgetFactory = NorobotsFieldWidget\ndiff --git a/plone/app/discussion/browser/validator.py b/plone/app/discussion/browser/validator.py\nindex d1582e9a..360616b7 100644\n--- a/plone/app/discussion/browser/validator.py\n+++ b/plone/app/discussion/browser/validator.py\n@@ -31,6 +31,11 @@\n except ImportError:\n pass\n \n+try:\n+ from plone.formwidget.hcaptcha.validator import WrongCaptchaCode # noqa\n+except ImportError:\n+ pass\n+\n \n @implementer(IValidator)\n @adapter(Interface, IDiscussionLayer, Interface, IField, Interface)\ndiff --git a/plone/app/discussion/configure.zcml b/plone/app/discussion/configure.zcml\nindex aabd851d..e4e3147d 100644\n--- a/plone/app/discussion/configure.zcml\n+++ b/plone/app/discussion/configure.zcml\n@@ -27,6 +27,9 @@\n \n \n \n+ \n+ \n+ \n \n \n \ndiff --git a/plone/app/discussion/interfaces.py b/plone/app/discussion/interfaces.py\nindex 76a0cee5..f8cac445 100644\n--- a/plone/app/discussion/interfaces.py\n+++ b/plone/app/discussion/interfaces.py\n@@ -315,7 +315,9 @@ class IDiscussionSettings(Interface):\n default=u\'Use this setting to enable or disable Captcha \'\n u\'validation for comments. Install \'\n u\'plone.formwidget.captcha, \'\n- u\'plone.formwidget.recaptcha, collective.akismet, or \'\n+ u\'plone.formwidget.recaptcha, \'\n+ u\'plone.formwidget.hcaptcha, \'\n+ u\'collective.akismet, or \'\n u\'collective.z3cform.norobots if there are no options \'\n u\'available.\'),\n required=True,\ndiff --git a/plone/app/discussion/vocabularies.py b/plone/app/discussion/vocabularies.py\nindex b1588667..bfe93e03 100644\n--- a/plone/app/discussion/vocabularies.py\n+++ b/plone/app/discussion/vocabularies.py\n@@ -18,6 +18,14 @@\n except ImportError:\n pass\n \n+HAS_HCAPTCHA = False\n+try:\n+ import plone.formwidget.hcaptcha # noqa\n+\n+ HAS_HCAPTCHA = True # pragma: no cover\n+except ImportError:\n+ pass\n+\n HAS_AKISMET = False\n try:\n import collective.akismet # noqa\n@@ -57,6 +65,13 @@ def captcha_vocabulary(context):\n token=\'recaptcha\',\n title=\'ReCaptcha\'))\n \n+ if HAS_HCAPTCHA: # pragma: no cover\n+ terms.append(\n+ SimpleTerm(\n+ value="hcaptcha",\n+ token="hcaptcha",\n+ title="HCaptcha"))\n+\n if HAS_AKISMET: # pragma: no cover\n terms.append(\n SimpleTerm(\n' +b"diff --git a/news/233.bugfix b/news/233.bugfix\nnew file mode 100644\nindex 00000000..8bfc3559\n--- /dev/null\n+++ b/news/233.bugfix\n@@ -0,0 +1 @@\n+Apply validation for all captchas. @ksuess\n\\ No newline at end of file\ndiff --git a/plone/app/discussion/browser/validator.py b/plone/app/discussion/browser/validator.py\nindex 360616b7..dce3c52b 100644\n--- a/plone/app/discussion/browser/validator.py\n+++ b/plone/app/discussion/browser/validator.py\n@@ -49,7 +49,7 @@ def validate(self, value):\n registry = queryUtility(IRegistry)\n settings = registry.forInterface(IDiscussionSettings, check=False)\n \n- if settings.captcha in ('captcha', 'recaptcha', 'norobots'):\n+ if settings.captcha != 'disabled':\n captcha = getMultiAdapter((aq_inner(self.context), self.request),\n name=settings.captcha)\n if not captcha.verify(input=value):\n"