Added config setting to disable password-reset and user-registration (#261)
This commit is contained in:
@@ -16,12 +16,13 @@ use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
|
||||
/**
|
||||
* This is the class that loads and manages your bundle configuration
|
||||
* This class that loads and manages the Kimai configuration and container parameter.
|
||||
*/
|
||||
class AppExtension extends Extension implements PrependExtensionInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param array $configs
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
@@ -36,10 +37,36 @@ class AppExtension extends Extension implements PrependExtensionInterface
|
||||
$container->setParameter('kimai.languages', $config['languages']);
|
||||
$container->setParameter('kimai.calendar', $config['calendar']);
|
||||
|
||||
$this->createUserParameter($config, $container);
|
||||
$this->createTimesheetParameter($config, $container);
|
||||
$this->createInvoiceParameter($config, $container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
public function createUserParameter(array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (!$config['user']['registration']) {
|
||||
$routes = $container->getParameter('admin_lte_theme.routes');
|
||||
$routes['adminlte_registration'] = null;
|
||||
$container->setParameter('admin_lte_theme.routes', $routes);
|
||||
}
|
||||
|
||||
if (!$config['user']['password_reset']) {
|
||||
$routes = $container->getParameter('admin_lte_theme.routes');
|
||||
$routes['adminlte_password_reset'] = null;
|
||||
$container->setParameter('admin_lte_theme.routes', $routes);
|
||||
}
|
||||
|
||||
$container->setParameter('kimai.fosuser', $config['user']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
public function createTimesheetParameter(array $config, ContainerBuilder $container)
|
||||
{
|
||||
$container->setParameter('kimai.timesheet.rates', $config['timesheet']['rates']);
|
||||
@@ -91,7 +118,7 @@ class AppExtension extends Extension implements PrependExtensionInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @return string
|
||||
*/
|
||||
public function getAlias()
|
||||
{
|
||||
|
||||
@@ -13,7 +13,9 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
/**
|
||||
* This is the class that validates and merges configuration from your app/config files
|
||||
* This class validates and merges configuration from the files:
|
||||
* - config/packages/kimai.yaml
|
||||
* - config/packages/local.yaml
|
||||
*/
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
@@ -27,6 +29,17 @@ class Configuration implements ConfigurationInterface
|
||||
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('user')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->booleanNode('registration')
|
||||
->defaultTrue()
|
||||
->end()
|
||||
->booleanNode('password_reset')
|
||||
->defaultTrue()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('timesheet')
|
||||
->children()
|
||||
->booleanNode('duration_only')
|
||||
|
||||
@@ -35,7 +35,7 @@ class DocumentationLinkExtension extends AbstractTypeExtension
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars['documentation'] = $options['documentation'] ?? '';
|
||||
$view->vars['docu_chapter'] = $options['docu_chapter'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,8 @@ class DocumentationLinkExtension extends AbstractTypeExtension
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefined(['documentation']);
|
||||
$resolver->setDefaults(['documentation' => null]);
|
||||
$resolver->setDefined(['docu_chapter']);
|
||||
$resolver->setAllowedTypes('docu_chapter', 'string');
|
||||
$resolver->setDefault('docu_chapter', '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ class TimesheetEditForm extends AbstractType
|
||||
'csrf_token_id' => 'timesheet_edit',
|
||||
'duration_only' => false,
|
||||
'include_user' => false,
|
||||
'documentation' => 'timesheet',
|
||||
'docu_chapter' => 'timesheet',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,12 +71,42 @@ class Kernel extends BaseKernel
|
||||
protected function configureRoutes(RouteCollectionBuilder $routes)
|
||||
{
|
||||
$confDir = $this->getProjectDir() . '/config';
|
||||
|
||||
// some routes are based on app configs and will be imported manually
|
||||
$this->configureFosUserRoutes($routes);
|
||||
|
||||
// load bundle specific route files
|
||||
if (is_dir($confDir . '/routes/')) {
|
||||
$routes->import($confDir . '/routes/*' . self::CONFIG_EXTS, '/', 'glob');
|
||||
}
|
||||
|
||||
// load environment specific route files
|
||||
if (is_dir($confDir . '/routes/' . $this->environment)) {
|
||||
$routes->import($confDir . '/routes/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
|
||||
}
|
||||
|
||||
// load application routes
|
||||
$routes->import($confDir . '/routes' . self::CONFIG_EXTS, '/', 'glob');
|
||||
}
|
||||
|
||||
protected function configureFosUserRoutes(RouteCollectionBuilder $routes)
|
||||
{
|
||||
$features = $this->getContainer()->getParameter('kimai.fosuser');
|
||||
|
||||
// Expose the user registration feature
|
||||
if ($features['registration']) {
|
||||
$routes->import(
|
||||
'@FOSUserBundle/Resources/config/routing/registration.xml',
|
||||
'/{_locale}/register'
|
||||
);
|
||||
}
|
||||
|
||||
// Expose the users password-reset feature
|
||||
if ($features['password_reset']) {
|
||||
$routes->import(
|
||||
'@FOSUserBundle/Resources/config/routing/resetting.xml',
|
||||
'/{_locale}/resetting'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user