Rename mapping_field to user_mapping_field

This is to be consistent with group_mapping_field. The code is backwards
compatible with mapping_field.

In sync_LDAP_groups assign user_mapping once, not for every group.
This commit is contained in:
Andrew Ruthven 2024-02-03 20:41:30 +13:00
parent 3d28433b5b
commit 56d7d22d86
3 changed files with 20 additions and 6 deletions

View File

@ -704,7 +704,7 @@ $c->admin_email = 'calendar-admin@example.com';
// 'filterGroups' => 'objectClass=groupOfUniqueNames',
/* /!\ "username" should be set and "modified" must be set
* used to create the user based on their ldap properties */
// 'mapping_field' => array(
// 'user_mapping_field' => array(
// "username" => "uid",
// "modified" => "modifyTimestamp",
// "fullname" => "cn",

View File

@ -643,6 +643,14 @@ function sync_LDAP_groups(){
if ( sizeof ( $groups_to_update ) ){
$c->messages[] = sprintf(i18n('- updating groups : %s'),join(', ',$groups_to_update));
// Support the old name of user_mapping_field..
$user_mapping = NULL;
if (isset($c->authenticate_hook['config']['user_mapping_field'])) {
$user_mapping = $c->authenticate_hook['config']['user_mapping_field'];
} else if (isset($c->authenticate_hook['config']['mapping_field'])) {
$user_mapping = $c->authenticate_hook['config']['mapping_field'];
}
foreach ( $groups_to_update as $group ){
$db_members = is_array( $db_group_members[$group] )
? array_values( $db_group_members[$group] )
@ -651,12 +659,10 @@ function sync_LDAP_groups(){
? array_values ( $ldap_groups_info[$group][$member_field] )
: array();
$mapping_field = $c->authenticate_hook['config']['mapping_field'];
if (isset($c->authenticate_hook['config']['group_match_username_attr'])
&& isset($mapping_field['username'])) {
&& isset($user_mapping['username'])) {
$query = $ldapDriver->ldap_query_one;
$username_ldap_attribute = $mapping_field['username'];
$username_ldap_attribute = $user_mapping['username'];
$filter = "(objectCategory=person)";
$ldap_members_tmp = array();
@ -757,7 +763,14 @@ function sync_LDAP(){
$ldapDriver = getStaticLdap();
if ( ! $ldapDriver->valid ) return;
$mapping = $c->authenticate_hook['config']['mapping_field'];
// Support the old name of user_mapping_field.
$mapping = NULL;
if (isset($c->authenticate_hook['config']['user_mapping_field'])) {
$mapping = $c->authenticate_hook['config']['user_mapping_field'];
} else if (isset($c->authenticate_hook['config']['mapping_field'])) {
$mapping = $c->authenticate_hook['config']['mapping_field'];
}
$attributes = array_values_mapping($mapping);
$ldap_users_tmp = $ldapDriver->getAllUsers($attributes);

View File

@ -32,6 +32,7 @@
//ldap 'protocolVersion' => 3,
//ldap 'baseDNUsers' => 'ou=users,dc=example,dc=com',
//ldap 'baseDNGroups' => 'ou=groups,dc=example,dc=com',
// Test with the old name, new name is "user_mapping_field".
//ldap 'mapping_field' => array(
//ldap "username" => "uid",
//ldap "modified" => "modifyTimestamp",