SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit a5c9544e authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Make it possible to save draft message without to_recipient, subject

parent 488dc09f
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,16 @@ class ComposedMessageSerializer(serializers.ModelSerializer): ...@@ -42,6 +42,16 @@ class ComposedMessageSerializer(serializers.ModelSerializer):
def get_from_email(self, obj): def get_from_email(self, obj):
return obj.from_account.email return obj.from_account.email
def validate(self, data):
if data['status'] != ComposedMessage.STATUS_DRAFT:
if not data['to_recipient']:
raise serializers.ValidationError(
"to_recipient cannot be empty if message is not a draft")
if not data['subject']:
raise serializers.ValidationError(
"Subject cannot be empty if message is not a draft")
return data
def create(self, validated_data): def create(self, validated_data):
attachment_uuids = validated_data.pop('attachment_uuids') attachment_uuids = validated_data.pop('attachment_uuids')
cm = super().create(validated_data) cm = super().create(validated_data)
......
# Generated by Django 2.2.16 on 2020-10-27 19:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('apimail', '0027_addressbookentry'),
]
operations = [
migrations.AlterField(
model_name='composedmessage',
name='subject',
field=models.CharField(blank=True, max_length=256),
),
migrations.AlterField(
model_name='composedmessage',
name='to_recipient',
field=models.EmailField(blank=True, max_length=254),
),
]
...@@ -50,7 +50,7 @@ class ComposedMessage(models.Model): ...@@ -50,7 +50,7 @@ class ComposedMessage(models.Model):
'apimail.EmailAccount', 'apimail.EmailAccount',
on_delete=models.PROTECT) on_delete=models.PROTECT)
to_recipient = models.EmailField() to_recipient = models.EmailField(blank=True)
cc_recipients = ArrayField( cc_recipients = ArrayField(
models.EmailField(), models.EmailField(),
...@@ -60,7 +60,9 @@ class ComposedMessage(models.Model): ...@@ -60,7 +60,9 @@ class ComposedMessage(models.Model):
models.EmailField(), models.EmailField(),
blank=True, null=True) blank=True, null=True)
subject = models.CharField(max_length=256) subject = models.CharField(
max_length=256,
blank=True)
body_text = models.TextField(blank=True) body_text = models.TextField(blank=True)
body_html = models.TextField(blank=True) body_html = models.TextField(blank=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment