From 3d3e24394996b0beb7bd5e5749d8dc8c06d38649 Mon Sep 17 00:00:00 2001 From: Claire Peters Date: Mon, 23 Oct 2023 13:00:35 -0700 Subject: [PATCH] fix diverged userlists between get and post in user removal page --- coldfront/core/project/views.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/coldfront/core/project/views.py b/coldfront/core/project/views.py index 8fb5d4baf..085aef9b9 100644 --- a/coldfront/core/project/views.py +++ b/coldfront/core/project/views.py @@ -772,7 +772,7 @@ def get(self, request, *args, **kwargs): users_to_remove = self.get_users_to_remove(project_obj) users_no_removal = None - # if ldap is activated, prevent + # if ldap is activated, prevent selection of users with project corresponding to primary group if 'coldfront.plugins.ldap' in settings.INSTALLED_APPS: usernames = [u['username'] for u in users_to_remove] @@ -800,13 +800,21 @@ def post(self, request, *args, **kwargs): project_obj = get_object_or_404(Project, pk=pk) users_to_remove = self.get_users_to_remove(project_obj) + # if ldap is activated, prevent selection of users with project corresponding to primary group + if 'coldfront.plugins.ldap' in settings.INSTALLED_APPS: + + usernames = [u['username'] for u in users_to_remove] + ldap_conn = LDAPConn() + users_main_group = ldap_conn.users_in_primary_group( + usernames, project_obj.title) + ingroup = lambda u: u['username'] in users_main_group + users_no_removal, users_to_remove = sort_by(users_to_remove, ingroup, how="condition") + formset = formset_factory(ProjectRemoveUserForm, max_num=len(users_to_remove)) formset = formset(request.POST, initial=users_to_remove, prefix='userform') remove_users_count = 0 - if 'coldfront.plugins.ldap' in settings.INSTALLED_APPS: - ldap_conn = LDAPConn() if formset.is_valid(): projectuser_status_removed = ProjectUserStatusChoice.objects.get(