Added support for language LDAP attribute

This commit is contained in:
Frederic Guillot
2016-05-07 18:05:33 -04:00
parent aac11a609c
commit 55ee906ba3
28 changed files with 400 additions and 258 deletions

View File

@@ -12,7 +12,7 @@ class App extends \Kanboard\Core\Base
{
public function getTimezone()
{
return $this->config->get('application_timezone');
return $this->timezone->getCurrentTimezone();
}
public function getVersion()

View File

@@ -42,7 +42,7 @@ class Config extends Base
}
if ($this->config->save($values)) {
$this->config->reload();
$this->language->loadCurrentLanguage();
$this->flash->success(t('Settings saved successfully.'));
} else {
$this->flash->failure(t('Unable to save your settings.'));
@@ -90,8 +90,8 @@ class Config extends Base
$this->common('application');
$this->response->html($this->helper->layout->config('config/application', array(
'languages' => $this->config->getLanguages(),
'timezones' => $this->config->getTimezones(),
'languages' => $this->language->getLanguages(),
'timezones' => $this->timezone->getTimezones(),
'date_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateFormats()),
'datetime_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getDateTimeFormats()),
'time_formats' => $this->dateParser->getAvailableFormats($this->dateParser->getTimeFormats()),

View File

@@ -59,7 +59,6 @@ class Currency extends Base
$values = $this->request->getValues();
if ($this->config->save($values)) {
$this->config->reload();
$this->flash->success(t('Settings saved successfully.'));
} else {
$this->flash->failure(t('Unable to save your settings.'));

View File

@@ -20,7 +20,7 @@ class Doc extends Base
$page = 'index';
}
if ($this->config->getCurrentLanguage() === 'fr_FR') {
if ($this->language->getCurrentLanguage() === 'fr_FR') {
$filename = __DIR__.'/../../doc/fr/' . $page . '.markdown';
} else {
$filename = __DIR__ . '/../../doc/' . $page . '.markdown';
@@ -83,7 +83,7 @@ class Doc extends Base
*/
public function replaceImageUrl(array $matches)
{
if ($this->config->getCurrentLanguage() === 'fr_FR') {
if ($this->language->getCurrentLanguage() === 'fr_FR') {
return '('.$this->helper->url->base().'doc/fr/'.$matches[1].')';
}

View File

@@ -67,8 +67,8 @@ class User extends Base
$is_remote = $this->request->getIntegerParam('remote') == 1 || (isset($values['is_ldap_user']) && $values['is_ldap_user'] == 1);
$this->response->html($this->helper->layout->app($is_remote ? 'user/create_remote' : 'user/create_local', array(
'timezones' => $this->config->getTimezones(true),
'languages' => $this->config->getLanguages(true),
'timezones' => $this->timezone->getTimezones(true),
'languages' => $this->language->getLanguages(true),
'roles' => $this->role->getApplicationRoles(),
'projects' => $this->project->getList(),
'errors' => $errors,
@@ -121,8 +121,8 @@ class User extends Base
$user = $this->getUser();
$this->response->html($this->helper->layout->user('user/show', array(
'user' => $user,
'timezones' => $this->config->getTimezones(true),
'languages' => $this->config->getLanguages(true),
'timezones' => $this->timezone->getTimezones(true),
'languages' => $this->language->getLanguages(true),
)));
}
@@ -247,7 +247,7 @@ class User extends Base
$this->response->html($this->helper->layout->user('user/integrations', array(
'user' => $user,
'values' => $this->userMetadata->getall($user['id']),
'values' => $this->userMetadata->getAll($user['id']),
)));
}
@@ -365,8 +365,8 @@ class User extends Base
'values' => $values,
'errors' => $errors,
'user' => $user,
'timezones' => $this->config->getTimezones(true),
'languages' => $this->config->getLanguages(true),
'timezones' => $this->timezone->getTimezones(true),
'languages' => $this->language->getLanguages(true),
'roles' => $this->role->getApplicationRoles(),
)));
}

View File

@@ -65,6 +65,7 @@ use Pimple\Container;
* @property \Kanboard\Model\ProjectFile $projectFile
* @property \Kanboard\Model\Group $group
* @property \Kanboard\Model\GroupMember $groupMember
* @property \Kanboard\Model\Language $language
* @property \Kanboard\Model\LastLogin $lastLogin
* @property \Kanboard\Model\Link $link
* @property \Kanboard\Model\Notification $notification
@@ -95,6 +96,7 @@ use Pimple\Container;
* @property \Kanboard\Model\TaskPosition $taskPosition
* @property \Kanboard\Model\TaskStatus $taskStatus
* @property \Kanboard\Model\TaskMetadata $taskMetadata
* @property \Kanboard\Model\Timezone $timezone
* @property \Kanboard\Model\Transition $transition
* @property \Kanboard\Model\User $user
* @property \Kanboard\Model\UserLocking $userLocking

View File

@@ -146,7 +146,8 @@ class User
$entry->getFirstValue($this->getAttributeEmail()),
$this->getRole($groupIds),
$groupIds,
$entry->getFirstValue($this->getAttributePhoto())
$entry->getFirstValue($this->getAttributePhoto()),
$entry->getFirstValue($this->getAttributeLanguage())
);
}
@@ -166,6 +167,7 @@ class User
$this->getAttributeEmail(),
$this->getAttributeGroup(),
$this->getAttributePhoto(),
$this->getAttributeLanguage(),
)));
}
@@ -236,6 +238,17 @@ class User
return strtolower(LDAP_USER_ATTRIBUTE_PHOTO);
}
/**
* Get LDAP language attribute
*
* @access public
* @return string
*/
public function getAttributeLanguage()
{
return strtolower(LDAP_USER_ATTRIBUTE_LANGUAGE);
}
/**
* Get LDAP Group User filter
*

View File

@@ -44,7 +44,7 @@ class TaskCalendarFormatter extends BaseTaskCalendarFormatter implements Formatt
foreach ($this->query->findAll() as $task) {
$events[] = array(
'timezoneParam' => $this->config->getCurrentTimezone(),
'timezoneParam' => $this->timezone->getCurrentTimezone(),
'id' => $task['id'],
'title' => t('#%d', $task['id']).' '.$task['title'],
'backgroundColor' => $this->color->getBackgroundColor($task['color_id']),

View File

@@ -90,7 +90,7 @@ class AppHelper extends Base
*/
public function jsLang()
{
return $this->config->getJsLanguageCode();
return $this->language->getJsLanguageCode();
}
/**
@@ -101,7 +101,7 @@ class AppHelper extends Base
*/
public function getTimezone()
{
return $this->config->getCurrentTimezone();
return $this->timezone->getCurrentTimezone();
}
/**

View File

@@ -2,7 +2,6 @@
namespace Kanboard\Model;
use Kanboard\Core\Translator;
use Kanboard\Core\Security\Token;
/**
@@ -14,162 +13,7 @@ use Kanboard\Core\Security\Token;
class Config extends Setting
{
/**
* Get available timezones
*
* @access public
* @param boolean $prepend Prepend a default value
* @return array
*/
public function getTimezones($prepend = false)
{
$timezones = timezone_identifiers_list();
$listing = array_combine(array_values($timezones), $timezones);
if ($prepend) {
return array('' => t('Application default')) + $listing;
}
return $listing;
}
/**
* Get current timezone
*
* @access public
* @return string
*/
public function getCurrentTimezone()
{
if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['timezone'])) {
return $this->sessionStorage->user['timezone'];
}
return $this->get('application_timezone', 'UTC');
}
/**
* Set timezone
*
* @access public
*/
public function setupTimezone()
{
date_default_timezone_set($this->getCurrentTimezone());
}
/**
* Get available languages
*
* @access public
* @param boolean $prepend Prepend a default value
* @return array
*/
public function getLanguages($prepend = false)
{
// Sorted by value
$languages = array(
'id_ID' => 'Bahasa Indonesia',
'bs_BA' => 'Bosanski',
'cs_CZ' => 'Čeština',
'da_DK' => 'Dansk',
'de_DE' => 'Deutsch',
'en_US' => 'English',
'es_ES' => 'Español',
'fr_FR' => 'Français',
'el_GR' => 'Grec',
'it_IT' => 'Italiano',
'hu_HU' => 'Magyar',
'my_MY' => 'Melayu',
'nl_NL' => 'Nederlands',
'nb_NO' => 'Norsk',
'pl_PL' => 'Polski',
'pt_PT' => 'Português',
'pt_BR' => 'Português (Brasil)',
'ru_RU' => 'Русский',
'sr_Latn_RS' => 'Srpski',
'fi_FI' => 'Suomi',
'sv_SE' => 'Svenska',
'tr_TR' => 'Türkçe',
'ko_KR' => '한국어',
'zh_CN' => '中文(简体)',
'ja_JP' => '日本語',
'th_TH' => 'ไทย',
);
if ($prepend) {
return array('' => t('Application default')) + $languages;
}
return $languages;
}
/**
* Get javascript language code
*
* @access public
* @return string
*/
public function getJsLanguageCode()
{
$languages = array(
'cs_CZ' => 'cs',
'da_DK' => 'da',
'de_DE' => 'de',
'en_US' => 'en',
'es_ES' => 'es',
'fr_FR' => 'fr',
'it_IT' => 'it',
'hu_HU' => 'hu',
'nl_NL' => 'nl',
'nb_NO' => 'nb',
'pl_PL' => 'pl',
'pt_PT' => 'pt',
'pt_BR' => 'pt-br',
'ru_RU' => 'ru',
'sr_Latn_RS' => 'sr',
'fi_FI' => 'fi',
'sv_SE' => 'sv',
'tr_TR' => 'tr',
'ko_KR' => 'ko',
'zh_CN' => 'zh-cn',
'ja_JP' => 'ja',
'th_TH' => 'th',
'id_ID' => 'id',
'el_GR' => 'el',
);
$lang = $this->getCurrentLanguage();
return isset($languages[$lang]) ? $languages[$lang] : 'en';
}
/**
* Get current language
*
* @access public
* @return string
*/
public function getCurrentLanguage()
{
if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['language'])) {
return $this->sessionStorage->user['language'];
}
return $this->get('application_language', 'en_US');
}
/**
* Load translations
*
* @access public
*/
public function setupTranslations()
{
Translator::load($this->getCurrentLanguage());
}
/**
* Get a config variable from the session or the database
* Get a config variable with in-memory caching
*
* @access public
* @param string $name Parameter name
@@ -182,16 +26,6 @@ class Config extends Setting
return isset($options[$name]) && $options[$name] !== '' ? $options[$name] : $default_value;
}
/**
* Reload settings in the session and the translations
*
* @access public
*/
public function reload()
{
$this->setupTranslations();
}
/**
* Optimize the Sqlite database
*
@@ -200,7 +34,7 @@ class Config extends Setting
*/
public function optimizeDatabase()
{
return $this->db->getconnection()->exec('VACUUM');
return $this->db->getConnection()->exec('VACUUM');
}
/**

178
app/Model/Language.php Normal file
View File

@@ -0,0 +1,178 @@
<?php
namespace Kanboard\Model;
use Kanboard\Core\Translator;
/**
* Class Language
*
* @package Kanboard\Model
* @author Frederic Guillot
*/
class Language extends Base
{
/**
* Get all language codes
*
* @static
* @access public
* @return string[]
*/
public static function getCodes()
{
return array(
'id_ID',
'bs_BA',
'cs_CZ',
'da_DK',
'de_DE',
'en_US',
'es_ES',
'fr_FR',
'el_GR',
'it_IT',
'hu_HU',
'my_MY',
'nl_NL',
'nb_NO',
'pl_PL',
'pt_PT',
'pt_BR',
'ru_RU',
'sr_Latn_RS',
'fi_FI',
'sv_SE',
'tr_TR',
'ko_KR',
'zh_CN',
'ja_JP',
'th_TH',
);
}
/**
* Find language code
*
* @static
* @access public
* @param string $code
* @return string
*/
public static function findCode($code)
{
$code = str_replace('-', '_', $code);
return in_array($code, self::getCodes()) ? $code : '';
}
/**
* Get available languages
*
* @access public
* @param boolean $prepend Prepend a default value
* @return array
*/
public function getLanguages($prepend = false)
{
// Sorted by value
$languages = array(
'id_ID' => 'Bahasa Indonesia',
'bs_BA' => 'Bosanski',
'cs_CZ' => 'Čeština',
'da_DK' => 'Dansk',
'de_DE' => 'Deutsch',
'en_US' => 'English',
'es_ES' => 'Español',
'fr_FR' => 'Français',
'el_GR' => 'Grec',
'it_IT' => 'Italiano',
'hu_HU' => 'Magyar',
'my_MY' => 'Melayu',
'nl_NL' => 'Nederlands',
'nb_NO' => 'Norsk',
'pl_PL' => 'Polski',
'pt_PT' => 'Português',
'pt_BR' => 'Português (Brasil)',
'ru_RU' => 'Русский',
'sr_Latn_RS' => 'Srpski',
'fi_FI' => 'Suomi',
'sv_SE' => 'Svenska',
'tr_TR' => 'Türkçe',
'ko_KR' => '한국어',
'zh_CN' => '中文(简体)',
'ja_JP' => '日本語',
'th_TH' => 'ไทย',
);
if ($prepend) {
return array('' => t('Application default')) + $languages;
}
return $languages;
}
/**
* Get javascript language code
*
* @access public
* @return string
*/
public function getJsLanguageCode()
{
$languages = array(
'cs_CZ' => 'cs',
'da_DK' => 'da',
'de_DE' => 'de',
'en_US' => 'en',
'es_ES' => 'es',
'fr_FR' => 'fr',
'it_IT' => 'it',
'hu_HU' => 'hu',
'nl_NL' => 'nl',
'nb_NO' => 'nb',
'pl_PL' => 'pl',
'pt_PT' => 'pt',
'pt_BR' => 'pt-br',
'ru_RU' => 'ru',
'sr_Latn_RS' => 'sr',
'fi_FI' => 'fi',
'sv_SE' => 'sv',
'tr_TR' => 'tr',
'ko_KR' => 'ko',
'zh_CN' => 'zh-cn',
'ja_JP' => 'ja',
'th_TH' => 'th',
'id_ID' => 'id',
'el_GR' => 'el',
);
$lang = $this->getCurrentLanguage();
return isset($languages[$lang]) ? $languages[$lang] : 'en';
}
/**
* Get current language
*
* @access public
* @return string
*/
public function getCurrentLanguage()
{
if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['language'])) {
return $this->sessionStorage->user['language'];
}
return $this->config->get('application_language', 'en_US');
}
/**
* Load translations for the current language
*
* @access public
*/
public function loadCurrentLanguage()
{
Translator::load($this->getCurrentLanguage());
}
}

