mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 18:58:46 +02:00
Hide nodes in tools menu, for which the user does not have permissions.
This commit is contained in:
parent
a078eef649
commit
44bad9029b
1 changed files with 89 additions and 32 deletions
|
@ -29,6 +29,18 @@
|
||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Entity\Attachments\AttachmentType;
|
||||||
|
use App\Entity\Devices\Device;
|
||||||
|
use App\Entity\Parts\Category;
|
||||||
|
use App\Entity\Parts\Footprint;
|
||||||
|
use App\Entity\Parts\Manufacturer;
|
||||||
|
use App\Entity\Parts\MeasurementUnit;
|
||||||
|
use App\Entity\Parts\Part;
|
||||||
|
use App\Entity\Parts\Storelocation;
|
||||||
|
use App\Entity\Parts\Supplier;
|
||||||
|
use App\Entity\PriceInformations\Currency;
|
||||||
|
use App\Entity\UserSystem\Group;
|
||||||
|
use App\Entity\UserSystem\User;
|
||||||
use App\Helpers\TreeViewNode;
|
use App\Helpers\TreeViewNode;
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
@ -47,9 +59,11 @@ class ToolsTreeBuilder
|
||||||
protected $urlGenerator;
|
protected $urlGenerator;
|
||||||
protected $keyGenerator;
|
protected $keyGenerator;
|
||||||
protected $cache;
|
protected $cache;
|
||||||
|
protected $security;
|
||||||
|
|
||||||
public function __construct(TranslatorInterface $translator, UrlGeneratorInterface $urlGenerator,
|
public function __construct(TranslatorInterface $translator, UrlGeneratorInterface $urlGenerator,
|
||||||
TagAwareCacheInterface $treeCache, UserCacheKeyGenerator $keyGenerator)
|
TagAwareCacheInterface $treeCache, UserCacheKeyGenerator $keyGenerator,
|
||||||
|
Security $security)
|
||||||
{
|
{
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
|
@ -57,6 +71,8 @@ class ToolsTreeBuilder
|
||||||
$this->cache = $treeCache;
|
$this->cache = $treeCache;
|
||||||
|
|
||||||
$this->keyGenerator = $keyGenerator;
|
$this->keyGenerator = $keyGenerator;
|
||||||
|
|
||||||
|
$this->security = $security;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,31 +103,67 @@ class ToolsTreeBuilder
|
||||||
protected function getEditNodes() : array
|
protected function getEditNodes() : array
|
||||||
{
|
{
|
||||||
$nodes = array();
|
$nodes = array();
|
||||||
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.attachment_types'),
|
|
||||||
$this->urlGenerator->generate('attachment_type_new'));
|
|
||||||
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.categories'),
|
|
||||||
$this->urlGenerator->generate('category_new'));
|
|
||||||
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.devices'),
|
|
||||||
$this->urlGenerator->generate('device_new'));
|
|
||||||
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.suppliers'),
|
|
||||||
$this->urlGenerator->generate('supplier_new'));
|
|
||||||
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.manufacturer'),
|
|
||||||
$this->urlGenerator->generate('manufacturer_new'));
|
|
||||||
|
|
||||||
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.storelocation'),
|
if ($this->security->isGranted('read', new AttachmentType())) {
|
||||||
$this->urlGenerator->generate('store_location_new'));
|
$nodes[] = new TreeViewNode(
|
||||||
|
$this->translator->trans('tree.tools.edit.attachment_types'),
|
||||||
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.footprint'),
|
$this->urlGenerator->generate('attachment_type_new')
|
||||||
$this->urlGenerator->generate('footprint_new'));
|
);
|
||||||
|
}
|
||||||
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.currency'),
|
if ($this->security->isGranted('read', new Category())) {
|
||||||
$this->urlGenerator->generate('currency_new'));
|
$nodes[] = new TreeViewNode(
|
||||||
|
$this->translator->trans('tree.tools.edit.categories'),
|
||||||
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.measurement_unit'),
|
$this->urlGenerator->generate('category_new')
|
||||||
$this->urlGenerator->generate('measurement_unit_new'));
|
);
|
||||||
|
}
|
||||||
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.part'),
|
if ($this->security->isGranted('read', new Device())) {
|
||||||
$this->urlGenerator->generate('part_new'));
|
$nodes[] = new TreeViewNode(
|
||||||
|
$this->translator->trans('tree.tools.edit.devices'),
|
||||||
|
$this->urlGenerator->generate('device_new')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($this->security->isGranted('read', new Supplier())) {
|
||||||
|
$nodes[] = new TreeViewNode(
|
||||||
|
$this->translator->trans('tree.tools.edit.suppliers'),
|
||||||
|
$this->urlGenerator->generate('supplier_new')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($this->security->isGranted('read', new Manufacturer())) {
|
||||||
|
$nodes[] = new TreeViewNode(
|
||||||
|
$this->translator->trans('tree.tools.edit.manufacturer'),
|
||||||
|
$this->urlGenerator->generate('manufacturer_new')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($this->security->isGranted('read', new Storelocation())) {
|
||||||
|
$nodes[] = new TreeViewNode(
|
||||||
|
$this->translator->trans('tree.tools.edit.storelocation'),
|
||||||
|
$this->urlGenerator->generate('store_location_new')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($this->security->isGranted('read', new Footprint())) {
|
||||||
|
$nodes[] = new TreeViewNode(
|
||||||
|
$this->translator->trans('tree.tools.edit.footprint'),
|
||||||
|
$this->urlGenerator->generate('footprint_new')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($this->security->isGranted('read', new Currency())) {
|
||||||
|
$nodes[] = new TreeViewNode(
|
||||||
|
$this->translator->trans('tree.tools.edit.currency'),
|
||||||
|
$this->urlGenerator->generate('currency_new')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($this->security->isGranted('read', new MeasurementUnit())) {
|
||||||
|
$nodes[] = new TreeViewNode(
|
||||||
|
$this->translator->trans('tree.tools.edit.measurement_unit'),
|
||||||
|
$this->urlGenerator->generate('measurement_unit_new')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($this->security->isGranted('create', new Part())) {
|
||||||
|
$nodes[] = new TreeViewNode(
|
||||||
|
$this->translator->trans('tree.tools.edit.part'),
|
||||||
|
$this->urlGenerator->generate('part_new')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $nodes;
|
return $nodes;
|
||||||
}
|
}
|
||||||
|
@ -138,13 +190,18 @@ class ToolsTreeBuilder
|
||||||
{
|
{
|
||||||
$nodes = array();
|
$nodes = array();
|
||||||
|
|
||||||
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.system.users'),
|
if ($this->security->isGranted('read', new User())) {
|
||||||
$this->urlGenerator->generate("user_new")
|
$nodes[] = new TreeViewNode(
|
||||||
);
|
$this->translator->trans('tree.tools.system.users'),
|
||||||
|
$this->urlGenerator->generate("user_new")
|
||||||
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.system.groups'),
|
);
|
||||||
$this->urlGenerator->generate('group_new')
|
}
|
||||||
);
|
if ($this->security->isGranted('read', new Group())) {
|
||||||
|
$nodes[] = new TreeViewNode(
|
||||||
|
$this->translator->trans('tree.tools.system.groups'),
|
||||||
|
$this->urlGenerator->generate('group_new')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $nodes;
|
return $nodes;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue