diff --git a/src/postorius/templates/postorius/user_profile.html b/src/postorius/templates/postorius/user_profile.html
index 4376b7c..1a0972f 100644
--- a/src/postorius/templates/postorius/user_profile.html
+++ b/src/postorius/templates/postorius/user_profile.html
@@ -27,7 +27,7 @@
{% trans 'Other emails' %} |
- {% for email in other_emails %}
+ {% for email in user.other_emails %}
- {{ email }}
{% endfor %}
|
diff --git a/src/postorius/utils.py b/src/postorius/utils.py
index 37a4011..5270543 100644
--- a/src/postorius/utils.py
+++ b/src/postorius/utils.py
@@ -43,6 +43,7 @@
"Please start Mailman core."},
context_instance=RequestContext(request))
+
def paginate(request, collection, count=20):
# count is the number of items per page
paginator = Paginator(collection, count)
@@ -56,3 +57,21 @@
# If page is out of range (e.g. 9999), deliver last page of results.
results = paginator.page(paginator.num_pages)
return results
+
+
+def set_other_emails(user):
+ from postorius.models import MailmanUser, MailmanApiError, Mailman404Error
+ user.other_emails = []
+ if not user.is_authenticated():
+ return
+ try:
+ mm_user = MailmanUser.objects.get(address=user.email)
+ user.other_emails = [str(address) for address in mm_user.addresses
+ if address.verified_on is not None]
+ except (MailmanApiError, Mailman404Error, AttributeError):
+ # MailmanApiError: No connection to Mailman
+ # Mailman404Error: The user does not have a mailman user associated with it.
+ # AttributeError: Anonymous user
+ return
+ if user.email in user.other_emails:
+ user.other_emails.remove(user.email)
diff --git a/src/postorius/views/generic.py b/src/postorius/views/generic.py
index e97fb45..647e601 100644
--- a/src/postorius/views/generic.py
+++ b/src/postorius/views/generic.py
@@ -48,18 +48,12 @@
def _get_list(self, list_id, page):
return List.objects.get_or_404(fqdn_listname=list_id)
- def _is_list_owner(self, user, mailing_list):
+ def _is_in_list_roster(self, user, mailing_list, roster):
if not user.is_authenticated():
return False
- if user.email in mailing_list.owners:
- return True
- return False
-
- def _is_list_moderator(self, user, mailing_list):
- if not user.is_authenticated():
- return False
- if user.email in mailing_list.moderators:
- return True
+ addresses = set(user.email) | set(user.other_emails)
+ if addresses & set(getattr(mailing_list, roster)):
+ return True # At least one address is in the roster
return False
def dispatch(self, request, *args, **kwargs):
@@ -70,10 +64,11 @@
int(kwargs.get('page', 1)))
except MailmanApiError:
return utils.render_api_error(request)
- request.user.is_list_owner = self._is_list_owner(
- request.user, self.mailing_list)
- request.user.is_list_moderator = self._is_list_moderator(
- request.user, self.mailing_list)
+ utils.set_other_emails(request.user)
+ request.user.is_list_owner = self._is_in_list_roster(
+ request.user, self.mailing_list, "owners")
+ request.user.is_list_moderator = self._is_in_list_roster(
+ request.user, self.mailing_list, "moderators")
# set the template
if 'template' in kwargs:
self.template = kwargs['template']
diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py
index ec65272..37149cf 100644
--- a/src/postorius/views/list.py
+++ b/src/postorius/views/list.py
@@ -178,10 +178,8 @@
def get(self, request, list_id):
try:
mm_user = MailmanUser.objects.get(address=request.user.email)
- user_emails = [str(address) for address in getattr(mm_user, 'addresses')]
- # TODO:maxking - add the clause below in above
- # statement after the subscription policy is sorted out
- # if address.verified_on is not None]
+ user_emails = [str(address) for address in mm_user.addresses
+ if address.verified_on is not None]
except Mailman404Error:
# The user does not have a mailman user associated with it.
user_emails = [request.user.email]
diff --git a/src/postorius/views/user.py b/src/postorius/views/user.py
index c94133d..ece5def 100644
--- a/src/postorius/views/user.py
+++ b/src/postorius/views/user.py
@@ -304,22 +304,13 @@
@login_required()
def user_profile(request, user_email=None):
+ utils.set_other_emails(request.user)
try:
mm_user = MailmanUser.objects.get(address=request.user.email)
- other_emails = [
- str(address) for address in mm_user.addresses
- if address.verified_on is not None
- ]
- if request.user.email in other_emails:
- other_emails.remove(request.user.email)
- except MailmanApiError:
+ except MailmanApiError:
return utils.render_api_error(request)
- except Mailman404Error:
- # The user does not have a mailman user associated with it.
- user_emails = []
return render_to_response('postorius/user_profile.html',
- {'mm_user': mm_user,
- 'other_emails': other_emails},
+ {'mm_user': mm_user},
context_instance=RequestContext(request))