--- a/src/pyams_content/shared/form/zmi/properties.py Mon Sep 16 16:57:01 2019 +0200
+++ b/src/pyams_content/shared/form/zmi/properties.py Tue Sep 17 12:03:03 2019 +0200
@@ -9,10 +9,11 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
-
+from pyramid.events import subscriber
from z3c.form import field
from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget
-from zope.interface import Interface
+from z3c.form.interfaces import IDataExtractedEvent, INPUT_MODE
+from zope.interface import Interface, Invalid
from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
from pyams_content.shared.common.zmi.properties import SharedContentPropertiesEditForm
@@ -58,11 +59,32 @@
fields = field.Fields(IWfForm).select('form_header', 'user_title', 'auth_only',
'submit_label', 'submit_message', 'handler',
'use_captcha', 'client_captcha_key',
- 'server_captcha_key', 'captcha_proxy')
+ 'server_captcha_key', 'captcha_proxy',
+ 'rgpd_consent', 'rgpd_warning', 'rgpd_user_rights')
fields['use_captcha'].widgetFactory = SingleCheckBoxFieldWidget
+ fields['rgpd_consent'].widgetFactory = SingleCheckBoxFieldWidget
weight = 1
+ def updateWidgets(self, prefix=None):
+ super(FormPropertiesInnerEditForm, self).updateWidgets(prefix)
+ if self.mode == INPUT_MODE:
+ translate = self.request.localizer.translate
+ if 'rgpd_warning' in self.widgets:
+ self.widgets['rgpd_warning'].after_widget_notice = \
+ '<div class="alert-info padding-5">{0}</div>'.format(
+ translate(_("Text samples:<br />"
+ "- By submitting this form, I agree that the information "
+ "entered may be used for the purpose of my request and the "
+ "business relationship that may result from it.")))
+ if 'rgpd_user_rights' in self.widgets:
+ self.widgets['rgpd_user_rights'].after_widget_notice = \
+ '<div class="alert-info padding-5">{0}</div>'.format(
+ translate(_("Text samples:<br />"
+ "- To know and enforce your rights, including the right to "
+ "withdraw your consent to the use of the data collected by "
+ "this form, please consult our privacy policy.")))
+
def updateGroups(self):
self.add_group(NamedWidgetsGroup(self, 'head', self.widgets,
('form_header', 'user_title', 'auth_only',
@@ -76,6 +98,14 @@
switch=True,
checkbox_switch=True,
checkbox_field=IWfForm['use_captcha']))
+ self.add_group(NamedWidgetsGroup(self, 'rgpd', self.widgets,
+ ('rgpd_consent', 'rgpd_warning', 'rgpd_user_rights'),
+ fieldset_class='inner bordered',
+ legend=_("Add RGPD warning"),
+ css_class='inner',
+ switch=True,
+ checkbox_switch=True,
+ checkbox_field=IWfForm['rgpd_consent']))
super(FormPropertiesInnerEditForm, self).updateGroups()
def get_ajax_output(self, changes):
@@ -88,6 +118,23 @@
return super(FormPropertiesInnerEditForm, self).get_ajax_output(changes)
+@subscriber(IDataExtractedEvent, form_selector=FormPropertiesInnerEditForm)
+def check_form_properties_data(event):
+ """Check form properties input data"""
+ data = event.data
+ if data.get('rgpd_consent'):
+ for attr in ('rgpd_warning', 'rgpd_user_rights'):
+ attr_ok = False
+ for lang, value in data.get(attr, {}).items():
+ if value:
+ attr_ok = True
+ break
+ if not attr_ok:
+ event.form.widgets.errors += (Invalid(_("You MUST set an RGPD consent text and "
+ "RGPD user rights to enable RGPD!")),)
+ return
+
+
@adapter_config(name='handler-settings',
context=(IWfForm, IPyAMSLayer, SharedContentPropertiesEditForm),
provides=IInnerSubForm)