Ignore guest users when looking up user in sendmail command

Also allow recipient users to have more than one user with the same
mail.
This commit is contained in:
Benjamin Dauvergne 2014-09-02 17:34:11 +02:00
parent 8da5aeee84
commit d904ce99fb
4 changed files with 22 additions and 19 deletions

View File

@ -13,6 +13,7 @@ from django.core.files.base import ContentFile
from django.core.exceptions import MultipleObjectsReturned from django.core.exceptions import MultipleObjectsReturned
from django.utils.timezone import utc, make_aware from django.utils.timezone import utc, make_aware
from django.template.defaultfilters import slugify from django.template.defaultfilters import slugify
from django.db.models.query import Q
from docbow_project.docbow import models, timestamp, utils from docbow_project.docbow import models, timestamp, utils
from docbow_project.docbow.email_utils import u2u_decode from docbow_project.docbow.email_utils import u2u_decode
@ -116,16 +117,22 @@ In case of failure the following return value is returned:
from_email = email.utils.parseaddr(options['sender'])[1] from_email = email.utils.parseaddr(options['sender'])[1]
if options.get('sender'): if options.get('sender'):
try: try:
sender = auth_models.User.objects.get(username=options['sender']) sender = auth_models.User.objects.filter(
Q(docbowprofile__is_guest=False)|
Q(docbowprofile__isnull=True)).get(
username=options['sender'])
except auth_models.User.DoesNotExist: except auth_models.User.DoesNotExist:
self.error('5.6.0 Unknown sender %r' % options['sender'], exit_code=8) self.error('5.6.0 Unknown sender %r' % options['sender'], exit_code=8)
else: else:
try: try:
sender = auth_models.User.objects.get(email=from_email) sender = auth_models.User.objects.filter(
Q(docbowprofile__is_guest=False)|
Q(docbowprofile__isnull=True)).get(
email=from_email)
except auth_models.User.DoesNotExist: except auth_models.User.DoesNotExist:
content_errors.append('No user have mail %r' % from_email) content_errors.append('No sender user have mail %r' % from_email)
except MultipleObjectsReturned: except MultipleObjectsReturned:
content_errors.append('Too many users have mail %r' % from_email) content_errors.append('Too many sender users have mail %r' % from_email)
tos = mail.get_all('to', []) tos = mail.get_all('to', [])
ccs = mail.get_all('cc', []) ccs = mail.get_all('cc', [])
resent_tos = mail.get_all('resent-to', []) resent_tos = mail.get_all('resent-to', [])
@ -185,14 +192,14 @@ In case of failure the following return value is returned:
mailing_list_recipients.append(mailing_list) mailing_list_recipients.append(mailing_list)
continue continue
# classic user case # classic user case
try: users = auth_models.User.objects.filter(
user = auth_models.User.objects.get(email=email_address) Q(docbowprofile__is_guest=False) |
recipients.append(user) Q(docbowprofile__isnull=True)).filter(
except MultipleObjectsReturned: email=email_address)
msg = 'Recipient %r has more than 1 user in the platform' \ if users:
% email_address for user in users:
content_errors.append(msg) recipients.append(user)
except auth_models.User.DoesNotExist: else:
try: try:
user = auth_models.User.objects.get(username=username) user = auth_models.User.objects.get(username=username)
recipients.append(user) recipients.append(user)
@ -200,10 +207,6 @@ In case of failure the following return value is returned:
msg = 'Recipient %r is not an user of the platform' \ msg = 'Recipient %r is not an user of the platform' \
% username % username
content_errors.append(msg) content_errors.append(msg)
except MultipleObjectsReturned:
msg = 'Recipient %r has more than 1 user in the platform' \
% username
content_errors.append(msg)
self.filenames = [a for a, b in attachments] self.filenames = [a for a, b in attachments]
if not len(attachments): if not len(attachments):
content_errors.append('You must send at least one attached file') content_errors.append('You must send at least one attached file')

View File

@ -1,5 +1,5 @@
--allow-all-external --allow-all-external
Django>=1.5 Django>=1.5,<1.7
South<0.8.0 South<0.8.0
django-debug-toolbar<0.9.0 django-debug-toolbar<0.9.0
django-grappelli<2.5.0 django-grappelli<2.5.0

View File

@ -87,7 +87,7 @@ setup(name='docbow',
scripts=('docbow-ctl',), scripts=('docbow-ctl',),
packages=find_packages(), packages=find_packages(),
install_requires=[ install_requires=[
'Django>=1.5', 'Django>=1.5,<1.7',
'South<0.8.0', 'South<0.8.0',
'django-debug-toolbar<0.9.0', 'django-debug-toolbar<0.9.0',
'django-grappelli<2.5.0', 'django-grappelli<2.5.0',

View File

@ -14,7 +14,7 @@ if [ "$VIRTUAL_ENV" = "" ]; then
fi fi
fi fi
easy_install -U pip distribute easy_install -U pip distribute
pip install -U 'django==1.5' pip install -U 'django>=1.5'
pip install -U -r requirements.txt pip install -U -r requirements.txt
if [ ! -f $PROJECT.db ]; then if [ ! -f $PROJECT.db ]; then
./$CTL syncdb --all --noinput ./$CTL syncdb --all --noinput