From 37aa4e3720ed4691a557a64d7af49dad1b138727 Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Sat, 18 Sep 2021 17:55:02 -0700 Subject: [PATCH] Show only member and non-member roles under susbcriptions of a user. Since it doesn't make sense to set Moderation and Delivery bit for Owners and Moderators, we are going to filter them from the 'Subscriptions' section of the mange user. Fixes #534 --- src/postorius/doc/news.rst | 2 ++ src/postorius/utils.py | 17 +++++++++++++++++ src/postorius/views/user.py | 6 ++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/postorius/doc/news.rst b/src/postorius/doc/news.rst index 716146c2..e5723807 100644 --- a/src/postorius/doc/news.rst +++ b/src/postorius/doc/news.rst @@ -82,6 +82,8 @@ Other can use a single implementation that uses caching for efficient lookups. * Bump bundled jQuery to 3.6.0.slim version. (See !637) * Use the full jQuery not the slim version. (Closes #523) +* Do not show Ownerships and Moderator roles in the 'Subscriptions' page + under mange new user interface. (Closes #534) Ascessibility ------------- diff --git a/src/postorius/utils.py b/src/postorius/utils.py index 710a360d..b8f5f28d 100644 --- a/src/postorius/utils.py +++ b/src/postorius/utils.py @@ -125,6 +125,23 @@ def get_django_user(mm_user, addresses=None): return django_email.user +def filter_memberships_by_roles(memberships, roles): + """Given a list of roles, filter the memberships with those roles. + + :param memberships: A list of Member objects. + :type memberships: List[mailmanclient.restobjects.Member] + :param roles: A list of roles. + :type roles: List[str] + :returns: A list of memberships filtered by roles. + :rtype: List[mailmanclient.restobjects.Member] + """ + return [ + member + for member in memberships + if member.role in roles + ] + + LANGUAGES = ( ('ar', 'Arabic'), ('ast', 'Asturian'), diff --git a/src/postorius/views/user.py b/src/postorius/views/user.py index 04d38cce..6a516c9e 100644 --- a/src/postorius/views/user.py +++ b/src/postorius/views/user.py @@ -43,7 +43,8 @@ from postorius.forms import ( ManageMemberForm, ManageMemberFormSet, ManageUserForm, UserPreferences, UserPreferencesFormset) from postorius.models import List, SubscriptionMode -from postorius.utils import get_django_user, set_preferred +from postorius.utils import ( + filter_memberships_by_roles, get_django_user, set_preferred) from postorius.views.generic import MailmanClientMixin @@ -382,7 +383,8 @@ def manage_user(request, user_id): ManageMemberForm, formset=ManageMemberFormSet, extra=0) django_user = get_django_user(user) addresses = addr_formset(addresses=user.addresses) - subscriptions = sub_formset(members=user.subscriptions) + subscriptions = sub_formset(members=filter_memberships_by_roles( + user.subscriptions, roles=['member', 'nonmember'])) change_password = None if django_user is not None: -- 2.11.4.GIT