Skip to content

Commit 2e8497e

Browse files
authored
Record privacy policy acceptance in the CFP (#4153)
1 parent 9b5f633 commit 2e8497e

File tree

2 files changed

+39
-48
lines changed

2 files changed

+39
-48
lines changed

backend/api/submissions/mutations.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from django.db import transaction
12
import math
23
import re
34
from typing import Annotated, Union, Optional
45

6+
from privacy_policy.record import record_privacy_policy_acceptance
57
import strawberry
68
from strawberry import ID
79
from strawberry.types import Info
@@ -312,6 +314,7 @@ def update_submission(
312314
return instance
313315

314316
@strawberry.mutation(permission_classes=[IsAuthenticated])
317+
@transaction.atomic
315318
def send_submission(
316319
self, info: Info, input: SendSubmissionInput
317320
) -> SendSubmissionOutput:
@@ -368,12 +371,21 @@ def send_submission(
368371
},
369372
)
370373

371-
notify_new_cfp_submission.delay(
372-
submission_id=instance.id,
373-
conference_id=instance.conference_id,
374-
admin_url=request.build_absolute_uri(instance.get_admin_url()),
374+
record_privacy_policy_acceptance(
375+
info.context.request,
376+
conference,
377+
"cfp",
375378
)
376379

380+
def _notify_new_submission():
381+
notify_new_cfp_submission.delay(
382+
submission_id=instance.id,
383+
conference_id=instance.conference_id,
384+
admin_url=request.build_absolute_uri(instance.get_admin_url()),
385+
)
386+
387+
transaction.on_commit(_notify_new_submission)
388+
377389
# hack because we return django models
378390
instance.__strawberry_definition__ = Submission.__strawberry_definition__
379391
return instance

backend/api/submissions/tests/test_send_submission.py

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from privacy_policy.models import PrivacyPolicyAcceptanceRecord
12
from files_upload.tests.factories import FileFactory
23
from conferences.tests.factories import (
34
AudienceLevelFactory,
@@ -11,6 +12,8 @@
1112
from submissions.models import Submission, SubmissionTag, SubmissionType
1213
from submissions.tests.factories import SubmissionFactory, SubmissionTypeFactory
1314

15+
pytestmark = mark.django_db
16+
1417

1518
def _submit_talk(client, conference, **kwargs):
1619
talk = SubmissionFactory.build(
@@ -134,8 +137,8 @@ def _submit_proposal(client, conference, submission, **kwargs):
134137
)
135138

136139

137-
@mark.django_db
138-
def test_submit_talk(graphql_client, user):
140+
def test_submit_talk(graphql_client, user, django_capture_on_commit_callbacks, mocker):
141+
mock_notify = mocker.patch("api.submissions.mutations.notify_new_cfp_submission")
139142
graphql_client.force_login(user)
140143

141144
conference = ConferenceFactory(
@@ -149,17 +152,18 @@ def test_submit_talk(graphql_client, user):
149152

150153
speaker_photo = FileFactory().id
151154

152-
resp, variables = _submit_talk(
153-
graphql_client,
154-
conference,
155-
title={
156-
"en": "English",
157-
"it": "old old",
158-
},
159-
shortSocialSummary="summary",
160-
speakerBio="my bio",
161-
speakerPhoto=speaker_photo,
162-
)
155+
with django_capture_on_commit_callbacks(execute=True):
156+
resp, variables = _submit_talk(
157+
graphql_client,
158+
conference,
159+
title={
160+
"en": "English",
161+
"it": "old old",
162+
},
163+
shortSocialSummary="summary",
164+
speakerBio="my bio",
165+
speakerPhoto=speaker_photo,
166+
)
163167

164168
assert resp["data"]["sendSubmission"]["__typename"] == "Submission"
165169

@@ -187,8 +191,13 @@ def test_submit_talk(graphql_client, user):
187191
assert participant.bio == "my bio"
188192
assert participant.photo_file_id == speaker_photo
189193

194+
assert PrivacyPolicyAcceptanceRecord.objects.filter(
195+
user=user, conference=conference, privacy_policy="cfp"
196+
).exists()
197+
198+
mock_notify.delay.assert_called_once()
199+
190200

191-
@mark.django_db
192201
def test_submit_talk_with_photo_to_upload(graphql_client, user, mocker):
193202
graphql_client.force_login(user)
194203

@@ -221,7 +230,6 @@ def test_submit_talk_with_photo_to_upload(graphql_client, user, mocker):
221230
assert participant.photo_file_id == speaker_photo
222231

223232

224-
@mark.django_db
225233
def test_submit_talk_without_photo_fails(graphql_client, user, mocker):
226234
graphql_client.force_login(user)
227235

@@ -252,7 +260,6 @@ def test_submit_talk_without_photo_fails(graphql_client, user, mocker):
252260
]
253261

254262

255-
@mark.django_db
256263
def test_submit_talk_with_existing_participant(graphql_client, user):
257264
graphql_client.force_login(user)
258265
conference = ConferenceFactory(
@@ -309,7 +316,6 @@ def test_submit_talk_with_existing_participant(graphql_client, user):
309316
assert participant.photo_file_id == speaker_photo
310317

311318

312-
@mark.django_db
313319
def test_submit_talk_with_missing_data_of_other_language_fails(graphql_client, user):
314320
graphql_client.force_login(user)
315321

@@ -341,7 +347,6 @@ def test_submit_talk_with_missing_data_of_other_language_fails(graphql_client, u
341347
]
342348

343349

344-
@mark.django_db
345350
def test_submit_talk_with_missing_data_fails(graphql_client, user):
346351
graphql_client.force_login(user)
347352

@@ -385,7 +390,6 @@ def test_submit_talk_with_missing_data_fails(graphql_client, user):
385390
)
386391

387392

388-
@mark.django_db
389393
def test_submit_talk_with_multiple_languages(graphql_client, user):
390394
graphql_client.force_login(user)
391395

@@ -429,7 +433,6 @@ def test_submit_talk_with_multiple_languages(graphql_client, user):
429433
assert talk.audience_level.name == "Beginner"
430434

431435

432-
@mark.django_db
433436
def test_submit_talk_with_not_valid_conf_language(graphql_client, user):
434437
graphql_client.force_login(user)
435438

@@ -450,7 +453,6 @@ def test_submit_talk_with_not_valid_conf_language(graphql_client, user):
450453
]
451454

452455

453-
@mark.django_db
454456
def test_submit_talk_with_not_valid_duration(graphql_client, user):
455457
graphql_client.force_login(user)
456458

@@ -471,7 +473,6 @@ def test_submit_talk_with_not_valid_duration(graphql_client, user):
471473
]
472474

473475

474-
@mark.django_db
475476
def test_cannot_use_duration_if_submission_type_is_not_allowed(graphql_client, user):
476477
graphql_client.force_login(user)
477478

@@ -502,7 +503,6 @@ def test_cannot_use_duration_if_submission_type_is_not_allowed(graphql_client, u
502503
]
503504

504505

505-
@mark.django_db
506506
def test_submit_talk_with_duration_id_of_another_conf(graphql_client, user):
507507
graphql_client.force_login(user)
508508

@@ -527,7 +527,6 @@ def test_submit_talk_with_duration_id_of_another_conf(graphql_client, user):
527527
]
528528

