Projet

Général

Profil

0003-matomo-dedicated-ihm-for-manual-configuration-19743.patch

Voir les différences:

Subject: [PATCH 3/4] matomo: dedicated ihm for manual configuration (#19743)

 hobo/matomo/__init__.py                       |   0
 hobo/matomo/forms.py                          |  29 +++++
 .../matomo/templates/hobo/matomo_disable.html |  20 ++++
 .../templates/hobo/matomo_enable_auto.html    |  20 ++++
 .../templates/hobo/matomo_enable_manual.html  |  20 ++++
 hobo/matomo/templates/hobo/matomo_home.html   |  84 ++++++++++++++
 hobo/matomo/urls.py                           |  26 +++++
 hobo/matomo/views.py                          | 105 ++++++++++++++++++
 hobo/settings.py                              |   1 +
 hobo/templates/hobo/home.html                 |   1 +
 hobo/urls.py                                  |   3 +
 11 files changed, 309 insertions(+)
 create mode 100644 hobo/matomo/__init__.py
 create mode 100644 hobo/matomo/forms.py
 create mode 100644 hobo/matomo/templates/hobo/matomo_disable.html
 create mode 100644 hobo/matomo/templates/hobo/matomo_enable_auto.html
 create mode 100644 hobo/matomo/templates/hobo/matomo_enable_manual.html
 create mode 100644 hobo/matomo/templates/hobo/matomo_home.html
 create mode 100644 hobo/matomo/urls.py
 create mode 100644 hobo/matomo/views.py
hobo/matomo/forms.py
1
# hobo - portal to configure and deploy applications
2
# Copyright (C) 2015-2019  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17
from django import forms
18
from django.utils.translation import ugettext_lazy as _
19

  
20

  
21
class SettingsForm(forms.Form):
22
    tracking_js = forms.CharField(
23
            label=_('Tracking Javascript'),
24
            help_text=_('See <a href="https://developer.matomo.org/guides/tracking-javascript-guide">'
25
                        'Matomo partners site</a> for getting your Javascript\'s tracking code.'),
26
            widget=forms.Textarea(attrs={'size': 1024}))
27

  
28
class EnableForm(forms.Form):
29
    pass
hobo/matomo/templates/hobo/matomo_disable.html
1
{% extends "hobo/matomo_home.html" %}
2
{% load i18n %}
3

  
4
{% block appbar %}
5
  <h2>Matomo</h2>
6
{% endblock %}
7

  
8
{% block content %}
9
<form method="post">
10
{% csrf_token %}
11
<p>
12
{% trans "Are you sure you want to disable Matomo support?" %}
13
{{ form.as_p }}
14
<div class="buttons">
15
<button class="submit-button">{% trans "Disable" %}</button>
16
<a class="cancel" href="{% url 'matomo-home' %}">{% trans "Cancel" %}</a>
17
</div>
18
</form>
19

  
20
{% endblock %}
hobo/matomo/templates/hobo/matomo_enable_auto.html
1
{% extends "hobo/matomo_home.html" %}
2
{% load i18n %}
3

  
4
{% block appbar %}
5
  <h2>Matomo</h2>
6
{% endblock %}
7

  
8
{% block content %}
9
<form method="post">
10
{% csrf_token %}
11
<p>
12
{% trans "Are you sure you want to enable Matomo automatic support?" %}
13
{{ form.as_p }}
14
<div class="buttons">
15
<button class="submit-button">{% trans "Enable" %}</button>
16
<a class="cancel" href="{% url 'matomo-home' %}">{% trans "Cancel" %}</a>
17
</div>
18
</form>
19

  
20
{% endblock %}
hobo/matomo/templates/hobo/matomo_enable_manual.html
1
{% extends "hobo/matomo_home.html" %}
2
{% load i18n %}
3

  
4
{% block appbar %}
5
  <h2>Matomo</h2>
6
{% endblock %}
7

  
8
{% block content %}
9
<form method="post">
10
{% csrf_token %}
11
<p>
12
{% trans "Are you sure you want to enable Matomo manual support?" %}
13
{{ form.as_p }}
14
<div class="buttons">
15
<button class="submit-button">{% trans "Enable" %}</button>
16
<a class="cancel" href="{% url 'matomo-home' %}">{% trans "Cancel" %}</a>
17
</div>
18
</form>
19

  
20
{% endblock %}
hobo/matomo/templates/hobo/matomo_home.html
1
{% extends "hobo/base.html" %}
2
{% load i18n %}
3

  
4
{% block breadcrumb %}
5
{{ block.super }}
6
<a href="{% url 'matomo-home' %}">Matomo</a>
7
{% endblock %}
8

  
9
{% block appbar %}
10
  <h2>{% trans 'Matomo' %}</h2>
11
  {% if enabled %}
12
  <span class="actions">
13
  <a rel="popup" href="{% url 'matomo-disable' %}">{% trans 'Disable' %}</a>
14
  </span>
15
  {% endif %}
16
{% endblock %}
17

  
18
{% block content %}
19

  
20
<div class="infonotice">
21
  {% blocktrans %}
22
  <p>
23
  Matomo is the tracker solution recommended by the National Commission for Data Protection and Liberties (<a href=https://www.cnil.fr/fr/solutions-pour-les-cookies-de-mesure-daudience>CNIL-France</a>).
24
  </p>
25
  <p>
26
  Les outils de mesures d’audience sont déployés afin d’obtenir des informations sur la navigation des visiteurs. Ils permettent notamment de comprendre comment les utilisateurs arrivent sur un site et de reconstituer leur parcours. Ces outils utilisent des technologies permettant de tracer les utilisateurs sur le site et d’associer un « referrer » ou une campagne à un identifiant unique.
27
  </p>
28
  L'outil Matomo requiert qu'un léger paramétrage pour être exempté de consentement en conformité avec la règlementation :
29
  <ul>
30
    <li>La non prorogation des cookies</li>
31
    <li>Anonymiser l’adresse IP</li>
32
    <li>Offrir une solution permettant de s’opposer au dépôt de cookie à des fins d’analytics</li>
33
  </ul>
34
  {% endblocktrans %}
35
</div>
36

  
37
{% if not enabled %}
38
<p>
39
 {% trans "Support is currently disabled." %}
40
</p>
41
<p>
42
  <a class="button" rel="popup" href="{% url 'matomo-enable-manual' %}">{% trans 'Manual' %}</a>
43
  <a class="button" rel="popup" href="{% url 'matomo-enable-auto' %}">{% trans 'Automatic' %}</a>
44
</p>
45
{% else %}
46

  
47
{% if cnil_ack_level == 'success' %}
48
<div class="successnotice">
49
  suivi des recommandations CNIL
50
</div>
51
{% elif cnil_ack_level == 'warning' %}
52
<div class="warningnotice">
53
  suivi des recommandations CNIL
54
</div>
55
{% elif cnil_ack_level == 'error' %}
56
<div class="errornotice">
57
  suivi des recommandations CNIL
58
</div>
59
{% endif %}
60

  
61
{% if mode == 'manual' %}
62
<p>
63
 {% trans "Manual mode." %}
64
</p>
65
{% endif %}
66

  
67
{% if mode == 'auto' %}
68
<p>
69
 {% trans "Automatic mode." %}
70
</p>
71
{% endif %}
72

  
73
<form method="post">
74
{% csrf_token %}
75
{{ form.as_p }}
76

  
77
<div class="buttons">
78
<button class="submit-button">{% trans "Save" %}</button>
79
</div>
80
</form>
81

  
82
{% endif %}
83

  
84
{% endblock %}
hobo/matomo/urls.py
1
# hobo - portal to configure and deploy applications
2
# Copyright (C) 2015-2019  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17
from django.conf.urls import url
18

  
19
from . import views
20

  
21
urlpatterns = [
22
    url(r'^$', views.home, name='matomo-home'),
23
    url(r'^enable-manual$', views.enable_manual, name='matomo-enable-manual'),
24
    url(r'^enable-auto$', views.enable_auto, name='matomo-enable-auto'),
25
    url(r'^disable$', views.disable, name='matomo-disable'),
26
]
hobo/matomo/views.py
1
# hobo - portal to configure and deploy applications
2
# Copyright (C) 2015-2019  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17
from django.core.urlresolvers import reverse_lazy
18
from django.views.generic import RedirectView, FormView
19

  
20
from .forms import SettingsForm, EnableForm
21
from .utils import get_variable, get_matomo_settings, \
22
     get_tenant_name_and_public_urls, auto_configure_matomo, \
23
     compute_cnil_acknowledgment_level
24

  
25

  
26
class HomeView(FormView):
27
    template_name = 'hobo/matomo_home.html'
28
    form_class = SettingsForm
29
    success_url = reverse_lazy('matomo-home')
30

  
31
    def get_initial(self):
32
        initial = super(HomeView, self).get_initial()
33
        initial['tracking_js'] = get_variable('cnil_compliant_visits_tracking_js').value
34
        return initial
35

  
36
    def form_valid(self, form):
37
        if get_variable('matomo_mode').json == 'manual':
38
            variable = get_variable('cnil_compliant_visits_tracking_js')
39
            variable.value = form.cleaned_data['tracking_js']
40
            variable.save()
41
        return super(HomeView, self).form_valid(form)
42

  
43
    def get_context_data(self, **kwargs):
44
        context = super(HomeView, self).get_context_data(**kwargs)
45
        context['enabled'] = bool(get_variable('matomo_enable').json)
46
        context['mode'] = get_variable('matomo_mode').json
47
        tracking_js = get_variable('cnil_compliant_visits_tracking_js').value
48
        context['cnil_ack_level'] = compute_cnil_acknowledgment_level(tracking_js)
49
        return context
50

  
51
home = HomeView.as_view()
52

  
53

  
54
class EnableManualView(FormView):
55
    form_class = EnableForm
56
    template_name = 'hobo/matomo_enable_manual.html'
57
    success_url = reverse_lazy('matomo-home')
58

  
59
    def form_valid(self, form):
60
        variable = get_variable('matomo_enable')
61
        variable.value = 'true'
62
        variable.save()
63
        variable = get_variable('matomo_mode')
64
        variable.value = 'manual'
65
        variable.save()
66
        return super(EnableManualView, self).form_valid(form)
67

  
68
enable_manual = EnableManualView.as_view()
69

  
70

  
71
class EnableAutoView(FormView):
72
    form_class = EnableForm
73
    template_name = 'hobo/matomo_enable_auto.html'
74
    success_url = reverse_lazy('matomo-home')
75

  
76
    def form_valid(self, form):
77
        variable = get_variable('matomo_enable')
78
        variable.value = 'true'
79
        variable.save()
80
        variable = get_variable('matomo_mode')
81
        variable.value = 'auto'
82
        variable.save()
83
        return super(EnableAutoView, self).form_valid(form)
84

  
85
enable_auto = EnableAutoView.as_view()
86

  
87

  
88
class DisableView(FormView):
89
    form_class = EnableForm
90
    template_name = 'hobo/matomo_disable.html'
91
    success_url = reverse_lazy('matomo-home')
92

  
93
    def form_valid(self, form):
94
        variable = get_variable('cnil_compliant_visits_tracking_js')
95
        variable.value = ''
96
        variable.save()
97
        variable = get_variable('matomo_enable')
98
        variable.value = 'false'
99
        variable.save()
100
        variable = get_variable('matomo_mode')
101
        variable.value = ''
102
        variable.save()
103
        return super(DisableView, self).form_valid(form)
104

  
105
disable = DisableView.as_view()
hobo/settings.py
41 41
    'gadjo',
42 42
    'hobo.environment',
43 43
    'hobo.franceconnect',
44
    'hobo.matomo',
44 45
    'hobo.profile',
45 46
    'hobo.theme',
46 47
    'hobo.emails',
hobo/templates/hobo/home.html
10 10
    <li><a href="{% url 'theme-home' %}">{% trans 'Theme' %}</a></li>
11 11
    <li><a href="{% url 'emails-home' %}">{% trans 'Emails' %}</a></li>
12 12
    <li><a href="{% url 'franceconnect-home' %}">FranceConnect</a></li>
13
    <li><a href="{% url 'matomo-home' %}">Matomo</a></li>
13 14
    <li><a href="{% url 'environment-home' %}">{% trans 'Services' %}</a></li>
14 15
    <li><a href="{% url 'environment-variables' %}">{% trans 'Variables' %}</a></li>
15 16
  </ul>
hobo/urls.py
8 8
from .urls_utils import decorated_includes
9 9
from .environment.urls import urlpatterns as environment_urls
10 10
from .franceconnect.urls import urlpatterns as franceconnect_urls
11
from .matomo.urls import urlpatterns as matomo_urls
11 12
from .profile.urls import urlpatterns as profile_urls
12 13
from .theme.urls import urlpatterns as theme_urls
13 14
from .emails.urls import urlpatterns as emails_urls
......
20 21
                                             include(profile_urls))),
21 22
    url(r'^franceconnect/',
22 23
        decorated_includes(admin_required, include(franceconnect_urls))),
24
    url(r'^matomo/',
25
        decorated_includes(admin_required, include(matomo_urls))),
23 26
    url(r'^theme/', decorated_includes(admin_required,
24 27
                                             include(theme_urls))),
25 28
    url(r'^emails/', decorated_includes(admin_required, include(emails_urls))),
26
-