Skip to content

Commit 45e9612

Browse files
authored
Merge pull request #583 from makinacorpus/add_orejime_manager
feat: Add orejime to manage cookies
2 parents bf05f72 + c5cdf3f commit 45e9612

File tree

18 files changed

+306
-29
lines changed

18 files changed

+306
-29
lines changed

atlas/atlasRoutes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,18 @@ def index():
207207
connection.close()
208208
session.close()
209209

210+
personal_data = False
211+
args_personal_data = request.args.get("personal_data")
212+
if args_personal_data and args_personal_data.lower() == "true":
213+
personal_data = True
214+
210215
return render_template(
211216
"templates/home/_main.html",
212217
observations=observations,
213218
mostViewTaxon=mostViewTaxon,
214219
customStatMedias=customStatMedias,
215220
lastDiscoveries=lastDiscoveries,
221+
personal_data=personal_data,
216222
)
217223

218224

atlas/configuration/config.py.example

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ LANGUAGES = {
8484
#####################
8585
#####################
8686

87-
# Code de suivi des statistiques Google Analytics (si AFFICHAGE_FOOTER = True)
88-
ID_GOOGLE_ANALYTICS = "UA-xxxxxxx-xx"
89-
9087
# Utiliser et afficher le glossaire (static/custom/glossaire.json.sample)
9188
GLOSSAIRE = False
9289

@@ -261,6 +258,12 @@ PATRIMONIALITE = {
261258
}
262259
}
263260

261+
# liste des application dont "orejime" controle la dépose de cookie
262+
OREJIME_APPS = []
263+
264+
# traduction orejime (voir la doc cookie et RGPD pour comment le remplir)
265+
OREJIME_TRANSLATIONS = {}
266+
264267
#############################
265268
#### Lien custom du logo ####
266269
#############################

atlas/configuration/config_schema.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@
7777
},
7878
}
7979

80+
orijime_default_translations = {
81+
"fr": {
82+
"consentModal": {
83+
"description": "",
84+
},
85+
"purposes": {"analytics": "Analyse", "security": "Sécurité"},
86+
},
87+
"en": {
88+
"consentModal": {
89+
"description": "This is an example of how to override an existing translation already used by Orejime",
90+
},
91+
"purposes": {"analytics": "Analytics", "security": "Security"},
92+
},
93+
}
94+
8095

8196
class SecretSchemaConf(Schema):
8297
class Meta:
@@ -122,7 +137,6 @@ class Meta:
122137
URL_APPLICATION = fields.String(load_default="")
123138
DEFAULT_LANGUAGE = fields.String(load_default="fr")
124139
MULTILINGUAL = fields.Boolean(load_default=False)
125-
ID_GOOGLE_ANALYTICS = fields.String(load_default="UA-xxxxxxx-xx")
126140
ORGANISM_MODULE = fields.Boolean(load_default=False)
127141
DISPLAY_OBSERVERS = fields.Boolean(load_default=True)
128142
GLOSSAIRE = fields.Boolean(load_default=False)
@@ -131,6 +145,8 @@ class Meta:
131145
AFFICHAGE_LOGOS_HOME = fields.Boolean(load_default=True)
132146
AFFICHAGE_FOOTER = fields.Boolean(load_default=True)
133147
AFFICHAGE_RGPD = fields.Boolean(load_default=True)
148+
OREJIME_APPS = fields.List(fields.Dict(), load_default=[])
149+
OREJIME_TRANSLATIONS = fields.Dict(load_default=orijime_default_translations)
134150
AFFICHAGE_STAT_GLOBALES = fields.Boolean(load_default=True)
135151
AFFICHAGE_DERNIERES_OBS = fields.Boolean(load_default=True)
136152
AFFICHAGE_EN_CE_MOMENT = fields.Boolean(load_default=True)

