Commit 6f3df599 authored by Joost Rijneveld's avatar Joost Rijneveld
Browse files

Merge branch 'feature/autoresponse-mailinglists' into 'master'

Add automatic response to mailinglists

Closes #285

See merge request thalia/concrexit!709
parents 2e2c61f7 dd0f5827
......@@ -6,7 +6,8 @@ from mailinglists.models import MailingList
class MailingListSerializer(serializers.ModelSerializer):
class Meta:
model = MailingList
fields = ('names', 'prefix', 'archived', 'moderated', 'addresses')
fields = ('names', 'prefix', 'archived', 'moderated', 'addresses',
'autoresponse_enabled', 'autoresponse_text')
names = serializers.SerializerMethodField('_names')
addresses = serializers.SerializerMethodField('_addresses')
......
# Generated by Django 2.0.2 on 2018-02-03 22:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('mailinglists', '0011_auto_20171013_1419'),
]
operations = [
migrations.AddField(
model_name='mailinglist',
name='autoresponse_enabled',
field=models.BooleanField(default=False, help_text='Indicate whether emails will get an automatic response.', verbose_name='Automatic response enabled'),
),
migrations.AddField(
model_name='mailinglist',
name='autoresponse_text',
field=models.TextField(blank=True, null=True, verbose_name='Autoresponse text'),
),
]
......@@ -54,6 +54,18 @@ class MailingList(models.Model):
blank=True,
)
autoresponse_enabled = models.BooleanField(
verbose_name=_("Automatic response enabled"),
default=False,
help_text=_('Indicate whether emails will get an automatic response.')
)
autoresponse_text = models.TextField(
verbose_name=_("Autoresponse text"),
null=True,
blank=True,
)
def all_addresses(self):
for member in self.members.all():
yield member.email
......@@ -78,6 +90,11 @@ class MailingList(models.Model):
}
})
if not self.autoresponse_text and self.autoresponse_enabled:
raise ValidationError({
'autoresponse_text': _('Enter a text for the auto response.')
})
def __str__(self):
return self.name
......
......@@ -31,6 +31,15 @@ class MailingListTest(TestCase):
listalias.alias = "mailalias"
listalias.clean()
def test_autoresponse_has_text(self):
self.mailinglist.autoresponse_enabled = True
with self.assertRaises(ValidationError):
self.mailinglist.clean()
self.mailinglist.autoresponse_text = "Hello World"
self.mailinglist.clean()
class ListAliasTest(TestCase):
"""Tests list aliases"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment