LDAP: consolidate config prefix determination, autofill combo box in settings

This commit is contained in:
Arthur Schiwon 2013-01-24 12:42:28 +01:00
parent b979bf6f1c
commit 96949fc9dd
3 changed files with 15 additions and 17 deletions

View File

@ -23,26 +23,16 @@
OCP\App::registerAdmin('user_ldap', 'settings'); OCP\App::registerAdmin('user_ldap', 'settings');
$query = \OCP\DB::prepare(' $configPrefixes = OCA\user_ldap\lib\Helper::getServerConfigurationPrefixes();
SELECT DISTINCT `configkey` if(count($configPrefixes) == 1) {
FROM `*PREFIX*appconfig` $connector = new OCA\user_ldap\lib\Connection($configPrefixes[0]);
WHERE `configkey` LIKE ?
');
$serverConnections = $query->execute(array('%ldap_login_filter'))->fetchAll();
if(count($serverConnections) == 1) {
$prefix = substr($serverConnections[0]['configkey'], 0, strlen($serverConnections[0]['configkey'])- strlen('ldap_login_filter'));
$connector = new OCA\user_ldap\lib\Connection($prefix);
$userBackend = new OCA\user_ldap\USER_LDAP(); $userBackend = new OCA\user_ldap\USER_LDAP();
$userBackend->setConnector($connector); $userBackend->setConnector($connector);
$groupBackend = new OCA\user_ldap\GROUP_LDAP(); $groupBackend = new OCA\user_ldap\GROUP_LDAP();
$groupBackend->setConnector($connector); $groupBackend->setConnector($connector);
} else { } else {
$prefixes = array(); $userBackend = new OCA\user_ldap\User_Proxy($configPrefixes);
foreach($serverConnections as $serverConnection) { $groupBackend = new OCA\user_ldap\Group_Proxy($configPrefixes);
$prefixes[] = substr($serverConnection['configkey'], 0, strlen($serverConnection['configkey'])- strlen('ldap_login_filter'));
}
$userBackend = new OCA\user_ldap\User_Proxy($prefixes);
$groupBackend = new OCA\user_ldap\Group_Proxy($prefixes);
} }
// register user backend // register user backend

View File

@ -86,7 +86,16 @@ $tmpl->assign('ldap_cache_ttl', OCP\Config::getAppValue('user_ldap', 'ldap_cache
$hfnr = OCP\Config::getAppValue('user_ldap', 'home_folder_naming_rule', 'opt:username'); $hfnr = OCP\Config::getAppValue('user_ldap', 'home_folder_naming_rule', 'opt:username');
$hfnr = ($hfnr == 'opt:username') ? '' : substr($hfnr, strlen('attr:')); $hfnr = ($hfnr == 'opt:username') ? '' : substr($hfnr, strlen('attr:'));
$tmpl->assign('home_folder_naming_rule', $hfnr, ''); $tmpl->assign('home_folder_naming_rule', $hfnr, '');
$tmpl->assign('serverConfigurationOptions', '', false);
$prefixes = \OCA\user_ldap\lib\Helper::getServerConfigurationPrefixes();
$scoHtml = '';
$i = 1;
$sel = ' selected';
foreach($prefixes as $prefix) {
$scoHtml .= '<option value="'.$prefix.'"'.$sel.'>'.$i++.'. Server</option>';
$sel = '';
}
$tmpl->assign('serverConfigurationOptions', $scoHtml, false);
// assign default values // assign default values
if(!isset($ldap)) { if(!isset($ldap)) {

View File

@ -13,7 +13,6 @@
?> ?>
<fieldset id="ldapSettings-1"> <fieldset id="ldapSettings-1">
<p><label for="ldap_serverconfig_chooser"><?php echo $l->t('Server configuration');?></label><select id="ldap_serverconfig_chooser" name="ldap_serverconfig_chooser"> <p><label for="ldap_serverconfig_chooser"><?php echo $l->t('Server configuration');?></label><select id="ldap_serverconfig_chooser" name="ldap_serverconfig_chooser">
<option value="" selected><?php echo $l->t('Default (1. Server)');?></option>
<?php echo $_['serverConfigurationOptions']; ?> <?php echo $_['serverConfigurationOptions']; ?>
<option value="NEW"><?php echo $l->t('Add Server Configuration');?></option> <option value="NEW"><?php echo $l->t('Add Server Configuration');?></option>
</select></p> </select></p>