plone / plone.api

The Plone API
https://6.docs.plone.org/plone.api
Other
86 stars 53 forks source link

api.user does not find LDAP users #359

Open ramonski opened 7 years ago

ramonski commented 7 years ago

Description

Having LDAP in place, the api.user.get_users() or api.user.get_users(ldapuserid) mothods do not return anything, but the LDAP users get found and listed in the user and groups control panel at /@@usergroup-userprefs.

szakitibi commented 5 years ago

get_user() method works, but it uses a different method to "hunt" the users in the user folders.

While get_users() fails to list LDAP users, but the problem is in the underlying method here:

https://github.com/plone/plone.api/blob/1e4acfbc2e75561c4885e1c5089b19aaed1ab25e/src/plone/api/user.py#L173

When pas.plugins.ldap add-on is activated, the ṗortal_membership.listMembers returns an empty list. It is not PAS plug-in aware.

A workaround would be:

md = getToolByName(api.portal.get(), 'portal_memberdata')
pm = getToolByName(api.portal.get(), 'portal_membership')
return all_members = [pm.getMemberById(userid) for userid in md._members.keys()]

Although I'm not sure if it is the fastest one.

ramonski commented 5 years ago

Hi @szakitibi, thanks for pointing this code out! We'll probably use your code it in our own API unless we find a better way to do it: https://github.com/senaite/senaite.core/blob/master/bika/lims/api/__init__.py#L956