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.utils.timezone import utc, make_aware
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.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]
if options.get('sender'):
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:
self.error('5.6.0 Unknown sender %r' % options['sender'], exit_code=8)
else:
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:
content_errors.append('No user have mail %r' % from_email)
content_errors.append('No sender user have mail %r' % from_email)
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', [])
ccs = mail.get_all('cc', [])
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)
continue
# classic user case
try:
user = auth_models.User.objects.get(email=email_address)
recipients.append(user)
except MultipleObjectsReturned:
msg = 'Recipient %r has more than 1 user in the platform' \
% email_address
content_errors.append(msg)
except auth_models.User.DoesNotExist:
users = auth_models.User.objects.filter(
Q(docbowprofile__is_guest=False) |
Q(docbowprofile__isnull=True)).filter(
email=email_address)
if users:
for user in users:
recipients.append(user)
else:
try:
user = auth_models.User.objects.get(username=username)
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' \
% username
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]
if not len(attachments):
content_errors.append('You must send at least one attached file')

View File

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

View File

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

View File

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