Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions backend/api/submissions/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ def multi_lingual_validation(
def validate(self, conference: Conference):
errors = SendSubmissionErrors()

if not self.tags:
errors.add_error("tags", "You need to add at least one tag")
elif len(self.tags) > 3:
if self.tags and len(self.tags) > 3:
errors.add_error("tags", "You can only add up to 3 tags")

if not self.speaker_level:
Expand Down Expand Up @@ -255,7 +253,7 @@ class UpdateSubmissionInput(BaseSubmissionInput):
speaker_availabilities: JSON

topic: Optional[strawberry.ID] = strawberry.field(default=None)
tags: list[strawberry.ID] = strawberry.field(default_factory=list)
tags: Optional[list[strawberry.ID]] = strawberry.field(default=None)
materials: list[SubmissionMaterialInput] = strawberry.field(default_factory=list)
do_not_record: bool = strawberry.field(default=False)

Expand Down Expand Up @@ -347,7 +345,8 @@ def update_submission(
languages = Language.objects.filter(code__in=input.languages).all()
instance.languages.set(languages)

instance.tags.set(input.tags)
if input.tags is not None:
instance.tags.set(input.tags)

instance.save()

Expand Down
32 changes: 31 additions & 1 deletion backend/api/submissions/tests/test_edit_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def _update_submission(
new_speaker_availabilities=None,
new_materials=None,
new_do_not_record=None,
omit_tags=False,
):
new_topic = new_topic or submission.topic
new_audience = new_audience or submission.audience_level
Expand Down Expand Up @@ -158,7 +159,7 @@ def _update_submission(
"type": new_type.id,
"languages": new_languages,
"notes": "notes here",
"tags": [new_tag.id],
**({} if omit_tags else {"tags": [new_tag.id]}),
"duration": new_duration.id,
"speakerLevel": new_speaker_level,
"previousTalkVideo": new_previous_talk_video,
Expand Down Expand Up @@ -234,6 +235,35 @@ def test_update_submission(graphql_client, user):
assert participant.linkedin_url == "http://linkedin.com/company/pythonpizza"


def test_update_submission_without_tags_keeps_existing_tags(graphql_client, user):
conference = ConferenceFactory(
topics=("life",),
languages=("en",),
durations=("10",),
active_cfp=True,
audience_levels=("adult",),
submission_types=("talk",),
)

submission = SubmissionFactory(
speaker_id=user.id,
custom_topic="life",
custom_duration="10m",
custom_audience_level="adult",
custom_submission_type="talk",
languages=["en"],
tags=["python", "ml"],
conference=conference,
)

graphql_client.force_login(user)

response = _update_submission(graphql_client, submission=submission, omit_tags=True)

assert response["data"]["updateSubmission"]["__typename"] == "Submission"
assert {tag.name for tag in submission.tags.all()} == {"python", "ml"}


def test_update_submission_with_materials(graphql_client, user):
conference = ConferenceFactory(
topics=("life", "diy"),
Expand Down
44 changes: 7 additions & 37 deletions backend/api/submissions/tests/test_send_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,8 @@ def test_same_user_can_submit_talks_to_different_conferences(graphql_client, use
)


def test_create_submission_tags(graphql_client, user):
@mark.parametrize("tag_names", [["python", "GraphQL"], []])
def test_create_submission_tags(graphql_client, user, tag_names):
graphql_client.force_login(user)

conference = ConferenceFactory(
Expand All @@ -995,17 +996,15 @@ def test_create_submission_tags(graphql_client, user):
identifier=EmailTemplateIdentifier.proposal_received_confirmation,
)

python, _ = SubmissionTag.objects.get_or_create(name="python")
graphql, _ = SubmissionTag.objects.get_or_create(name="GraphQL")
tags = [SubmissionTag.objects.get_or_create(name=name)[0] for name in tag_names]

resp, variables = _submit_talk(
graphql_client, conference, tags=[python.id, graphql.id]
graphql_client, conference, tags=[tag.id for tag in tags]
)

assert resp["data"]["sendSubmission"]["__typename"] == "Submission"
assert resp["data"]["sendSubmission"]["tags"] == [
{"name": "python"},
{"name": "GraphQL"},
{"name": name} for name in tag_names
]


Expand Down Expand Up @@ -1080,7 +1079,7 @@ def test_submit_talk_with_too_long_title_fails(graphql_client, user):
)


def test_submit_talk_with_no_languages_and_no_tags_is_not_allowed(graphql_client, user):
def test_submit_talk_with_no_languages_is_not_allowed(graphql_client, user):
graphql_client.force_login(user)

conference = ConferenceFactory(
Expand All @@ -1092,7 +1091,7 @@ def test_submit_talk_with_no_languages_and_no_tags_is_not_allowed(graphql_client
audience_levels=("Beginner",),
)

resp, _ = _submit_talk(graphql_client, conference, languages=[], tags=[])
resp, _ = _submit_talk(graphql_client, conference, languages=[])

assert resp["data"]["sendSubmission"]["__typename"] == "SendSubmissionErrors"

Expand All @@ -1101,11 +1100,6 @@ def test_submit_talk_with_no_languages_and_no_tags_is_not_allowed(graphql_client
in resp["data"]["sendSubmission"]["errors"]["validationLanguages"]
)

assert (
"You need to add at least one tag"
in resp["data"]["sendSubmission"]["errors"]["validationTags"]
)


def test_submit_talk_with_no_conference(graphql_client, user):
graphql_client.force_login(user)
Expand Down Expand Up @@ -1215,30 +1209,6 @@ def test_submit_talk_only_allows_5_tags(graphql_client, user):
)


def test_submit_talk_with_no_tags_fails(graphql_client, user):
graphql_client.force_login(user)

conference = ConferenceFactory(
topics=("my-topic",),
languages=("en", "it"),
submission_types=("talk",),
active_cfp=True,
durations=("50",),
audience_levels=("Beginner",),
)

resp, _ = _submit_talk(
graphql_client, conference, shortSocialSummary="summary", tags=[]
)

assert resp["data"]["sendSubmission"]["__typename"] == "SendSubmissionErrors"

assert (
"You need to add at least one tag"
in resp["data"]["sendSubmission"]["errors"]["validationTags"]
)


def test_cannot_submit_more_than_3_proposals(graphql_client, user):
graphql_client.force_login(user)

Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/cfp-form/cfp-form.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ query CfpForm($conference: String!) {
name
}

topics {
id
name
}

submissionTypes {
id
name
Expand Down
13 changes: 5 additions & 8 deletions frontend/src/components/cfp-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ import { ProposalSection } from "./proposal-section";
export type GetErrorsKey =
| "validationTitle"
| "validationAbstract"
| "validationTopic"
| "validationLanguages"
| "validationType"
| "validationDuration"
| "validationElevatorPitch"
| "validationNotes"
| "validationAudienceLevel"
| "validationTags"
| "validationSpeakerLevel"
| "validationPreviousTalkVideo"
| "validationShortSocialSummary"
Expand All @@ -64,8 +64,8 @@ export type CfpFormFields = ParticipantFormFields & {
audienceLevel: string;
abstract: { it?: string; en?: string };
notes: string;
topic: string;
languages: string[];
tags: string[];
speakerLevel: string;
previousTalkVideo: string;
shortSocialSummary: string;
Expand All @@ -85,13 +85,13 @@ export type SubmissionStructure = {
multilingualTitle: { it: string; en: string };
multilingualElevatorPitch: { it: string; en: string };
multilingualAbstract: { it: string; en: string };
topic: { id: string } | null;
duration: { id: string };
audienceLevel: { id: string };
languages: { code: string }[];
notes: string;
previousTalkVideo: string;
speakerLevel: string;
tags: { id: string }[];
shortSocialSummary: string;
materials: {
id: string;
Expand Down Expand Up @@ -184,6 +184,7 @@ export const CfpForm = ({
formState.values.abstract,
formState.values.languages,
),
topic: formState.values.topic,
languages: formState.values.languages,
type: formState.values.type,
length: formState.values.length,
Expand All @@ -193,7 +194,6 @@ export const CfpForm = ({
),
notes: formState.values.notes,
audienceLevel: formState.values.audienceLevel,
tags: formState.values.tags,
speakerLevel: formState.values.speakerLevel,
previousTalkVideo: formState.values.previousTalkVideo,
shortSocialSummary: formState.values.shortSocialSummary,
Expand Down Expand Up @@ -247,6 +247,7 @@ export const CfpForm = ({
"elevatorPitch",
submission!.multilingualElevatorPitch,
);
formState.setField("topic", submission!.topic?.id);
formState.setField("length", submission!.duration.id);
formState.setField("audienceLevel", submission!.audienceLevel.id);
formState.setField(
Expand All @@ -255,10 +256,6 @@ export const CfpForm = ({
);
formState.setField("abstract", submission!.multilingualAbstract);
formState.setField("notes", submission!.notes);
formState.setField(
"tags",
submission!.tags.map((t) => t.id),
);
formState.setField("shortSocialSummary", submission!.shortSocialSummary);
formState.setField("acceptedPrivacyPolicy", true);
formState.setField(
Expand Down
44 changes: 27 additions & 17 deletions frontend/src/components/cfp-form/proposal-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import { FormattedMessage } from "react-intl";
import { useTranslatedMessage } from "~/helpers/use-translated-message";
import { MultiLingualInput } from "../multilingual-input";
import { TagsSelect } from "../tags-select";

export const ProposalSection = ({
conferenceData,
Expand Down Expand Up @@ -147,6 +146,33 @@ export const ProposalSection = ({
</Select>
</InputWrapper>

{conferenceData!.conference.topics.length > 0 && (
<InputWrapper
required={true}
title={<FormattedMessage id="cfp.trackLabel" />}
description={<FormattedMessage id="cfp.topicDescription" />}
>
<Select
{...select("topic")}
required={true}
errors={getErrors("validationTopic")}
>
<FormattedMessage id="cfp.selectTrack">
{(txt) => (
<option value="" disabled={true}>
{txt}
</option>
)}
</FormattedMessage>
{conferenceData!.conference.topics.map((topic) => (
<option key={topic.id} value={topic.id}>
{topic.name}
</option>
))}
</Select>
</InputWrapper>
)}

<InputWrapper
required={true}
title={<FormattedMessage id="cfp.audienceLevelLabel" />}
Expand All @@ -172,22 +198,6 @@ export const ProposalSection = ({
</Select>
</InputWrapper>

<InputWrapper
required={true}
title={<FormattedMessage id="cfp.tagsLabel" />}
description={<FormattedMessage id="cfp.tagsDescription" />}
>
<TagsSelect
tags={formState.values.tags || []}
onChange={(tags: { value: string }[]) => {
formState.setField(
"tags",
tags.map((t) => t.value),
);
}}
/>
</InputWrapper>

<InputWrapper
required={true}
title={<FormattedMessage id="cfp.abstractLabel" />}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/cfp-send-submission/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ export const CfpSendSubmission = () => {
conference: code,
title: input.title,
abstract: input.abstract,
topic: input.topic,
languages: input.languages,
type: input.type,
duration: input.length,
elevatorPitch: input.elevatorPitch,
notes: input.notes,
audienceLevel: input.audienceLevel,
tags: input.tags,
speakerLevel: input.speakerLevel,
previousTalkVideo: input.previousTalkVideo,
shortSocialSummary: input.shortSocialSummary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ mutation SendSubmission($input: SendSubmissionInput!, $language: String!) {
errors {
validationTitle: title
validationAbstract: abstract
validationTopic: topic
validationLanguages: languages
validationType: type
validationDuration: duration
validationElevatorPitch: elevatorPitch
validationNotes: notes
validationAudienceLevel: audienceLevel
validationTags: tags
validationPreviousTalkVideo: previousTalkVideo
validationSpeakerLevel: speakerLevel
validationShortSocialSummary: shortSocialSummary
Expand Down
Loading
Loading