Commit 31c098a3 authored by Joren Vrancken's avatar Joren Vrancken

Merge branch 'fix-things-mailinglists' into 'master'

Fix small issues in the mailinglists app

See merge request !1402
parents 192980ea 4a8fd980
......@@ -23,8 +23,8 @@ class MailingListAdmin(admin.ModelAdmin):
filter_horizontal = ('members',)
inlines = (VerbatimAddressInline, ListAliasInline)
list_display = ('name', 'alias_names', 'description')
search_fields = ['name', 'prefix', 'aliasses__alias']
list_display = ('name', 'alias_names', 'moderated', 'description')
search_fields = ['name', 'aliasses__alias']
def alias_names(self, obj):
"""Return list of aliases of obj."""
......
......@@ -12,7 +12,6 @@ from mailinglists.services import get_automatic_lists
from utils.google_api import get_directory_api, get_groups_settings_api
logger = logging.getLogger(__name__)
logger.setLevel(logging.WARNING)
class GSuiteSyncService:
......@@ -24,7 +23,7 @@ class GSuiteSyncService:
self.name = name
self.description = description
self.aliases = aliases
self.addresses = addresses
self.addresses = sorted(set(addresses))
def __eq__(self, other: object) -> bool:
if isinstance(other, self.__class__):
......@@ -216,7 +215,7 @@ class GSuiteSyncService:
except HttpError as e:
logger.error('Could not obtain list member data', e.content)
return # the list does not exist or something else is wrong
new_members = list(group.addresses)
new_members = group.addresses
remove_list = [x for x in existing_members if x not in new_members]
insert_list = [x for x in new_members if x not in existing_members
......@@ -254,8 +253,10 @@ class GSuiteSyncService:
moderated=mailinglist.moderated,
name=mailinglist.name,
description=mailinglist.description,
aliases=[x.alias for x in mailinglist.aliases.all()],
addresses=list(mailinglist.all_addresses())
aliases=([x.alias for x in mailinglist.aliases.all()]
if mailinglist.pk is not None else []),
addresses=(list(mailinglist.all_addresses())
if mailinglist.pk is not None else [])
)
@staticmethod
......
# Generated by Django 2.2.6 on 2019-10-30 21:14
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('mailinglists', '0015_auto_20191013_2352'),
]
operations = [
migrations.AlterField(
model_name='mailinglist',
name='name',
field=models.CharField(help_text='Enter the name for the list (i.e. name@thalia.nu).', max_length=60, unique=True, validators=[django.core.validators.RegexValidator(message='Enter a simpler name', regex='^[a-zA-Z0-9-]+$')], verbose_name='Name'),
),
]
......@@ -32,9 +32,9 @@ class MailingList(models.Model):
name = models.CharField(
verbose_name=_("Name"),
max_length=100,
max_length=60,
validators=[validators.RegexValidator(
regex=r'^[a-zA-Z0-9]+$',
regex=r'^[a-zA-Z0-9-]+$',
message=_('Enter a simpler name'))
],
unique=True,
......@@ -69,15 +69,18 @@ class MailingList(models.Model):
def all_addresses(self):
"""Return all addresses subscribed to this mailing list."""
for member in self.members.all():
yield member.email
if member.email:
yield member.email
for group in self.member_groups.all().prefetch_related("members"):
for member in group.members.exclude(
membergroupmembership__until__lt=timezone.now().date()):
yield member.email
if member.email:
yield member.email
for verbatimaddress in self.addresses.all():
yield verbatimaddress.address
if verbatimaddress.address:
yield verbatimaddress.address
def clean(self):
"""Validate the mailing list."""
......
......@@ -110,18 +110,20 @@ def _create_automatic_list(names, prefix, members, description='',
}
if multilingual:
data['addresses'] = set([member.email for member in members])
data['addresses'] = set([member.email for member in members
if member.email])
yield data # this is the complete list, e.g. leden@
for language in settings.LANGUAGES:
localized_data = data.copy()
localized_data['addresses'] = [
member.email for member in members
if member.profile.language == language[0]]
if member.profile.language == language[0] and member.email]
localized_data['names'] = [
'{}-{}'.format(n, language[0]) for n in names]
localized_data['name'] = localized_data['names'][0]
localized_data['aliases'] = localized_data['names'][1:]
yield localized_data # these are localized lists, e.g. leden-nl@
else:
data['addresses'] = set([member.email for member in members])
data['addresses'] = set([member.email for member in members
if member.email])
yield data
Markdown is supported
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