Skip to content

Commit e5c11e3

Browse files
authored
Limit submissions to 3 (#4505)
1 parent 08e9861 commit e5c11e3

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed

backend/api/submissions/mutations.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,17 @@ def send_submission(
409409
if not conference.is_cfp_open:
410410
errors.add_error("non_field_errors", "The call for paper is not open!")
411411

412+
if (
413+
SubmissionModel.objects.of_user(request.user)
414+
.for_conference(conference)
415+
.non_cancelled()
416+
.count()
417+
>= 3
418+
):
419+
errors.add_error(
420+
"non_field_errors", "You can only submit up to 3 proposals"
421+
)
422+
412423
if errors.has_errors:
413424
return errors
414425

backend/api/submissions/tests/test_send_submission.py

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ def _submit_proposal(client, conference, submission, **kwargs):
141141

142142

143143
def test_submit_talk(
144-
graphql_client, user, django_capture_on_commit_callbacks, mocker, settings, sent_emails
144+
graphql_client,
145+
user,
146+
django_capture_on_commit_callbacks,
147+
mocker,
148+
settings,
149+
sent_emails,
145150
):
146151
settings.FRONTEND_URL = "http://testserver"
147152
mock_notify = mocker.patch("api.submissions.mutations.notify_new_cfp_submission")
@@ -221,17 +226,23 @@ def test_submit_talk(
221226
# Verify that the correct email template was used and email was sent
222227
emails_sent = sent_emails()
223228
assert emails_sent.count() == 1
224-
229+
225230
sent_email = emails_sent.first()
226-
assert sent_email.email_template.identifier == EmailTemplateIdentifier.proposal_received_confirmation
231+
assert (
232+
sent_email.email_template.identifier
233+
== EmailTemplateIdentifier.proposal_received_confirmation
234+
)
227235
assert sent_email.email_template.conference == conference
228236
assert sent_email.recipient == user
229237
assert sent_email.recipient_email == user.email
230-
238+
231239
# Verify placeholders were processed correctly
232240
assert sent_email.placeholders["user_name"] == user.full_name
233241
assert sent_email.placeholders["proposal_title"] == "English"
234-
assert sent_email.placeholders["proposal_url"] == f"http://testserver/submission/{talk.hashid}"
242+
assert (
243+
sent_email.placeholders["proposal_url"]
244+
== f"http://testserver/submission/{talk.hashid}"
245+
)
235246

236247

237248
def test_submit_talk_with_photo_to_upload(graphql_client, user, mocker):
@@ -1224,3 +1235,39 @@ def test_submit_talk_with_no_tags_fails(graphql_client, user):
12241235
"You need to add at least one tag"
12251236
in resp["data"]["sendSubmission"]["errors"]["validationTags"]
12261237
)
1238+
1239+
1240+
def test_cannot_submit_more_than_3_proposals(graphql_client, user):
1241+
graphql_client.force_login(user)
1242+
1243+
conference = ConferenceFactory(
1244+
topics=("my-topic",),
1245+
languages=("en", "it"),
1246+
submission_types=("talk",),
1247+
active_cfp=True,
1248+
durations=("50",),
1249+
audience_levels=("Beginner",),
1250+
)
1251+
1252+
SubmissionFactory(
1253+
speaker_id=user.id,
1254+
conference=conference,
1255+
status=Submission.STATUS.proposed,
1256+
)
1257+
SubmissionFactory(
1258+
speaker_id=user.id,
1259+
conference=conference,
1260+
status=Submission.STATUS.proposed,
1261+
)
1262+
SubmissionFactory(
1263+
speaker_id=user.id,
1264+
conference=conference,
1265+
status=Submission.STATUS.proposed,
1266+
)
1267+
1268+
resp, _ = _submit_talk(graphql_client, conference, title={"en": "My first talk"})
1269+
1270+
assert resp["data"]["sendSubmission"]["__typename"] == "SendSubmissionErrors"
1271+
assert resp["data"]["sendSubmission"]["errors"]["nonFieldErrors"] == [
1272+
"You can only submit up to 3 proposals"
1273+
]

0 commit comments

Comments
 (0)