Organized parameters better.

Parameters can now be found in their own file config/parameters.yaml. They are prefixed with partdb. and structured into different sections.
This commit is contained in:
Jan Böhmer 2020-05-12 22:53:42 +02:00
parent ffdb721e38
commit decc4e90fc
11 changed files with 86 additions and 57 deletions

View file

@ -7,7 +7,7 @@ scheb_two_factor:
google: google:
enabled: true # If Google Authenticator should be enabled, default false enabled: true # If Google Authenticator should be enabled, default false
server_name: '%partdb_title%' # Server name used in QR code server_name: '%partdb.title%' # Server name used in QR code
issuer: 'Part-DB' # Issuer name used in QR code issuer: 'Part-DB' # Issuer name used in QR code
digits: 6 # Number of digits in authentication code digits: 6 # Number of digits in authentication code
window: 1 # How many codes before/after the current one would be accepted as valid window: 1 # How many codes before/after the current one would be accepted as valid

View file

@ -1,7 +1,7 @@
framework: framework:
default_locale: '%locale%' default_locale: '%partdb.locale%'
translator: translator:
default_path: '%kernel.project_dir%/translations' default_path: '%kernel.project_dir%/translations'
fallbacks: fallbacks:
- '%locale%' - '%partdb.locale%'
- 'en' - 'en'

View file

@ -6,10 +6,10 @@ twig:
'%kernel.project_dir%/assets/css': css '%kernel.project_dir%/assets/css': css
globals: globals:
partdb_title: '%partdb_title%' partdb_title: '%partdb.title%'
default_currency: '%default_currency%' default_currency: '%partdb.default_currency%'
global_theme: '%global_theme%' global_theme: '%partdb.global_theme%'
allow_email_pw_reset: '%allow_email_pw_reset%' allow_email_pw_reset: '%partdb.users.email_pw_reset%'
locale_menu: '%locale_menu%' locale_menu: '%partdb.locale_menu%'
attachment_manager: '@App\Services\Attachments\AttachmentManager' attachment_manager: '@App\Services\Attachments\AttachmentManager'
label_profile_dropdown_helper: '@App\Services\LabelSystem\LabelProfileDropdownHelper' label_profile_dropdown_helper: '@App\Services\LabelSystem\LabelProfileDropdownHelper'

43
config/parameters.yaml Normal file
View file

@ -0,0 +1,43 @@
# Here you can configure the global behavior of Part-DB
parameters:
######################################################################################################################
# Common
######################################################################################################################
partdb.locale: 'en' # The default language to use serverwide
partdb.timezone: 'Europe/Berlin' # The default timezone
partdb.title: 'Part-DB' # The title shown inside of Part-DB (e.g. in the navbar and on homepage)
partdb.banner: '%env(trim:string:BANNER)%' # The info text shown in the homepage, if empty config/banner.md is used
partdb.default_currency: 'EUR' # The currency that is used inside the DB (and is assumed when no currency is set). This can not be changed later, so be sure to set it the currency used in your country
partdb.global_theme: '' # The theme to use globally (see public/build/themes/ for choices, use name without .css). Set to '' for default bootstrap theme
partdb.locale_menu: ['en', 'de', 'fr', 'ru', 'ja'] # The languages that are shown in user drop down menu
######################################################################################################################
# Users and Privacy
######################################################################################################################
partdb.gpdr_compliance: true # If this option is activated, IP addresses are anonymized to be GPDR compliant
partdb.users.use_gravatar: true # Set to false, if no Gravatar images should be used for user profiles.
partdb.users.email_pw_reset: '%env(validMailDSN:MAILER_DSN)%' # Config if users are able, to reset their password by email. By default this enabled, when a mail server is configured.
######################################################################################################################
# Mail settings
######################################################################################################################
partdb.mail.sender_email: 'noreply@partdb.changeme' # The email address from which all emails are sent from
partdb.mail.sender_name: 'Part-DB Mailer' # The name that will be used for all mails sent by Part-DB
######################################################################################################################
# Attachments and files
######################################################################################################################
partdb.attachments.allow_downloads: false # Allow users to download attachments to server. Warning: This can be dangerous, because via that feature attackers maybe can access ressources on your intranet!
partdb.attachments.dir.media: 'public/media/' # The folder where uploaded attachment files are saved (must be in public folder)
partdb.attachments.dir.secure: 'uploads/' # The folder where secured attachment files are saved (must not be in public/)
######################################################################################################################
# Miscellaneous
######################################################################################################################
partdb.demo_mode: '%env(bool:DEMO_MODE)%' # If set to true, all potentially dangerous things are disabled (like changing passwords of the own user)

View file

