udata 14.4.1.dev7__py3-none-any.whl → 14.5.1.dev9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. udata/api/__init__.py +2 -0
  2. udata/auth/views.py +7 -3
  3. udata/commands/dcat.py +1 -1
  4. udata/core/dataservices/api.py +8 -1
  5. udata/core/dataservices/apiv2.py +2 -5
  6. udata/core/dataservices/models.py +4 -1
  7. udata/core/dataservices/rdf.py +2 -1
  8. udata/core/dataservices/tasks.py +6 -2
  9. udata/core/dataset/api.py +28 -4
  10. udata/core/dataset/api_fields.py +1 -1
  11. udata/core/dataset/apiv2.py +1 -1
  12. udata/core/dataset/models.py +4 -4
  13. udata/core/dataset/rdf.py +8 -2
  14. udata/core/dataset/tasks.py +6 -2
  15. udata/core/discussions/api.py +15 -1
  16. udata/core/discussions/models.py +5 -0
  17. udata/core/legal/__init__.py +0 -0
  18. udata/core/legal/mails.py +128 -0
  19. udata/core/organization/api.py +8 -0
  20. udata/core/organization/api_fields.py +3 -3
  21. udata/core/organization/apiv2.py +2 -3
  22. udata/core/organization/models.py +6 -1
  23. udata/core/reuse/api.py +8 -0
  24. udata/core/reuse/apiv2.py +2 -5
  25. udata/core/topic/models.py +8 -2
  26. udata/core/user/api.py +10 -3
  27. udata/core/user/api_fields.py +3 -3
  28. udata/core/user/models.py +7 -1
  29. udata/flask_mongoengine/pagination.py +1 -1
  30. udata/harvest/backends/dcat.py +4 -1
  31. udata/harvest/tests/test_dcat_backend.py +24 -0
  32. udata/mail.py +14 -0
  33. udata/rdf.py +20 -5
  34. udata/settings.py +4 -0
  35. udata/tests/api/test_datasets_api.py +44 -0
  36. udata/tests/apiv2/test_search.py +30 -0
  37. udata/tests/dataservice/test_dataservice_tasks.py +29 -0
  38. udata/tests/dataset/test_dataset_rdf.py +16 -0
  39. udata/tests/dataset/test_dataset_tasks.py +25 -0
  40. udata/tests/frontend/test_auth.py +34 -0
  41. udata/tests/helpers.py +6 -0
  42. udata/tests/search/test_search_integration.py +33 -0
  43. udata/tests/test_api_fields.py +10 -0
  44. udata/tests/test_legal_mails.py +359 -0
  45. {udata-14.4.1.dev7.dist-info → udata-14.5.1.dev9.dist-info}/METADATA +2 -2
  46. {udata-14.4.1.dev7.dist-info → udata-14.5.1.dev9.dist-info}/RECORD +50 -45
  47. {udata-14.4.1.dev7.dist-info → udata-14.5.1.dev9.dist-info}/WHEEL +0 -0
  48. {udata-14.4.1.dev7.dist-info → udata-14.5.1.dev9.dist-info}/entry_points.txt +0 -0
  49. {udata-14.4.1.dev7.dist-info → udata-14.5.1.dev9.dist-info}/licenses/LICENSE +0 -0
  50. {udata-14.4.1.dev7.dist-info → udata-14.5.1.dev9.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,359 @@
1
+ import pytest
2
+ from flask import url_for
3
+
4
+ from udata.core.dataservices.factories import DataserviceFactory
5
+ from udata.core.dataset.factories import DatasetFactory
6
+ from udata.core.discussions.factories import DiscussionFactory, MessageDiscussionFactory
7
+ from udata.core.organization.factories import OrganizationFactory
8
+ from udata.core.reuse.factories import ReuseFactory
9
+ from udata.core.user.factories import AdminFactory, UserFactory
10
+ from udata.tests.api import APITestCase
11
+ from udata.tests.helpers import capture_mails
12
+
13
+
14
+ class AdminMailsOnDeleteTest(APITestCase):
15
+ """Test admin mails are sent on delete when send_legal_notice=True and user is sysadmin"""
16
+
17
+ modules = []
18
+
19
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
20
+ def test_dataset_delete_with_mail_as_admin(self):
21
+ """Admin deleting dataset with send_legal_notice=True should send email to owner"""
22
+ self.login(AdminFactory())
23
+ owner = UserFactory()
24
+ dataset = DatasetFactory(owner=owner)
25
+
26
+ with capture_mails() as mails:
27
+ response = self.delete(
28
+ url_for("api.dataset", dataset=dataset) + "?send_legal_notice=true"
29
+ )
30
+
31
+ self.assertStatus(response, 204)
32
+ assert len(mails) == 1
33
+ assert mails[0].recipients[0] == owner.email
34
+ assert "deletion" in mails[0].subject.lower()
35
+
36
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
37
+ def test_dataset_delete_without_mail_as_admin(self):
38
+ """Admin deleting dataset without send_mail should not send email"""
39
+ self.login(AdminFactory())
40
+ owner = UserFactory()
41
+ dataset = DatasetFactory(owner=owner)
42
+
43
+ with capture_mails() as mails:
44
+ response = self.delete(url_for("api.dataset", dataset=dataset))
45
+
46
+ self.assertStatus(response, 204)
47
+ assert len(mails) == 0
48
+
49
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
50
+ def test_dataset_delete_with_mail_as_non_admin(self):
51
+ """Non-admin deleting their dataset with send_legal_notice=True should not send email"""
52
+ owner = self.login()
53
+ dataset = DatasetFactory(owner=owner)
54
+
55
+ with capture_mails() as mails:
56
+ response = self.delete(
57
+ url_for("api.dataset", dataset=dataset) + "?send_legal_notice=true"
58
+ )
59
+
60
+ self.assertStatus(response, 204)
61
+ assert len(mails) == 0
62
+
63
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
64
+ def test_dataset_delete_with_org_owner_sends_to_admins(self):
65
+ """Deleting org-owned dataset should send email to org admins"""
66
+ self.login(AdminFactory())
67
+ org_admin = UserFactory()
68
+ org = OrganizationFactory(members=[{"user": org_admin, "role": "admin"}])
69
+ dataset = DatasetFactory(organization=org)
70
+
71
+ with capture_mails() as mails:
72
+ response = self.delete(
73
+ url_for("api.dataset", dataset=dataset) + "?send_legal_notice=true"
74
+ )
75
+
76
+ self.assertStatus(response, 204)
77
+ assert len(mails) == 1
78
+ assert mails[0].recipients[0] == org_admin.email
79
+
80
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
81
+ def test_reuse_delete_with_mail_as_admin(self):
82
+ """Admin deleting reuse with send_legal_notice=True should send email to owner"""
83
+ self.login(AdminFactory())
84
+ owner = UserFactory()
85
+ reuse = ReuseFactory(owner=owner)
86
+
87
+ with capture_mails() as mails:
88
+ response = self.delete(url_for("api.reuse", reuse=reuse) + "?send_legal_notice=true")
89
+
90
+ self.assertStatus(response, 204)
91
+ assert len(mails) == 1
92
+ assert mails[0].recipients[0] == owner.email
93
+
94
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
95
+ def test_reuse_delete_without_mail_as_admin(self):
96
+ """Admin deleting reuse without send_mail should not send email"""
97
+ self.login(AdminFactory())
98
+ owner = UserFactory()
99
+ reuse = ReuseFactory(owner=owner)
100
+
101
+ with capture_mails() as mails:
102
+ response = self.delete(url_for("api.reuse", reuse=reuse))
103
+
104
+ self.assertStatus(response, 204)
105
+ assert len(mails) == 0
106
+
107
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
108
+ def test_dataservice_delete_with_mail_as_admin(self):
109
+ """Admin deleting dataservice with send_legal_notice=True should send email to owner"""
110
+ self.login(AdminFactory())
111
+ owner = UserFactory()
112
+ dataservice = DataserviceFactory(owner=owner)
113
+
114
+ with capture_mails() as mails:
115
+ response = self.delete(
116
+ url_for("api.dataservice", dataservice=dataservice) + "?send_legal_notice=true"
117
+ )
118
+
119
+ self.assertStatus(response, 204)
120
+ assert len(mails) == 1
121
+ assert mails[0].recipients[0] == owner.email
122
+
123
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
124
+ def test_organization_delete_with_mail_as_admin(self):
125
+ """Admin deleting organization with send_legal_notice=True should send email to org admins"""
126
+ self.login(AdminFactory())
127
+ org_admin = UserFactory()
128
+ org = OrganizationFactory(members=[{"user": org_admin, "role": "admin"}])
129
+
130
+ with capture_mails() as mails:
131
+ response = self.delete(url_for("api.organization", org=org) + "?send_legal_notice=true")
132
+
133
+ self.assertStatus(response, 204)
134
+ assert len(mails) == 1
135
+ assert mails[0].recipients[0] == org_admin.email
136
+
137
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
138
+ def test_user_delete_with_legal_notice_skips_simple_notification(self):
139
+ """Admin deleting user with send_legal_notice=True automatically skips simple notification"""
140
+ self.login(AdminFactory())
141
+ user_to_delete = UserFactory()
142
+
143
+ with capture_mails() as mails:
144
+ response = self.delete(
145
+ url_for("api.user", user=user_to_delete) + "?send_legal_notice=true"
146
+ )
147
+
148
+ self.assertStatus(response, 204)
149
+ # Only legal notice mail, simple notification is automatically skipped
150
+ assert len(mails) == 1
151
+ assert mails[0].recipients[0] == user_to_delete.email
152
+ # Verify it's the legal notice (with appeal info), not the simple notification
153
+ assert "Deletion of your" in mails[0].subject # Legal notice subject
154
+ assert "contest this decision" in mails[0].body # Legal notice contains appeal info
155
+
156
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
157
+ def test_discussion_delete_with_mail_as_admin(self):
158
+ """Admin deleting discussion with send_legal_notice=True should send email to author"""
159
+ self.login(AdminFactory())
160
+ author = UserFactory()
161
+ dataset = DatasetFactory()
162
+ discussion = DiscussionFactory(subject=dataset, user=author)
163
+
164
+ with capture_mails() as mails:
165
+ response = self.delete(
166
+ url_for("api.discussion", id=discussion.id) + "?send_legal_notice=true"
167
+ )
168
+
169
+ self.assertStatus(response, 204)
170
+ assert len(mails) == 1
171
+ assert mails[0].recipients[0] == author.email
172
+
173
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
174
+ def test_message_delete_with_mail_as_admin(self):
175
+ """Admin deleting message with send_legal_notice=True should send email to author"""
176
+ self.login(AdminFactory())
177
+ author = UserFactory()
178
+ message_author = UserFactory()
179
+ dataset = DatasetFactory()
180
+ discussion = DiscussionFactory(
181
+ subject=dataset,
182
+ user=author,
183
+ discussion=[
184
+ MessageDiscussionFactory(posted_by=author),
185
+ MessageDiscussionFactory(posted_by=message_author),
186
+ ],
187
+ )
188
+
189
+ with capture_mails() as mails:
190
+ response = self.delete(
191
+ url_for("api.discussion_comment", id=discussion.id, cidx=1)
192
+ + "?send_legal_notice=true"
193
+ )
194
+
195
+ self.assertStatus(response, 204)
196
+ assert len(mails) == 1
197
+ assert mails[0].recipients[0] == message_author.email
198
+
199
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
200
+ def test_dataset_delete_without_owner_no_mail_sent(self):
201
+ """Deleting dataset without owner or organization should not send email"""
202
+ self.login(AdminFactory())
203
+ dataset = DatasetFactory(owner=None, organization=None)
204
+
205
+ with capture_mails() as mails:
206
+ response = self.delete(
207
+ url_for("api.dataset", dataset=dataset) + "?send_legal_notice=true"
208
+ )
209
+
210
+ self.assertStatus(response, 204)
211
+ assert len(mails) == 0
212
+
213
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
214
+ def test_reuse_delete_without_owner_no_mail_sent(self):
215
+ """Deleting reuse without owner or organization should not send email"""
216
+ self.login(AdminFactory())
217
+ reuse = ReuseFactory(owner=None, organization=None)
218
+
219
+ with capture_mails() as mails:
220
+ response = self.delete(url_for("api.reuse", reuse=reuse) + "?send_legal_notice=true")
221
+
222
+ self.assertStatus(response, 204)
223
+ assert len(mails) == 0
224
+
225
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
226
+ def test_dataservice_delete_without_owner_no_mail_sent(self):
227
+ """Deleting dataservice without owner or organization should not send email"""
228
+ self.login(AdminFactory())
229
+ dataservice = DataserviceFactory(owner=None, organization=None)
230
+
231
+ with capture_mails() as mails:
232
+ response = self.delete(
233
+ url_for("api.dataservice", dataservice=dataservice) + "?send_legal_notice=true"
234
+ )
235
+
236
+ self.assertStatus(response, 204)
237
+ assert len(mails) == 0
238
+
239
+ @pytest.mark.options(DEFAULT_LANGUAGE="en")
240
+ def test_organization_delete_without_admins_no_mail_sent(self):
241
+ """Deleting organization without admin members should not send email"""
242
+ self.login(AdminFactory())
243
+ editor = UserFactory()
244
+ org = OrganizationFactory(members=[{"user": editor, "role": "editor"}])
245
+
246
+ with capture_mails() as mails:
247
+ response = self.delete(url_for("api.organization", org=org) + "?send_legal_notice=true")
248
+
249
+ self.assertStatus(response, 204)
250
+ assert len(mails) == 0
251
+
252
+
253
+ class MailContentVariantsTest(APITestCase):
254
+ """Test mail content varies based on settings"""
255
+
256
+ modules = []
257
+
258
+ @pytest.mark.options(
259
+ DEFAULT_LANGUAGE="en",
260
+ TERMS_OF_USE_URL="https://example.com/terms",
261
+ TERMS_OF_USE_DELETION_ARTICLE="5.1.2",
262
+ TELERECOURS_URL="https://telerecours.fr",
263
+ )
264
+ def test_mail_with_all_settings(self):
265
+ """Mail should contain terms of use reference and telerecours when all settings defined"""
266
+ self.login(AdminFactory())
267
+ owner = UserFactory()
268
+ dataset = DatasetFactory(owner=owner)
269
+
270
+ with capture_mails() as mails:
271
+ self.delete(url_for("api.dataset", dataset=dataset) + "?send_legal_notice=true")
272
+
273
+ assert len(mails) == 1
274
+ body = mails[0].body
275
+ assert "Our terms of use specify" in body
276
+ assert "5.1.2" in body
277
+ assert "Télérecours" in body
278
+
279
+ @pytest.mark.options(
280
+ DEFAULT_LANGUAGE="en",
281
+ TERMS_OF_USE_DELETION_ARTICLE=None,
282
+ TELERECOURS_URL=None,
283
+ )
284
+ def test_mail_without_settings(self):
285
+ """Mail should use generic text when settings are not defined"""
286
+ self.login(AdminFactory())
287
+ owner = UserFactory()
288
+ dataset = DatasetFactory(owner=owner)
289
+
290
+ with capture_mails() as mails:
291
+ self.delete(url_for("api.dataset", dataset=dataset) + "?send_legal_notice=true")
292
+
293
+ assert len(mails) == 1
294
+ body = mails[0].body
295
+ assert "Our terms of use specify" not in body
296
+ assert "Télérecours" not in body
297
+ assert "contacting us" in body
298
+
299
+ @pytest.mark.options(
300
+ DEFAULT_LANGUAGE="en",
301
+ TERMS_OF_USE_URL="https://example.com/terms",
302
+ TERMS_OF_USE_DELETION_ARTICLE="3.2",
303
+ TELERECOURS_URL=None,
304
+ )
305
+ def test_mail_with_terms_only(self):
306
+ """Mail should contain terms of use but generic appeal when only terms defined"""
307
+ self.login(AdminFactory())
308
+ owner = UserFactory()
309
+ dataset = DatasetFactory(owner=owner)
310
+
311
+ with capture_mails() as mails:
312
+ self.delete(url_for("api.dataset", dataset=dataset) + "?send_legal_notice=true")
313
+
314
+ assert len(mails) == 1
315
+ body = mails[0].body
316
+ assert "Our terms of use specify" in body
317
+ assert "3.2" in body
318
+ assert "Télérecours" not in body
319
+ assert "contacting us" in body
320
+
321
+ @pytest.mark.options(
322
+ DEFAULT_LANGUAGE="en",
323
+ TERMS_OF_USE_DELETION_ARTICLE=None,
324
+ TELERECOURS_URL="https://telerecours.fr",
325
+ )
326
+ def test_mail_with_telerecours_only(self):
327
+ """Mail should contain telerecours but generic terms when only telerecours defined"""
328
+ self.login(AdminFactory())
329
+ owner = UserFactory()
330
+ dataset = DatasetFactory(owner=owner)
331
+
332
+ with capture_mails() as mails:
333
+ self.delete(url_for("api.dataset", dataset=dataset) + "?send_legal_notice=true")
334
+
335
+ assert len(mails) == 1
336
+ body = mails[0].body
337
+ assert "Our terms of use specify" not in body
338
+ assert "Télérecours" in body
339
+ assert "contacting us" not in body
340
+
341
+ @pytest.mark.options(
342
+ DEFAULT_LANGUAGE="en",
343
+ TERMS_OF_USE_URL=None,
344
+ TERMS_OF_USE_DELETION_ARTICLE="5.1.2",
345
+ TELERECOURS_URL=None,
346
+ )
347
+ def test_mail_with_article_but_no_url(self):
348
+ """Mail should use generic terms when article is defined but URL is missing"""
349
+ self.login(AdminFactory())
350
+ owner = UserFactory()
351
+ dataset = DatasetFactory(owner=owner)
352
+
353
+ with capture_mails() as mails:
354
+ self.delete(url_for("api.dataset", dataset=dataset) + "?send_legal_notice=true")
355
+
356
+ assert len(mails) == 1
357
+ body = mails[0].body
358
+ assert "Our terms of use specify" not in body
359
+ assert "5.1.2" not in body
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: udata
3
- Version: 14.4.1.dev7
3
+ Version: 14.5.1.dev9
4
4
  Summary: Open data portal
5
5
  Author-email: Opendata Team <opendatateam@data.gouv.fr>
6
6
  Maintainer-email: Opendata Team <opendatateam@data.gouv.fr>
@@ -85,7 +85,7 @@ Requires-Dist: tzdata
85
85
  Requires-Dist: urlextract<2.0.0,>=1.9.0
86
86
  Requires-Dist: urllib3<3.0.0,>=2.0.0
87
87
  Requires-Dist: voluptuous<1.0.0,>=0.15.2
88
- Requires-Dist: werkzeug<4.0.0,>=3.0.0
88
+ Requires-Dist: werkzeug<3.1.4,>=3.0.0
89
89
  Requires-Dist: wtforms[email]<4.0.0,>=3.2.1
90
90
  Requires-Dist: wtforms-json<1.0.0,>=0.3.5
91
91
  Dynamic: license-file