atlas/static/custom/templates/footer.html.sample

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
data-target="#modalCredits">{{ _('credits') }}</a> |
66
<a data-toggle="modal" href="#"
77
data-target="#modalMentions">{{ _('legal') }}</a>
8-
{% if configuration.AFFICHAGE_RGPD %}
8+
{% if configuration.AFFICHAGE_RGPD and configuration.OREJIME_APPS | length > 0 %}
99
|
1010
<a data-toggle="modal" href="#"
1111
data-target="#modalPersonalData">{{ _('personal_data') }}</a>
12+
| <a id="preferences-cookies" href="#" onclick="orejime.show()">{{ _('preferences_cookies') }}</a>
1213
{% endif %}
1314
</small>
1415

@@ -74,22 +75,5 @@
7475
</div>
7576
{% endif %}
7677

77-
{% if configuration.ID_GOOGLE_ANALYTICS != "UA-xxxxxxx-xx" %}
78-
<!-- Script Google Analytics -->
79-
<script>
80-
(function (i, s, o, g, r, a, m) {
81-
i['GoogleAnalyticsObject'] = r;
82-
i[r] = i[r] || function () {
83-
(i[r].q = i[r].q || []).push(arguments)
84-
}, i[r].l = 1 * new Date();
85-
a = s.createElement(o),
86-
m = s.getElementsByTagName(o)[0];
87-
a.async = 1;
88-
a.src = g;
89-
m.parentNode.insertBefore(a, m)
90-
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
78+
<!-- BLOC TRACEURS / ANALYSES VIZA COOKIES -->
9179

92-
ga('create', '{{configuration.ID_GOOGLE_ANALYTICS}}', 'auto');
93-
ga('send', 'pageview');
94-
</script>
95-
{% endif %}

atlas/static/main.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,24 @@ if (configuration.GLOSSAIRE) {
139139
});
140140
});
141141
}
142+
143+
if (configuration.OREJIME_APPS.length > 0) {
144+
var orejimeConfig = {
145+
elementID: "orejime",
146+
appElement: "main",
147+
cookieName: "orejime",
148+
cookieExpiresAfterDays: 365,
149+
privacyPolicy: "/?personal_data=true",
150+
default: true,
151+
mustConsent: false,
152+
mustNotice: false,
153+
lang: configuration.DEFAULT_LANGUAGE,
154+
logo: false,
155+
debug: configuration.modeDebug,
156+
apps: configuration.OREJIME_APPS,
157+
categories: configuration.OREJIME_CATEGORIES
158+
}
159+
if (configuration.OREJIME_TRANSLATIONS && configuration.OREJIME_TRANSLATIONS != {}) {
160+
orejimeConfig.translations = configuration.OREJIME_TRANSLATIONS
161+
}
162+
}

atlas/static/package-lock.json

Lines changed: 82 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

atlas/static/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"leaflet.snogylop": "^0.4.0",
3434
"leaflet.zoomhome": "^1.0.0",
3535
"lightbox2": "^2.8.2",
36+
"orejime": "^2.3.0",
3637
"popper.js": "^1.16.0",
3738
"raphael": "^2.2.0",
3839
"slick": "^1.12.2",

atlas/templates/core/assets_header.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@
3838
<link rel="SHORTCUT ICON" href="{{ url_for('static', filename='custom/images/favicon.ico') }}">
3939
<link rel="stylesheet" href="{{url_for('static', filename='css/atlas.css') }}" />
4040

41+
<!-- GDPR -->
42+
<script src="{{url_for('static', filename='node_modules/orejime/dist/orejime.js') }}"></script>
43+
<link rel="stylesheet" href="{{url_for('static', filename='node_modules/orejime/dist/orejime.css') }}" />
44+
4145
{% endblock %}

atlas/templates/home/_main.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
</script>
2929
<script src="{{ url_for('static', filename='index.js') }}"></script>
3030

31+
{% if personal_data %}
32+
<script>
33+
$("#modalPersonalData").modal('show');
34+
</script>
35+
{% endif %}
36+
3137
{% endblock %}
3238

3339

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)