From 13083b07e8faa0ccc7e7f3a91ba5ede40bf259a2 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Sat, 3 Feb 2024 20:03:49 +1300 Subject: [PATCH] Rename username to name in group mappings, drop unused fullname from example Usinger "username" for the group name is confusing and misleading. Just use name, but support our users who still have username. We don't use fullname, drop it from the example. --- config/example-config.php | 3 +-- inc/drivers_ldap.php | 12 ++++++++++-- testing/regression-conf.php.example | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/config/example-config.php b/config/example-config.php index 1b2fc141..4175c22e 100644 --- a/config/example-config.php +++ b/config/example-config.php @@ -712,9 +712,8 @@ $c->admin_email = 'calendar-admin@example.com'; // ), /* used to create the group based on the ldap properties */ // 'group_mapping_field' => array( -// "username" => "cn", +// "name" => "cn", // "modified" => "modifyTimestamp", -// "fullname" => "cn", // "members" => "member" // ), diff --git a/inc/drivers_ldap.php b/inc/drivers_ldap.php index 9d3cc381..944fbc7b 100644 --- a/inc/drivers_ldap.php +++ b/inc/drivers_ldap.php @@ -498,6 +498,14 @@ function sync_LDAP_groups(){ if ( ! $ldapDriver->valid ) return; $mapping = $c->authenticate_hook['config']['group_mapping_field']; + + // Old config (pre 1.1.13) used "username" as the group name, if that is in + // use, copy it to the new name: name. + if ( ! isset($mapping['name']) && isset($mapping['username']) ) { + $mapping['name'] = $mapping['username']; + unset($mapping['username']); + } + $attributes = array_values_mapping($mapping); $ldap_groups_tmp = $ldapDriver->getAllGroups($attributes); @@ -510,8 +518,8 @@ function sync_LDAP_groups(){ $dnfix = isset($c->authenticate_hook['config']['group_member_dnfix']) && $c->authenticate_hook['config']['group_member_dnfix']; - foreach($ldap_groups_tmp as $key => $ldap_group){ - $group_mapping = $ldap_group[$mapping['username']]; + foreach ($ldap_groups_tmp as $key => $ldap_group) { + $group_name = $ldap_group[$mapping['name']]; $ldap_groups_info[$group_mapping] = $ldap_group; if ( isset($ldap_groups_info[$group_mapping][$member_field]) ) { diff --git a/testing/regression-conf.php.example b/testing/regression-conf.php.example index 69de7d72..d14c7b89 100644 --- a/testing/regression-conf.php.example +++ b/testing/regression-conf.php.example @@ -39,9 +39,9 @@ //ldap "email" => "mail" //ldap ), //ldap 'group_mapping_field' => array( + // Test with the old name, new name is "name"" //ldap "username" => "cn", //ldap "modified" => "modifyTimestamp", - //ldap "fullname" => "cn" , //ldap "members" => "memberUid", //ldap ), //ldap 'format_updated' => array(