Skip to content

Commit

Permalink
fix diverged userlists between get and post in user removal page
Browse files Browse the repository at this point in the history
  • Loading branch information
claire-peters committed Oct 23, 2023
1 parent 7d26124 commit 3d3e243
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions coldfront/core/project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 3d3e243

Please sign in to comment.