add terms and conditions for admin too

This commit is contained in:
Cayo Puigdefabregas 2024-02-05 12:25:02 +01:00
parent 2d4273032c
commit a09d969dba
10 changed files with 164 additions and 27 deletions

View File

@ -23,7 +23,7 @@ from idhub.models import (
from idhub_auth.models import User from idhub_auth.models import User
class TermsConditionsForm(forms.Form): class TermsConditionsForm2(forms.Form):
accept = forms.BooleanField( accept = forms.BooleanField(
label=_("Accept terms and conditions of the service"), label=_("Accept terms and conditions of the service"),
required=False required=False
@ -50,6 +50,65 @@ class TermsConditionsForm(forms.Form):
return 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' <a class="btn btn-green-admin" target="_blank" href="{url}" '
label += f'title="{read}">{read}</a>'
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): class ImportForm(forms.Form):
did = forms.ChoiceField(label=_("Did"), choices=[]) did = forms.ChoiceField(label=_("Did"), choices=[])
eidas1 = forms.ChoiceField( eidas1 = forms.ChoiceField(

View File

@ -60,7 +60,7 @@ from idhub.models import (
class TermsAndConditionsView(AdminView, FormView): class TermsAndConditionsView(AdminView, FormView):
template_name = "idhub/admin/terms_conditions.html" template_name = "idhub/admin/terms_conditions.html"
title = _("GDPR") title = _('Data protection')
section = "" section = ""
subtitle = _('Terms and Conditions') subtitle = _('Terms and Conditions')
icon = 'bi bi-file-earmark-medical' icon = 'bi bi-file-earmark-medical'
@ -70,7 +70,12 @@ class TermsAndConditionsView(AdminView, FormView):
def get_form_kwargs(self): def get_form_kwargs(self):
kwargs = super().get_form_kwargs() kwargs = super().get_form_kwargs()
kwargs['user'] = self.request.user 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 return kwargs
def form_valid(self, form): def form_valid(self, form):

View File

@ -5,14 +5,14 @@
<div class="well"> <div class="well">
<div class="row-fluid"> <div class="row-fluid">
<h2>{% trans 'Doble Factor of Authentication' %}</h2> <h2>{% trans 'Two-factor Authentication' %}</h2>
</div> </div>
</div> </div>
<div class="well"> <div class="well">
<div class="row-fluid"> <div class="row-fluid">
<div> <div>
<span>{% trans "We have sent an email with a link that you have to select in order to login." %}</span> <span>{% trans "We have sent you an email with a link that you have to click to log in." %}</span>
</div> </div>
</div><!-- /.row-fluid --> </div><!-- /.row-fluid -->
</div><!--/.well--> </div><!--/.well-->

View File

@ -1,6 +1,6 @@
{% load i18n %}{% autoescape off %} {% load i18n %}{% autoescape off %}
<p> <p>
{% 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 %}
</p> </p>
<p> <p>

View File

@ -1,5 +1,5 @@
{% load i18n %}{% autoescape off %} {% 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" %} {% trans "Please go to the following page" %}
{% block reset_link %} {% block reset_link %}

View File

@ -20,38 +20,68 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
<div class="row">
<div class="row mt-4">
<div class="col"> <div class="col">
You must read the terms and conditions of this service and accept the {{ form.accept_privacy }}
<a class="btn btn-green-admin" href="jacascript:void()" data-bs-toggle="modal" data-bs-target="#gdpr" title="{% trans 'GDPR' %}">Read GDPR</a> {{ form.privacy_label|safe }}
</div> </div>
</div> </div>
<div class="row"> <div class="row mt-2">
<div class="col-sm-4"> <div class="col">
{% bootstrap_form form %} {{ form.accept_legal }}
{{ form.legal_label|safe }}
</div> </div>
</div> </div>
<div class="form-actions-no-box"> <div class="row mt-2">
<a class="btn btn-grey" href="{% url 'idhub:admin_dashboard' %}">{% translate "Cancel" %}</a> <div class="col">
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" /> {{ form.accept_cookies }}
{{ form.cookies_label|safe }}
</div>
</div>
<div class="form-actions-no-box mt-4">
<a href="javascript:accepts();" type="button" class="btn btn-green-admin">{% trans 'Confirm' %}</a>
</div> </div>
</form>
<!-- Modal --> <!-- Modal -->
<div class="modal" id="gdpr" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal" id="gdpr" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">{% trans 'GDPR info' %}</h5> <h5 class="modal-title" id="exampleModalLabel">{% trans 'Data protection' %}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p>Here we write the info about GDPR</p> {% blocktrans %}
<p>If you do not consent to all terms and conditons this service may not be available to
anyone in your organization.<br /><br />
If you are sure to opt out of using this service please contact <a href="mailto:suport@pangea.org">suport@pangea.org</a> to unsubscribe. If you wish to continue, you must consent to all terms and conditions.</p>
{% endblocktrans %}
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans 'Close' %}</button> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans 'No' %}</button>
<input id="submit" class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Yes' %}" />
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</form>
{% endblock %}
{% block extrascript %}
<script>
$(document).ready(function() {
});
function accepts() {
var privacy = $("#id_accept_privacy").prop("checked");
var policy = $("#id_accept_legal").prop("checked");
var cookies = $("#id_accept_cookies").prop("checked");
if (privacy && policy && cookies) {
$("#submit").trigger("click");
} else {
$("#gdpr").modal("show");
}
}
</script>
{% endblock %} {% endblock %}

View File

@ -88,7 +88,7 @@
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link {% if path == 'user_gdpr' %}active2{% endif %}" href="{% url 'idhub:user_gdpr' %}"> <a class="nav-link {% if path == 'user_gdpr' %}active2{% endif %}" href="{% url 'idhub:user_gdpr' %}">
{% trans 'GDPR info' %} {% trans 'Data protection' %}
</a> </a>
</li> </li>
</ul> </ul>
@ -150,9 +150,12 @@
</div> </div>
</div> </div>
{% block script %}
<script src="{% static "js/jquery-3.3.1.slim.min.js" %}"></script>
<script src="/static/js/bootstrap.bundle.min.js"></script> <script src="/static/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js" integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js" integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" integrity="sha384-zNy6FEbO50N+Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" integrity="sha384-zNy6FEbO50N+Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" crossorigin="anonymous"></script>
<script src="/static/js/dashboard.js"></script> {% block extrascript %}{% endblock %}
{% endblock %}
</body> </body>
</html> </html>

View File

@ -39,9 +39,49 @@
</div> </div>
</div> </div>
<div class="form-actions-no-box mt-4"> <div class="form-actions-no-box mt-4">
<a class="btn btn-grey" href="{% url 'idhub:user_dashboard' %}">{% translate "Cancel" %}</a> <a href="javascript:accepts();" type="button" class="btn btn-green-user">{% trans 'Confirm' %}</a>
<input class="btn btn-green-user" type="submit" name="submit" value="{% translate 'Save' %}" />
</div> </div>
<!-- Modal -->
<div class="modal" id="gdpr" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">{% trans 'Data protection' %}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{% blocktrans %}
<p>If you do not accept all the terms and conditions of this service you will not be able
to continue.
<br /><br />
Are you sure to opt out of using this service?</p>
{% endblocktrans %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans 'No' %}</button>
<input id="submit" class="btn btn-green-user" type="submit" name="submit" value="{% translate 'Yes' %}" />
</div>
</div>
</div>
</div>
</form> </form>
{% endblock %} {% endblock %}
{% block extrascript %}
<script>
$(document).ready(function() {
});
function accepts() {
var privacy = $("#id_accept_privacy").prop("checked");
var policy = $("#id_accept_legal").prop("checked");
var cookies = $("#id_accept_cookies").prop("checked");
if (privacy && policy && cookies) {
$("#submit").trigger("click");
} else {
$("#gdpr").modal("show");
}
}
</script>
{% endblock %}

View File

@ -33,7 +33,7 @@ class TermsConditionsForm(forms.Form):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def get_label(self, url, read): 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' <a class="btn btn-green-user" target="_blank" href="{url}" ' label += f' <a class="btn btn-green-user" target="_blank" href="{url}" '
label += f'title="{read}">{read}</a>' label += f'title="{read}">{read}</a>'
return label return label

View File

@ -123,7 +123,7 @@ class RolesView(MyProfile, SingleTableView):
class GDPRView(MyProfile, TemplateView): class GDPRView(MyProfile, TemplateView):
template_name = "idhub/user/gdpr.html" template_name = "idhub/user/gdpr.html"
subtitle = _('GDPR info') subtitle = _('Data protection')
icon = 'bi bi-file-earmark-medical' icon = 'bi bi-file-earmark-medical'
@ -142,7 +142,7 @@ class CredentialsView(MyWallet, SingleTableView):
class TermsAndConditionsView(UserView, FormView): class TermsAndConditionsView(UserView, FormView):
template_name = "idhub/user/terms_conditions.html" template_name = "idhub/user/terms_conditions.html"
title = _("GDPR") title = _("Data Protection")
section = "" section = ""
subtitle = _('Terms and Conditions') subtitle = _('Terms and Conditions')
icon = 'bi bi-file-earmark-medical' icon = 'bi bi-file-earmark-medical'