From 81bcb7176c1fdcd4486f411ee058f4a10e947746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20A=2E=20S=C3=A1nchez=20L=C3=B3pez?= Date: Fri, 13 Aug 2010 12:07:45 +0000 Subject: [PATCH] Users only belong to automatic groups if the group is retrieved from the correct source. Fixes #360 - Legacy-Id: 2477 --- ietf/ietfauth/auth.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ietf/ietfauth/auth.py b/ietf/ietfauth/auth.py index f24028122..e232fd46e 100644 --- a/ietf/ietfauth/auth.py +++ b/ietf/ietfauth/auth.py @@ -39,6 +39,9 @@ from ietf.ietfauth.models import IetfUserProfile from ietf.utils import log +AUTOMATIC_GROUPS = ["Area_Director", "Secretariat", "IETF_Chair", + "IAB_Chair", "IRTF_Chair", ] + class IetfUserBackend(RemoteUserBackend): def find_groups(username): @@ -56,6 +59,8 @@ class IetfUserBackend(RemoteUserBackend): Session_Chair chairing a non-WG session in IETF meeting Ex_Area_Director past AD """ + # Any group name added by this method should be added to the + # AUTOMATIC_GROUPS list groups = [] try: login = IESGLogin.objects.get(login_name=username) @@ -97,6 +102,10 @@ class IetfUserBackend(RemoteUserBackend): profile = IetfUserProfile(user=user) profile.save() + # Remove any automatic groups, the proper ones will be retrieved by + # find_groups + groups = [group for group in user.groups.exclude(name__in=AUTOMATIC_GROUPS)] + # Update group memberships group_names = IetfUserBackend.find_groups(user.username) for group_name in group_names: @@ -104,6 +113,6 @@ class IetfUserBackend(RemoteUserBackend): group,created = Group.objects.get_or_create(name=group_name) if created: log("IetfUserBackend created Group '%s'" % (group_name,)) - user.groups.add(group) + groups.append(group) + user.groups = groups return user -