plone / Products.CMFPlone

The core of the Plone content management system
https://plone.org
GNU General Public License v2.0
252 stars 188 forks source link

Can't add an user in UserGroupsControlpanelView to a Group with pas.plugin.ldap with plone.many_users=True #3790

Closed 1letter closed 1 year ago

1letter commented 1 year ago

What I did:

What I expect to happen:

What actually happened:

What version of Plone/ Addons I am using:

Some investigations

the GroupMembershipControlPanel clean the searchstring in the request and pass it to the membership search in UsersGroupsControlPanelView.

An empty searchstring is like a intention "list all users" and a violation against the option many_users = True. The search with empty searchstring should not be performed.

With the following patch, all is fine ;-)

if searchGroups:
  if not self.many_groups or bool(searchString):
    groupResults = searchView.merge(chain(*[searchView.searchGroups(**{field: searchString}) for field in ['id', 'title']]), 'groupid')
    groupResults = [gtool.getGroupById(g['id']) for g in groupResults if g['id'] not in ignore]
    groupResults.sort(key=lambda x: x is not None and normalizeString(x.getGroupTitleOrName()))

  if searchUsers:
    if not self.many_users or bool(searchString):
      userResults = searchView.merge(chain(*[searchView.searchUsers(**{field: searchString}) for field in ['login', 'fullname', 'email']]), 'userid')
      userResults = [mtool.getMemberById(u['id']) for u in userResults if u['id'] not in ignore]
      userResults.sort(key=lambda x: x is not None and x.getProperty('fullname') is not None and normalizeString(x.getProperty('fullname')) or '')