Untitled
unknown
plain_text
10 months ago
2.6 kB
17
Indexable
all_users = []
ldap_user_ids = set()
# 1️⃣ Fetch LDAP users directly
ldap_plugin = acl_users.get('pasldap')
if ldap_plugin is not None:
conn = ldap_plugin._getConnection() # get raw LDAP connection
base_dn = ldap_plugin.getProperty('users_base') # base DN from plugin
search_filter = "(objectClass=person)" # adjust if needed
attrs = ['cn', 'mail', 'distinguishedName']
try:
result = conn.search_s(base_dn, ldap.SCOPE_SUBTREE, search_filter, attrs)
except ldap.LDAPError:
result = []
for dn, entry in result:
if not entry:
continue
user_id = entry.get('sAMAccountName', [b''])[0].decode() # adjust if needed
if not user_id:
continue
ldap_user_ids.add(user_id)
all_users.append({
'id': user_id,
'fullname': entry.get('cn', [b''])[0].decode(),
'email': entry.get('mail', [b''])[0].decode(),
'area': parse_area(entry.get('distinguishedName', [b''])[0].decode()),
'cargo': '', # will fill from Plone if exists
'telefono': '', # will fill from Plone if exists
'pluginid': 'pasldap',
'portrait': f'/++api++/portrait/{user_id}',
})
# 2️⃣ Merge Plone-only properties
local_plugin = acl_users.get('source_users')
if local_plugin is not None:
local_users = local_plugin.enumerateUsers(id=None, exact_match=False)
for user in local_users:
user_id = user.get('id')
if user_id in ldap_user_ids:
# Merge cargo and telefono into existing LDAP entry
idx = next((i for i, u in enumerate(all_users) if u['id'] == user_id), None)
if idx is not None:
all_users[idx]['cargo'] = user.get('cargo', '')
all_users[idx]['telefono'] = user.get('telefono', '')
continue
# local-only user
all_users.append({
'id': user_id,
'fullname': user.get('fullname', ''),
'email': user.get('email', ''),
'area': user.get('area', ''),
'cargo': user.get('cargo', ''),
'telefono': user.get('telefono', ''),
'pluginid': 'source_users',
'portrait': f'/++api++/portrait/{user_id}',
})
return all_usersEditor is loading...
Leave a Comment