From c014f6615a1872b150010c344fb8b42e298dd41e Mon Sep 17 00:00:00 2001 From: Marco Acierno Date: Mon, 30 Nov 2026 14:53:56 +0100 Subject: [PATCH] Fix CFP Slack notification for proposals without tags The CFP form no longer collects tags, so new proposals have none and the Tags field was sent to Slack as a plain_text object with empty text. Slack requires text objects to have at least 1 character, so the message is rejected and slack.send_message raises SlackIncomingWebhookError. Only add the Tags field when there are tags, and show the proposal's topic when it has one. --- backend/submissions/tasks.py | 43 ++++++++++++--------- backend/submissions/tests/test_tasks.py | 51 +++++++++++++++++++++---- 2 files changed, 69 insertions(+), 25 deletions(-) diff --git a/backend/submissions/tasks.py b/backend/submissions/tasks.py index 7831613d30..cc7e4a0631 100644 --- a/backend/submissions/tasks.py +++ b/backend/submissions/tasks.py @@ -27,6 +27,30 @@ def notify_new_cfp_submission(*, submission_id, conference_id, admin_url): speaker = User.objects.get(id=speaker_id) user_name = get_name(speaker) + fields = [] + if submission.topic: + fields += [ + {"type": "mrkdwn", "text": "*Topic*"}, + {"type": "plain_text", "text": submission.topic.name}, + ] + # Slack rejects the whole message if a plain_text field is empty. + if tags: + fields += [ + {"type": "mrkdwn", "text": "*Tags*"}, + {"type": "plain_text", "text": tags}, + ] + + section = { + "type": "section", + "text": { + "type": "mrkdwn", + "text": f"*<{admin_url}|{title.capitalize()}>*\n" + f"*Elevator Pitch*\n{elevator_pitch}", + }, + } + if fields: + section["fields"] = fields + slack.send_message( [ { @@ -37,24 +61,7 @@ def notify_new_cfp_submission(*, submission_id, conference_id, admin_url): }, } ], - [ - { - "blocks": [ - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": f"*<{admin_url}|{title.capitalize()}>*\n" - f"*Elevator Pitch*\n{elevator_pitch}", - }, - "fields": [ - {"type": "mrkdwn", "text": "*Tags*"}, - {"type": "plain_text", "text": str(tags)}, - ], - } - ] - } - ], + [{"blocks": [section]}], oauth_token=conference.get_slack_oauth_token(), channel_id=conference.slack_new_proposal_channel_id, ) diff --git a/backend/submissions/tests/test_tasks.py b/backend/submissions/tests/test_tasks.py index c101e19819..7d435ab18b 100644 --- a/backend/submissions/tests/test_tasks.py +++ b/backend/submissions/tests/test_tasks.py @@ -17,7 +17,31 @@ pytestmark = pytest.mark.django_db -def test_handle_new_cfp_submission(): +@pytest.mark.parametrize( + "topic_name,tags,expected_fields", + [ + (None, [], None), + ( + "Web", + [], + [ + {"type": "mrkdwn", "text": "*Topic*"}, + {"type": "plain_text", "text": "Web"}, + ], + ), + ( + "Web", + ["python"], + [ + {"type": "mrkdwn", "text": "*Topic*"}, + {"type": "plain_text", "text": "Web"}, + {"type": "mrkdwn", "text": "*Tags*"}, + {"type": "plain_text", "text": "python"}, + ], + ), + ], +) +def test_handle_new_cfp_submission(topic_name, tags, expected_fields): user = UserFactory( full_name="Marco Acierno", email="marco@placeholder.it", @@ -27,11 +51,15 @@ def test_handle_new_cfp_submission(): conference = ConferenceFactory( slack_new_proposal_channel_id="C123456", + topics=(topic_name,) if topic_name else (), ) submission = SubmissionFactory( conference=conference, speaker=user, + topic=None, + custom_topic=topic_name, + tags=tags, ) with patch("submissions.tasks.slack") as slack_mock: @@ -43,6 +71,9 @@ def test_handle_new_cfp_submission(): slack_mock.send_message.assert_called_once() assert "Marco Acierno" in str(slack_mock.send_message.mock_calls[0]) + attachments = slack_mock.send_message.call_args.args[1] + section = attachments[0]["blocks"][0] + assert section.get("fields") == expected_fields def test_send_proposal_rejected_email(sent_emails): @@ -65,13 +96,16 @@ def test_send_proposal_rejected_email(sent_emails): # Verify that the correct email template was used and email was sent emails_sent = sent_emails() assert emails_sent.count() == 1 - + sent_email = emails_sent.first() - assert sent_email.email_template.identifier == EmailTemplateIdentifier.proposal_rejected + assert ( + sent_email.email_template.identifier + == EmailTemplateIdentifier.proposal_rejected + ) assert sent_email.email_template.conference == submission.conference assert sent_email.recipient == submission.speaker assert sent_email.recipient_email == submission.speaker.email - + # Verify placeholders were processed correctly assert sent_email.placeholders["proposal_title"] == "Title" assert sent_email.placeholders["proposal_type"] == submission.type.name @@ -99,13 +133,16 @@ def test_send_proposal_in_waiting_list_email(sent_emails): # Verify that the correct email template was used and email was sent emails_sent = sent_emails() assert emails_sent.count() == 1 - + sent_email = emails_sent.first() - assert sent_email.email_template.identifier == EmailTemplateIdentifier.proposal_in_waiting_list + assert ( + sent_email.email_template.identifier + == EmailTemplateIdentifier.proposal_in_waiting_list + ) assert sent_email.email_template.conference == submission.conference assert sent_email.recipient == submission.speaker assert sent_email.recipient_email == submission.speaker.email - + # Verify placeholders were processed correctly assert sent_email.placeholders["proposal_title"] == "Title" assert sent_email.placeholders["proposal_type"] == submission.type.name