@ -4,38 +4,18 @@
# Put parameters here that don't need to change on each machine where the app is deployed # Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'en' # Set the default language to use her
timezone: 'Europe/Berlin'
partdb_title: 'Part-DB' # The title shown inside of Part-DB (e.g. in the navbar and on homepage)
banner: '%env(trim:string:BANNER)%' # The info text shown in the homepage, if empty config/banner.md is used
use_gravatar: true # Set to false, if no Gravatar images should be used for user profiles.
default_currency: 'EUR' # The currency that should be used
media_directory: 'public/media/' # The folder where uploaded attachment files are saved
secure_media_directory: 'uploads/' # The folder where secured attachment files are saved (must not be in public/)
global_theme: '' # The theme to use globally (see public/build/themes/ for choices). Set to '' for default bootstrap theme
# Allow users to download attachments to server. Warning: This can be dangerous, because via that feature attackers maybe can access ressources on your intranet!
allow_attachments_downloads: false
demo_mode: '%env(bool:DEMO_MODE)%' # If set to true, all potentially dangerous things are disabled (like changing passwords of the own user)
sender_email: 'noreply@partdb.changeme' # The email address from which all emails are sent from
sender_name: 'Part-DB Mailer' # The name that will be used for all mails sent by Part-DB
allow_email_pw_reset: '%env(validMailDSN:MAILER_DSN)%' # Config if users are able, to reset their password by email. By default this enabled, when a mail server is configured.
locale_menu: ['en', 'de', 'fr', 'ru', 'ja'] # The languages that are shown in user drop down menu
# If this option is activated, IP addresses are anonymized to be GPDR compliant
gpdr_compliance: true
services: services:
# default configuration for services in *this* file # default configuration for services in *this* file
_defaults: _defaults:
autowire: true # Automatically injects dependencies in your services. autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
bind: bind:
bool $demo_mode: '%demo_mode%' bool $demo_mode: '%partdb.demo_mode%'
bool $gpdr_compliance : '%gpdr_compliance%' bool $gpdr_compliance : '%partdb.gpdr_compliance%'
bool $kernel_debug: '%kernel.debug%' bool $kernel_debug: '%kernel.debug%'
string $kernel_cache_dir: '%kernel.cache_dir%' string $kernel_cache_dir: '%kernel.cache_dir%'
string $partdb_title: '%partdb_title%' string $partdb_title: '%partdb.title%'
string $default_currency: '%partdb.default_currency%'
_instanceof: _instanceof:
App\Services\LabelSystem\PlaceholderProviders\PlaceholderProviderInterface: App\Services\LabelSystem\PlaceholderProviders\PlaceholderProviderInterface:
@ -56,8 +36,8 @@ services:
App\EventSubscriber\SetMailFromSubscriber: App\EventSubscriber\SetMailFromSubscriber:
tags: ['kernel.event_subscriber'] tags: ['kernel.event_subscriber']
arguments: arguments:
$email: '%sender_email%' $email: '%partdb.mail.sender_email%'
$name: '%sender_name%' $name: '%partdb.mail.sender_name%'
App\Services\LogSystem\EventLogger: App\Services\LogSystem\EventLogger:
arguments: arguments:
@ -111,51 +91,51 @@ services:
App\Controller\RedirectController: App\Controller\RedirectController:
arguments: arguments:
$default_locale: '%locale%' $default_locale: '%partdb.locale%'
$enforce_index_php: '%env(bool:NO_URL_REWRITE_AVAILABLE)%' $enforce_index_php: '%env(bool:NO_URL_REWRITE_AVAILABLE)%'
App\Command\UpdateExchangeRatesCommand: App\Command\UpdateExchangeRatesCommand:
arguments: arguments:
$base_current: '%default_currency%' $base_current: '%partdb.default_currency%'
App\Form\Type\CurrencyEntityType: App\Form\Type\CurrencyEntityType:
arguments: arguments:
$base_currency: '%default_currency%' $base_currency: '%partdb.default_currency%'
App\Services\PricedetailHelper: App\Services\PricedetailHelper:
arguments: arguments:
$base_currency: '%default_currency%' $base_currency: '%partdb.default_currency%'
App\Services\MoneyFormatter: App\Services\MoneyFormatter:
arguments: arguments:
$base_currency: '%default_currency%' $base_currency: '%partdb.default_currency%'
App\Form\AttachmentFormType: App\Form\AttachmentFormType:
arguments: arguments:
$allow_attachments_downloads: '%allow_attachments_downloads%' $allow_attachments_downloads: '%partdb.attachments.allow_downloads%'
App\Services\Attachments\AttachmentSubmitHandler: App\Services\Attachments\AttachmentSubmitHandler:
arguments: arguments:
$allow_attachments_downloads: '%allow_attachments_downloads%' $allow_attachments_downloads: '%partdb.attachments.allow_downloads%'
$mimeTypes: '@mime_types' $mimeTypes: '@mime_types'
App\Form\UserSettingsType: App\Form\UserSettingsType:
arguments: arguments:
$demo_mode: '%demo_mode%' $demo_mode: '%partdb.demo_mode%'
App\EventSubscriber\UserSystem\SetUserTimezoneSubscriber: App\EventSubscriber\UserSystem\SetUserTimezoneSubscriber:
arguments: arguments:
$timezone: '%timezone%' $timezone: '%partdb.timezone%'
App\Controller\SecurityController: App\Controller\SecurityController:
arguments: arguments:
$allow_email_pw_reset: '%allow_email_pw_reset%' $allow_email_pw_reset: '%partdb.users.email_pw_reset%'
App\Services\Attachments\AttachmentPathResolver: App\Services\Attachments\AttachmentPathResolver:
arguments: arguments:
$project_dir: '%kernel.project_dir%' $project_dir: '%kernel.project_dir%'
$media_path: '%media_directory%' $media_path: '%partdb.attachments.dir.media%'
$secure_path: '%secure_media_directory%' $secure_path: '%partdb.attachments.dir.secure%'
$footprints_path: 'public/img/footprints' $footprints_path: 'public/img/footprints'
$models_path: null $models_path: null