56
app/Model/Timezone.php Normal file
View File

@@ -0,0 +1,56 @@
<?php
namespace Kanboard\Model;
/**
* Class Timezone
*
* @package Kanboard\Model
* @author Frederic Guillot
*/
class Timezone extends Base
{
/**
* Get available timezones
*
* @access public
* @param boolean $prepend Prepend a default value
* @return array
*/
public function getTimezones($prepend = false)
{
$timezones = timezone_identifiers_list();
$listing = array_combine(array_values($timezones), $timezones);
if ($prepend) {
return array('' => t('Application default')) + $listing;
}
return $listing;
}
/**
* Get current timezone
*
* @access public
* @return string
*/
public function getCurrentTimezone()
{
if ($this->userSession->isLogged() && ! empty($this->sessionStorage->user['timezone'])) {
return $this->sessionStorage->user['timezone'];
}
return $this->config->get('application_timezone', 'UTC');
}
/**
* Set timezone
*
* @access public
*/
public function setCurrentTimezone()
{
date_default_timezone_set($this->getCurrentTimezone());
}
}

View File

@@ -54,7 +54,7 @@ class UserNotification extends Base
}
// Restore locales
$this->config->setupTranslations();
$this->language->loadCurrentLanguage();
}
/**

View File

@@ -35,6 +35,7 @@ class ClassProvider implements ServiceProviderInterface
'CustomFilter',
'Group',
'GroupMember',
'Language',
'LastLogin',
'Link',
'Notification',
@@ -66,6 +67,7 @@ class ClassProvider implements ServiceProviderInterface
'TaskPosition',
'TaskStatus',
'TaskMetadata',
'Timezone',
'Transition',
'User',
'UserLocking',

View File

@@ -16,8 +16,8 @@ class BootstrapSubscriber extends BaseSubscriber implements EventSubscriberInter
public function execute()
{
$this->logger->debug('Subscriber executed: '.__METHOD__);
$this->config->setupTranslations();
$this->config->setupTimezone();
$this->language->loadCurrentLanguage();
$this->timezone->setCurrentTimezone();
$this->actionManager->attachEvents();
if ($this->userSession->isLogged()) {

View File

@@ -3,6 +3,7 @@
namespace Kanboard\User;
use Kanboard\Core\User\UserProviderInterface;
use Kanboard\Model\Language;
/**
* LDAP User Provider
@@ -68,6 +69,14 @@ class LdapUserProvider implements UserProviderInterface
*/
protected $photo = '';
/**
* User language
*
* @access protected
* @var string
*/
protected $language = '';
/**
* Constructor
*
@@ -80,7 +89,7 @@ class LdapUserProvider implements UserProviderInterface
* @param string[] $groupIds
* @param string $photo
*/
public function __construct($dn, $username, $name, $email, $role, array $groupIds, $photo = '')
public function __construct($dn, $username, $name, $email, $role, array $groupIds, $photo = '', $language = '')
{
$this->dn = $dn;
$this->username = $username;
@@ -89,6 +98,7 @@ class LdapUserProvider implements UserProviderInterface
$this->role = $role;
$this->groupIds = $groupIds;
$this->photo = $photo;
$this->language = $language;
}
/**
@@ -198,9 +208,13 @@ class LdapUserProvider implements UserProviderInterface
*/
public function getExtraAttributes()
{
return array(
'is_ldap_user' => 1,
);
$attributes = array('is_ldap_user' => 1);
if (! empty($this->language)) {
$attributes['language'] = Language::findCode($this->language);
}
return $attributes;
}
/**

View File

@@ -65,6 +65,7 @@ defined('LDAP_USER_ATTRIBUTE_FULLNAME') or define('LDAP_USER_ATTRIBUTE_FULLNAME'
defined('LDAP_USER_ATTRIBUTE_EMAIL') or define('LDAP_USER_ATTRIBUTE_EMAIL', 'mail');
defined('LDAP_USER_ATTRIBUTE_GROUPS') or define('LDAP_USER_ATTRIBUTE_GROUPS', 'memberof');
defined('LDAP_USER_ATTRIBUTE_PHOTO') or define('LDAP_USER_ATTRIBUTE_PHOTO', '');
defined('LDAP_USER_ATTRIBUTE_LANGUAGE') or define('LDAP_USER_ATTRIBUTE_LANGUAGE', '');
defined('LDAP_USER_CREATION') or define('LDAP_USER_CREATION', true);
defined('LDAP_GROUP_ADMIN_DN') or define('LDAP_GROUP_ADMIN_DN', '');