Skip to content

Commit ab8df9d

Browse files
committed
Validate that file doesn’t exist in subject
1 parent 0c30b35 commit ab8df9d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

app/main/forms.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,6 +3214,7 @@ def validate_report_has_been_processed(self, field):
32143214
class TemplateEmailFilesUploadForm(StripWhitespaceForm):
32153215
def __init__(self, *args, template, **kwargs):
32163216
self.existing_file_names = InsensitiveSet(file.filename for file in template.existing_files)
3217+
self.placeholders_in_subject = InsensitiveSet(UtilsField(template.subject).placeholders)
32173218
super().__init__(*args, **kwargs)
32183219

32193220
allowed_file_formats = {
@@ -3253,6 +3254,12 @@ def validate_file(self, field):
32533254
if field.data.filename in self.existing_file_names:
32543255
raise ValidationError(f"Your template already has a file called ‘{field.data.filename}’")
32553256

3257+
if field.data.filename in self.placeholders_in_subject:
3258+
raise ValidationError(
3259+
f"You cannot put a file in the subject of a template "
3260+
"– remove ((field.data.filename)) or rename your file"
3261+
)
3262+
32563263

32573264
class TemplateEmailFileLinkTextForm(StripWhitespaceForm):
32583265
link_text = GovukTextInputField("Link text (optional)")

0 commit comments

Comments
 (0)