View file

@ -68,7 +68,7 @@ class HomepageController extends AbstractController
public function getBanner(): string public function getBanner(): string
{ {
$banner = $this->getParameter('banner'); $banner = $this->getParameter('partdb.banner');
if (empty($banner)) { if (empty($banner)) {
$banner_path = $this->kernel->getProjectDir() $banner_path = $this->kernel->getProjectDir()
.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'banner.md'; .DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'banner.md';

View file

@ -193,7 +193,7 @@ class UserController extends AdminPages\BaseAdminController
return $table->getResponse(); return $table->getResponse();
} }
if ($this->getParameter('use_gravatar')) { if ($this->getParameter('partdb.users.use_gravatar')) {
$avatar = $this->getGravatar($user->getEmail(), 200, 'identicon'); $avatar = $this->getGravatar($user->getEmail(), 200, 'identicon');
} else { } else {
$avatar = $packages->getUrl('/img/default_avatar.png'); $avatar = $packages->getUrl('/img/default_avatar.png');

View file

@ -44,7 +44,6 @@ namespace App\Form\AdminPages;
use App\Entity\Base\AbstractNamedDBElement; use App\Entity\Base\AbstractNamedDBElement;
use App\Services\Attachments\FileTypeFilterTools; use App\Services\Attachments\FileTypeFilterTools;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -54,10 +53,10 @@ class AttachmentTypeAdminForm extends BaseEntityAdminForm
{ {
protected $filterTools; protected $filterTools;
public function __construct(Security $security, ParameterBagInterface $params, FileTypeFilterTools $filterTools) public function __construct(Security $security, FileTypeFilterTools $filterTools)
{ {
$this->filterTools = $filterTools; $this->filterTools = $filterTools;
parent::__construct($security, $params); parent::__construct($security);
} }
protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void

View file

@ -42,7 +42,6 @@ declare(strict_types=1);
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Attachments\Attachment;
use App\Entity\Base\AbstractNamedDBElement; use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\AbstractStructuralDBElement; use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\LabelSystem\LabelProfile; use App\Entity\LabelSystem\LabelProfile;
@ -52,7 +51,6 @@ use App\Form\Type\MasterPictureAttachmentType;
use App\Form\Type\StructuralEntityType; use App\Form\Type\StructuralEntityType;
use FOS\CKEditorBundle\Form\Type\CKEditorType; use FOS\CKEditorBundle\Form\Type\CKEditorType;
use function get_class; use function get_class;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\CollectionType;
@ -66,12 +64,10 @@ use Symfony\Component\Security\Core\Security;
class BaseEntityAdminForm extends AbstractType class BaseEntityAdminForm extends AbstractType
{ {
protected $security; protected $security;
protected $params;
public function __construct(Security $security, ParameterBagInterface $params) public function __construct(Security $security)
{ {
$this->security = $security; $this->security = $security;
$this->params = $params;
} }
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void

View file

@ -47,9 +47,18 @@ use App\Entity\PriceInformations\Currency;
use App\Form\Type\StructuralEntityType; use App\Form\Type\StructuralEntityType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType; use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
class SupplierForm extends CompanyForm class SupplierForm extends CompanyForm
{ {
protected $default_currency;
public function __construct(Security $security, string $default_currency)
{
parent::__construct($security);
$this->default_currency = $default_currency;
}
protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void
{ {
$is_new = null === $entity->getID(); $is_new = null === $entity->getID();
@ -66,7 +75,7 @@ class SupplierForm extends CompanyForm
$builder->add('shipping_costs', MoneyType::class, [ $builder->add('shipping_costs', MoneyType::class, [
'required' => false, 'required' => false,
'currency' => $this->params->get('default_currency'), 'currency' => $this->default_currency,
'scale' => 3, 'scale' => 3,
'label' => 'supplier.shipping_costs.label', 'label' => 'supplier.shipping_costs.label',
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity),

View file

@ -57,6 +57,8 @@ class Kernel extends BaseKernel
$container->setParameter('container.dumper.inline_factories', true); $container->setParameter('container.dumper.inline_factories', true);
$confDir = $this->getProjectDir().'/config'; $confDir = $this->getProjectDir().'/config';
$loader->load($confDir.'/parameters.yaml');
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob'); $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob'); $loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob'); $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');