529529

530-
@mark.django_db
531530
def test_submit_talk_with_not_valid_conf_topic(graphql_client, user):
532531
graphql_client.force_login(user)
533532

@@ -549,7 +548,6 @@ def test_submit_talk_with_not_valid_conf_topic(graphql_client, user):
549548
]
550549

551550

552-
@mark.django_db
553551
def test_submit_talk_with_not_valid_allowed_submission_type_in_the_conference(
554552
graphql_client, user
555553
):
@@ -572,7 +570,6 @@ def test_submit_talk_with_not_valid_allowed_submission_type_in_the_conference(
572570
]
573571

574572

575-
@mark.django_db
576573
def test_submit_talk_with_not_valid_submission_type_id(graphql_client, user):
577574
graphql_client.force_login(user)
578575

@@ -593,7 +590,6 @@ def test_submit_talk_with_not_valid_submission_type_id(graphql_client, user):
593590
]
594591

595592

596-
@mark.django_db
597593
def test_submit_talk_with_not_valid_language_code(graphql_client, user):
598594
graphql_client.force_login(user)
599595

@@ -614,7 +610,6 @@ def test_submit_talk_with_not_valid_language_code(graphql_client, user):
614610
]
615611

616612

617-
@mark.django_db
618613
def test_submit_talk_with_not_valid_audience_level(graphql_client, user):
619614
graphql_client.force_login(user)
620615

@@ -636,7 +631,6 @@ def test_submit_talk_with_not_valid_audience_level(graphql_client, user):
636631
# assert resp["data"]["sendSubmission"]["errors"][0]["field"] == "audience_level"
637632

638633

639-
@mark.django_db
640634
def test_submit_talk_with_not_valid_conf_audience_level(graphql_client, user):
641635
graphql_client.force_login(user)
642636
audience_level = AudienceLevelFactory(name="Intermidiate")
@@ -657,7 +651,6 @@ def test_submit_talk_with_not_valid_conf_audience_level(graphql_client, user):
657651
]
658652

