allow to disable user preferences by permission (#895)
This commit is contained in:
@@ -22,4 +22,14 @@ class ThemeConfiguration implements SystemBundleConfiguration
|
||||
{
|
||||
return (string) $this->find('select_type');
|
||||
}
|
||||
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
$title = $this->find('branding.title');
|
||||
if (null === $title) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) $title;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,6 +335,9 @@ class Configuration implements ConfigurationInterface
|
||||
->scalarNode('company')
|
||||
->defaultNull()
|
||||
->end()
|
||||
->scalarNode('title')
|
||||
->defaultNull()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
||||
@@ -64,12 +64,13 @@ class ThemeOptionsSubscriber implements EventSubscriberInterface
|
||||
/** @var User $user */
|
||||
$user = $this->storage->getToken()->getUser();
|
||||
|
||||
$skin = '';
|
||||
foreach ($user->getPreferences() as $ref) {
|
||||
$name = $ref->getName();
|
||||
switch ($name) {
|
||||
case UserPreference::SKIN:
|
||||
$skin = 'skin-' . $ref->getValue();
|
||||
if (!empty($ref->getValue())) {
|
||||
$this->helper->setOption('skin', 'skin-' . $ref->getValue());
|
||||
}
|
||||
break;
|
||||
|
||||
case 'theme.collapsed_sidebar':
|
||||
@@ -77,12 +78,6 @@ class ThemeOptionsSubscriber implements EventSubscriberInterface
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($skin)) {
|
||||
$skin = 'skin-green';
|
||||
}
|
||||
|
||||
$this->helper->setOption('skin', $skin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -97,7 +97,6 @@ class UserPreferenceSubscriber implements EventSubscriberInterface
|
||||
|
||||
(new UserPreference())
|
||||
->setName(UserPreference::SKIN)
|
||||
->setValue('green')
|
||||
->setType(SkinType::class),
|
||||
|
||||
(new UserPreference())
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Twig;
|
||||
|
||||
use App\Configuration\ThemeConfiguration;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
@@ -19,13 +20,18 @@ class TitleExtension extends AbstractExtension
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
/**
|
||||
* @var ThemeConfiguration
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
/**
|
||||
* @param TranslatorInterface $translator
|
||||
*/
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
public function __construct(TranslatorInterface $translator, ThemeConfiguration $configuration)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
$this->configuration = $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,13 +44,10 @@ class TitleExtension extends AbstractExtension
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string $prefix
|
||||
* @param string $delimiter
|
||||
* @return string
|
||||
*/
|
||||
public function generateTitle(?string $prefix = null, string $delimiter = ' – ')
|
||||
public function generateTitle(?string $prefix = null, string $delimiter = ' – '): string
|
||||
{
|
||||
return ($prefix ?? '') . 'Kimai' . $delimiter . $this->translator->trans('time_tracking', [], 'messages');
|
||||
$title = $this->configuration->getTitle() ?? 'Kimai';
|
||||
|
||||
return ($prefix ?? '') . ($title) . $delimiter . $this->translator->trans('time_tracking', [], 'messages');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,13 +83,13 @@ class UserVoter extends AbstractVoter
|
||||
// used in templates and ProfileController
|
||||
case self::VIEW:
|
||||
case self::EDIT:
|
||||
case self::PREFERENCES:
|
||||
// always allow the user to edit these own settings
|
||||
if ($subject->getId() === $user->getId()) {
|
||||
return true;
|
||||
}
|
||||
// no break on purpose
|
||||
|
||||
case self::PREFERENCES:
|
||||
case self::PASSWORD:
|
||||
case self::API_TOKEN:
|
||||
case self::ROLES:
|
||||
|
||||
Reference in New Issue
Block a user