mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
saved export: add form to share the export
This commit is contained in:
parent
2842548c17
commit
9f12b42961
@ -13,15 +13,22 @@ namespace Chill\MainBundle\Form;
|
|||||||
|
|
||||||
use Chill\MainBundle\Entity\SavedExport;
|
use Chill\MainBundle\Entity\SavedExport;
|
||||||
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
||||||
|
use Chill\MainBundle\Form\Type\PickUserGroupOrUserDynamicType;
|
||||||
|
use Chill\MainBundle\Security\Authorization\SavedExportVoter;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
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;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
|
||||||
class SavedExportType extends AbstractType
|
class SavedExportType extends AbstractType
|
||||||
{
|
{
|
||||||
|
public function __construct(private Security $security) {}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
|
$savedExport = $options['data'];
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->add('title', TextType::class, [
|
->add('title', TextType::class, [
|
||||||
'required' => true,
|
'required' => true,
|
||||||
@ -29,6 +36,14 @@ class SavedExportType extends AbstractType
|
|||||||
->add('description', ChillTextareaType::class, [
|
->add('description', ChillTextareaType::class, [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($this->security->isGranted(SavedExportVoter::SHARE, $savedExport)) {
|
||||||
|
$builder->add('share', PickUserGroupOrUserDynamicType::class, [
|
||||||
|
'multiple' => true,
|
||||||
|
'required' => false,
|
||||||
|
'label' => 'saved_export.Share',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
@ -2,6 +2,16 @@
|
|||||||
|
|
||||||
{% block title %}{{ 'saved_export.Edit'|trans }}{% endblock %}
|
{% block title %}{{ 'saved_export.Edit'|trans }}{% endblock %}
|
||||||
|
|
||||||
|
{% block css %}
|
||||||
|
{{ parent() }}
|
||||||
|
{{ encore_entry_link_tags('mod_pickentity_type') }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
{{ parent() }}
|
||||||
|
{{ encore_entry_script_tags('mod_pickentity_type') }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
<h1>{{ block('title') }}</h1>
|
<h1>{{ block('title') }}</h1>
|
||||||
@ -10,6 +20,10 @@
|
|||||||
{{ form_row(form.title) }}
|
{{ form_row(form.title) }}
|
||||||
{{ form_row(form.description) }}
|
{{ form_row(form.description) }}
|
||||||
|
|
||||||
|
{% if form.share is defined %}
|
||||||
|
{{ form_row(form.share) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<ul class="record_actions sticky-form-buttons">
|
<ul class="record_actions sticky-form-buttons">
|
||||||
<li class="cancel">
|
<li class="cancel">
|
||||||
<a href="{{ chill_return_path_or('chill_main_homepage') }}" class="btn btn-cancel">{{ 'Cancel'|trans }}</a>
|
<a href="{{ chill_return_path_or('chill_main_homepage') }}" class="btn btn-cancel">{{ 'Cancel'|trans }}</a>
|
||||||
|
@ -2,6 +2,16 @@
|
|||||||
|
|
||||||
{% block title %}{{ 'saved_export.New'|trans }}{% endblock %}
|
{% block title %}{{ 'saved_export.New'|trans }}{% endblock %}
|
||||||
|
|
||||||
|
{% block css %}
|
||||||
|
{{ parent() }}
|
||||||
|
{{ encore_entry_link_tags('mod_pickentity_type') }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
{{ parent() }}
|
||||||
|
{{ encore_entry_script_tags('mod_pickentity_type') }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
<h1>{{ block('title') }}</h1>
|
<h1>{{ block('title') }}</h1>
|
||||||
@ -10,6 +20,10 @@
|
|||||||
{{ form_row(form.title) }}
|
{{ form_row(form.title) }}
|
||||||
{{ form_row(form.description) }}
|
{{ form_row(form.description) }}
|
||||||
|
|
||||||
|
{% if form.share is defined %}
|
||||||
|
{{ form_row(form.share) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<ul class="record_actions sticky-form-buttons">
|
<ul class="record_actions sticky-form-buttons">
|
||||||
<li class="cancel">
|
<li class="cancel">
|
||||||
<a href="{{ chill_return_path_or('chill_main_homepage') }}" class="btn btn-cancel">{{ 'Cancel'|trans }}</a>
|
<a href="{{ chill_return_path_or('chill_main_homepage') }}" class="btn btn-cancel">{{ 'Cancel'|trans }}</a>
|
||||||
|
@ -36,8 +36,16 @@ class SavedExportVoter extends Voter
|
|||||||
|
|
||||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
|
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
|
||||||
{
|
{
|
||||||
|
/* @var SavedExport $subject */
|
||||||
|
$user = $token->getUser();
|
||||||
|
|
||||||
|
if (!$user instanceof User) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return match ($attribute) {
|
return match ($attribute) {
|
||||||
self::DELETE, self::EDIT, self::GENERATE => $subject->getUser() === $token->getUser(),
|
self::DELETE, self::EDIT, self::SHARE => $subject->getUser() === $token->getUser(),
|
||||||
|
self::GENERATE => $this->canUserGenerate($user, $subject),
|
||||||
default => throw new \UnexpectedValueException('attribute not supported: '.$attribute),
|
default => throw new \UnexpectedValueException('attribute not supported: '.$attribute),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -146,3 +146,5 @@ services:
|
|||||||
Chill\MainBundle\Form\DataTransformer\IdToLocationDataTransformer: ~
|
Chill\MainBundle\Form\DataTransformer\IdToLocationDataTransformer: ~
|
||||||
Chill\MainBundle\Form\DataTransformer\IdToUserDataTransformer: ~
|
Chill\MainBundle\Form\DataTransformer\IdToUserDataTransformer: ~
|
||||||
Chill\MainBundle\Form\DataTransformer\IdToUsersDataTransformer: ~
|
Chill\MainBundle\Form\DataTransformer\IdToUsersDataTransformer: ~
|
||||||
|
|
||||||
|
Chill\MainBundle\Form\SavedExportType: ~
|
||||||
|
Loading…
x
Reference in New Issue
Block a user