From a09d969dba530e9867fe6502d5a566c2b82a8324 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 5 Feb 2024 12:25:02 +0100 Subject: [PATCH] add terms and conditions for admin too --- idhub/admin/forms.py | 61 ++++++++++++++++++- idhub/admin/views.py | 9 ++- idhub/templates/auth/2fadmin.html | 4 +- idhub/templates/auth/2fadmin_email.html | 2 +- idhub/templates/auth/2fadmin_email.txt | 2 +- .../idhub/admin/terms_conditions.html | 56 +++++++++++++---- idhub/templates/idhub/base.html | 7 ++- .../idhub/user/terms_conditions.html | 44 ++++++++++++- idhub/user/forms.py | 2 +- idhub/user/views.py | 4 +- 10 files changed, 164 insertions(+), 27 deletions(-) diff --git a/idhub/admin/forms.py b/idhub/admin/forms.py index b8fcec4..1895195 100644 --- a/idhub/admin/forms.py +++ b/idhub/admin/forms.py @@ -23,7 +23,7 @@ from idhub.models import ( from idhub_auth.models import User -class TermsConditionsForm(forms.Form): +class TermsConditionsForm2(forms.Form): accept = forms.BooleanField( label=_("Accept terms and conditions of the service"), required=False @@ -50,6 +50,65 @@ class TermsConditionsForm(forms.Form): return +class TermsConditionsForm(forms.Form): + accept_privacy = forms.BooleanField( + widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}), + required=False + ) + accept_legal = forms.BooleanField( + widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}), + required=False + ) + accept_cookies = forms.BooleanField( + widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}), + required=False + ) + + def __init__(self, *args, **kwargs): + self.user = kwargs.pop('user', None) + super().__init__(*args, **kwargs) + + def get_label(self, url, read): + label = _('I read and accepted the') + label += f' {read}' + return label + + def privacy_label(self): + url = "https://laweb.pangea.org/politica-de-privacitat/" + read = _("Read privacy policy") + return self.get_label(url, read) + + def legal_label(self): + url = "https://laweb.pangea.org/avis-legal/" + read = _("Read legal policy") + return self.get_label(url, read) + + def cookies_label(self): + url = "https://laweb.pangea.org/politica-de-cookies-2/" + read = _("Read cookies policy") + return self.get_label(url, read) + + def clean(self): + data = self.cleaned_data + privacy = data.get("accept_privacy") + legal = data.get("accept_legal") + cookies = data.get("accept_cookies") + if privacy and legal and cookies: + self.user.accept_gdpr = True + else: + self.user.accept_gdpr = False + return data + + def save(self, commit=True): + + if commit: + self.user.save() + return self.user + + return + + class ImportForm(forms.Form): did = forms.ChoiceField(label=_("Did"), choices=[]) eidas1 = forms.ChoiceField( diff --git a/idhub/admin/views.py b/idhub/admin/views.py index 31a9994..f680698 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -60,7 +60,7 @@ from idhub.models import ( class TermsAndConditionsView(AdminView, FormView): template_name = "idhub/admin/terms_conditions.html" - title = _("GDPR") + title = _('Data protection') section = "" subtitle = _('Terms and Conditions') icon = 'bi bi-file-earmark-medical' @@ -70,7 +70,12 @@ class TermsAndConditionsView(AdminView, FormView): def get_form_kwargs(self): kwargs = super().get_form_kwargs() kwargs['user'] = self.request.user - kwargs['initial'] = {"accept": self.request.user.accept_gdpr} + if self.request.user.accept_gdpr: + kwargs['initial'] = { + "accept_privacy": True, + "accept_legal": True, + "accept_cookies": True + } return kwargs def form_valid(self, form): diff --git a/idhub/templates/auth/2fadmin.html b/idhub/templates/auth/2fadmin.html index 4dc2ae6..e96d1b7 100644 --- a/idhub/templates/auth/2fadmin.html +++ b/idhub/templates/auth/2fadmin.html @@ -5,14 +5,14 @@
-

{% trans 'Doble Factor of Authentication' %}

+

{% trans 'Two-factor Authentication' %}

- {% trans "We have sent an email with a link that you have to select in order to login." %} + {% trans "We have sent you an email with a link that you have to click to log in." %}
diff --git a/idhub/templates/auth/2fadmin_email.html b/idhub/templates/auth/2fadmin_email.html index d2253c5..6ea0793 100644 --- a/idhub/templates/auth/2fadmin_email.html +++ b/idhub/templates/auth/2fadmin_email.html @@ -1,6 +1,6 @@ {% load i18n %}{% autoescape off %}

-{% blocktrans %}You're receiving this email because you try to access in {{ site_name }}.{% endblocktrans %} +{% blocktrans %}You're receiving this email because you tried to access {{ site_name }}.{% endblocktrans %}

diff --git a/idhub/templates/auth/2fadmin_email.txt b/idhub/templates/auth/2fadmin_email.txt index a9ef3e5..6328f66 100644 --- a/idhub/templates/auth/2fadmin_email.txt +++ b/idhub/templates/auth/2fadmin_email.txt @@ -1,5 +1,5 @@ {% load i18n %}{% autoescape off %} -{% blocktrans %}You're receiving this email because you try to access in {{ site_name }}.{% endblocktrans %} +{% blocktrans %}You're receiving this email because you tried to access {{ site_name }}.{% endblocktrans %} {% trans "Please go to the following page" %} {% block reset_link %} diff --git a/idhub/templates/idhub/admin/terms_conditions.html b/idhub/templates/idhub/admin/terms_conditions.html index 51f8b6c..c73f953 100644 --- a/idhub/templates/idhub/admin/terms_conditions.html +++ b/idhub/templates/idhub/admin/terms_conditions.html @@ -20,38 +20,68 @@ {% endif %} -

+ +
- You must read the terms and conditions of this service and accept the - Read GDPR + {{ form.accept_privacy }} + {{ form.privacy_label|safe }}
-
-
- {% bootstrap_form form %} +
+
+ {{ form.accept_legal }} + {{ form.legal_label|safe }}
-
- {% translate "Cancel" %} - +
+
+ {{ form.accept_cookies }} + {{ form.cookies_label|safe }} +
+
+ - + +{% endblock %} + +{% block extrascript %} + {% endblock %} diff --git a/idhub/templates/idhub/base.html b/idhub/templates/idhub/base.html index e579a81..c2524ad 100644 --- a/idhub/templates/idhub/base.html +++ b/idhub/templates/idhub/base.html @@ -88,7 +88,7 @@ @@ -150,9 +150,12 @@
+ {% block script %} + - + {% block extrascript %}{% endblock %} + {% endblock %} diff --git a/idhub/templates/idhub/user/terms_conditions.html b/idhub/templates/idhub/user/terms_conditions.html index f021b4d..4175a60 100644 --- a/idhub/templates/idhub/user/terms_conditions.html +++ b/idhub/templates/idhub/user/terms_conditions.html @@ -39,9 +39,49 @@
- {% translate "Cancel" %} - + {% trans 'Confirm' %}
+ + {% endblock %} + +{% block extrascript %} + +{% endblock %} diff --git a/idhub/user/forms.py b/idhub/user/forms.py index 0c16171..79e3d17 100644 --- a/idhub/user/forms.py +++ b/idhub/user/forms.py @@ -33,7 +33,7 @@ class TermsConditionsForm(forms.Form): super().__init__(*args, **kwargs) def get_label(self, url, read): - label = _('You must read the terms and conditions of this service and accept the') + label = _('I read and accepted the') label += f' {read}' return label diff --git a/idhub/user/views.py b/idhub/user/views.py index fcd622d..27c8f77 100644 --- a/idhub/user/views.py +++ b/idhub/user/views.py @@ -123,7 +123,7 @@ class RolesView(MyProfile, SingleTableView): class GDPRView(MyProfile, TemplateView): template_name = "idhub/user/gdpr.html" - subtitle = _('GDPR info') + subtitle = _('Data protection') icon = 'bi bi-file-earmark-medical' @@ -142,7 +142,7 @@ class CredentialsView(MyWallet, SingleTableView): class TermsAndConditionsView(UserView, FormView): template_name = "idhub/user/terms_conditions.html" - title = _("GDPR") + title = _("Data Protection") section = "" subtitle = _('Terms and Conditions') icon = 'bi bi-file-earmark-medical'