659653

660-
@mark.django_db
661654
def test_cannot_propose_a_talk_as_unlogged_user(graphql_client):
662655
conference = ConferenceFactory(
663656
topics=("my-topic",),
@@ -672,7 +665,6 @@ def test_cannot_propose_a_talk_as_unlogged_user(graphql_client):
672665
assert resp["errors"][0]["message"] == "User not logged in"
673666

674667

675-
@mark.django_db
676668
def test_cannot_propose_a_talk_if_the_cfp_is_not_open(graphql_client, user):
677669
graphql_client.force_login(user)
678670

@@ -693,7 +685,6 @@ def test_cannot_propose_a_talk_if_the_cfp_is_not_open(graphql_client, user):
693685
]
694686

695687

696-
@mark.django_db
697688
def test_cannot_propose_a_talk_if_a_cfp_is_not_specified(graphql_client, user):
698689
graphql_client.force_login(user)
699690

@@ -713,7 +704,6 @@ def test_cannot_propose_a_talk_if_a_cfp_is_not_specified(graphql_client, user):
713704
]
714705

715706

716-
@mark.django_db
717707
def test_same_user_can_propose_multiple_talks_to_the_same_conference(
718708
graphql_client, user
719709
):
@@ -747,7 +737,6 @@ def test_same_user_can_propose_multiple_talks_to_the_same_conference(
747737
)
748738

749739

750-
@mark.django_db
751740
def test_submit_tutorial(graphql_client, user):
752741
graphql_client.force_login(user)
753742

@@ -773,7 +762,6 @@ def test_submit_tutorial(graphql_client, user):
773762
)
774763

775764

776-
@mark.django_db
777765
def test_submit_tutorial_and_talk_to_the_same_conference(graphql_client, user):
778766
graphql_client.force_login(user)
779767

@@ -807,7 +795,6 @@ def test_submit_tutorial_and_talk_to_the_same_conference(graphql_client, user):
807795
)
808796

809797

810-
@mark.django_db
811798
def test_notes_are_not_required(graphql_client, user):
812799
graphql_client.force_login(user)
813800

@@ -831,7 +818,6 @@ def test_notes_are_not_required(graphql_client, user):
831818
)
832819

833820

834-
@mark.django_db
835821
def test_same_user_can_submit_talks_to_different_conferences(graphql_client, user):
836822
graphql_client.force_login(user)
837823

@@ -944,7 +930,6 @@ def test_speaker_level_only_allows_the_predefined_levels(graphql_client, user):
944930
] == ["Select a valid choice"]
945931

946932

947-
@mark.django_db
948933
def test_submit_talk_with_too_long_title_fails(graphql_client, user):
949934
graphql_client.force_login(user)
950935

@@ -978,7 +963,6 @@ def test_submit_talk_with_too_long_title_fails(graphql_client, user):
978963
)
979964

980965

981-
@mark.django_db
982966
def test_submit_talk_with_no_languages_and_no_tags_is_not_allowed(graphql_client, user):
983967
graphql_client.force_login(user)
984968

@@ -1006,7 +990,6 @@ def test_submit_talk_with_no_languages_and_no_tags_is_not_allowed(graphql_client
1006990
)
1007991

1008992

1009-
@mark.django_db
1010993
def test_submit_talk_with_no_conference(graphql_client, user):
1011994
graphql_client.force_login(user)
1012995

@@ -1029,7 +1012,6 @@ def test_submit_talk_with_no_conference(graphql_client, user):
10291012
)
10301013

10311014

1032-
@mark.django_db
10331015
def test_submit_talk_with_too_long_notes_fails(graphql_client, user):
10341016
graphql_client.force_login(user)
10351017

@@ -1056,7 +1038,6 @@ def test_submit_talk_with_too_long_notes_fails(graphql_client, user):
10561038
)
10571039

10581040

1059-
@mark.django_db
10601041
def test_submit_talk_with_too_long_summary_fails(graphql_client, user):
10611042
graphql_client.force_login(user)
10621043

@@ -1083,7 +1064,6 @@ def test_submit_talk_with_too_long_summary_fails(graphql_client, user):
10831064
)
10841065

10851066

1086-
@mark.django_db
10871067
def test_submit_talk_only_allows_5_tags(graphql_client, user):
10881068
graphql_client.force_login(user)
10891069

@@ -1118,7 +1098,6 @@ def test_submit_talk_only_allows_5_tags(graphql_client, user):
11181098
)
11191099

11201100

1121-
@mark.django_db
11221101
def test_submit_talk_with_no_tags_fails(graphql_client, user):
11231102
graphql_client.force_login(user)
11241103

0 commit comments

Comments
 (0)