plone / Products.CMFPlone

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

Could not add usergroup into another usergroup #3006

Closed mliebischer closed 1 year ago

mliebischer commented 4 years ago

It is currently not possible to add a usergroup into another usergroup. An exception is raised (see below). I am not sure whether it is intended nowadays to have group in groups. In any case, this should be fixed, or if this is not the intended behavior, a user-friendly error message should be displayed instead (e.g. "It is not supported to add groups to groups").

What I did:

What I expect to happen:

The group should be added to the list of current group members.

What actually happened:

An error message is shown:

Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 155, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 337, in publish_module
  Module ZPublisher.WSGIPublisher, line 255, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 61, in call_object
  Module Products.CMFPlone.controlpanel.browser.usergroups_groupmembership, line 77, in __call__
  Module Products.CMFPlone.controlpanel.browser.usergroups_groupmembership, line 74, in update
  Module Products.CMFPlone.controlpanel.browser.usergroups_groupmembership, line 87, in getMembers
TypeError: '<' not supported between instances of 'str' and 'bool'

What version of Plone/ Addons I am using:

Seem like the code of Products.CMFPlone 5.2.1rc2 has the same bug, but I have only tested it with 5.2.0.

Also reproducible on demo.plone.org (Plone 5.2.0), see http://demo.plone.org/@@usergroup-groupmembership?groupname=Administrators

Possible cause:

The cause of this error seems to be in Products.CMFPlone.controlpanel.browser.usergroups_groupmembership.GroupMembershipControlPanel.getMembers. The code tries to sort a list of None's and GroupData entries against a sort function that returns false if entry is None or the normalized group title.

# searchResults =>['user1', 'user2', 'user3', 'Reviewers']
# groupResults => [None, None, None, <GroupData at /site/portal_groupdata/Reviewers used for /site/acl_users/source_groups>]
groupResults.sort(key=lambda x: x is not None and normalizeString(
            x.getGroupTitleOrName()))

Which lead us to the 'str' and 'bool' type error.

Possible fix:

Clean up groupResults and userResults before sorting them by removing any "None" entries from it.

    def getMembers(self):
        searchResults = self.gtool.getGroupMembers(self.groupname)

        groupResults = [self.gtool.getGroupById(m) for m in searchResults]
        groupResults = [x for x in groupResults if x]  ## Removes "None" entries before sorting
        groupResults.sort(key=lambda x: x is not None and normalizeString(
            x.getGroupTitleOrName()))

        userResults = [self.mtool.getMemberById(m) for m in searchResults]
        userResults = [x for x in userResults if x]  ## Removes "None" entries before sorting
        userResults.sort(key=lambda x: x is not None and x.getProperty(
            'fullname') is not None and normalizeString(x.getProperty('fullname')) or '')

        mergedResults = groupResults + userResults
        return [i for i in mergedResults if i]
mauritsvanrees commented 4 years ago

I cannot reproduce this locally with latest development versions of Plone. But on the demo site and one client site with 5.2.0 I can reproduce this.

The code has not changed since over a year, but possibly this was fixed somewhere else in the stack.

I may check later.

jensens commented 1 year ago

this was fixed