Added permissions to label system.

This commit is contained in:
Jan Böhmer 2020-05-04 23:21:58 +02:00
parent fde1d7be4f
commit 5a9be023b1
6 changed files with 62 additions and 27 deletions

View file

@ -61,25 +61,19 @@ class LabelController extends AbstractController
$this->rangeParser = $rangeParser;
}
/**
* @Route("/{profile}/{part}/view")
*/
public function view(LabelProfile $profile, Part $part)
{
$label = $this->labelGenerator->generateLabel($profile->getOptions(), $part);
$response = new LabelResponse($label);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, 'label.pdf');
return $response;
}
/**
* @Route("/dialog", name="label_dialog")
* @Route("/{profile}/dialog", name="label_dialog_profile")
*/
public function generator(Request $request, ?LabelProfile $profile = null)
{
$this->denyAccessUnlessGranted('@labels.create_labels');
//If we inherit a LabelProfile, the user need to have access to it...
if ($profile !== null) {
$this->denyAccessUnlessGranted('read', $profile);
}
if ($profile) {
$label_options = $profile->getOptions();
} else {

View file

@ -29,9 +29,17 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security;
class LabelDialogType extends AbstractType
{
protected $security;
public function __construct(Security $security)
{
$this->security = $security;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('target_id', TextType::class, [
@ -45,6 +53,8 @@ class LabelDialogType extends AbstractType
$builder->add('options', LabelOptionsType::class, [
'label' => false,
'disabled' => !$this->security->isGranted('@labels.edit_options'),
]);
$builder->add('update', SubmitType::class, [

View file

@ -27,12 +27,19 @@ use App\Entity\UserSystem\User;
class LabelProfileVoter extends ExtendedVoter
{
protected const MAPPING = [
'read' => 'read_profiles',
'create' => 'create_profiles',
'edit' => 'edit_profiles',
'delete' => 'delete_profiles',
];
/**
* @inheritDoc
*/
protected function voteOnUser($attribute, $subject, User $user): bool
{
return true;
return $this->resolver->inherit($user, 'labels', self::MAPPING[$attribute]) ?? false;
}
/**
@ -41,7 +48,11 @@ class LabelProfileVoter extends ExtendedVoter
protected function supports($attribute, $subject)
{
if ($subject instanceof LabelProfile) {
return true;
if (!isset(self::MAPPING[$attribute])) {
return false;
}
return $this->resolver->isValidOperation('labels', self::MAPPING[$attribute]);
}
return false;

View file

@ -118,10 +118,12 @@ class ToolsTreeBuilder
{
$nodes = [];
$nodes[] = new TreeViewNode(
$this->translator->trans('tree.tools.tools.label_dialog'),
$this->urlGenerator->generate('label_dialog')
);
if($this->security->isGranted('@labels.create_labels')) {
$nodes[] = new TreeViewNode(
$this->translator->trans('tree.tools.tools.label_dialog'),
$this->urlGenerator->generate('label_dialog')
);
}
$nodes[] = new TreeViewNode(
$this->translator->trans('tree.tools.tools.label_scanner'),
@ -194,7 +196,7 @@ class ToolsTreeBuilder
$this->urlGenerator->generate('measurement_unit_new')
);
}
if ($this->security->isGranted('create', new LabelProfile())) {
if ($this->security->isGranted('read', new LabelProfile())) {
$nodes[] = new TreeViewNode(
$this->translator->trans('tree.tools.edit.label_profile'),
$this->urlGenerator->generate('label_profile_new')