diff --git a/src/Bundle/ChillMainBundle/Form/SavedExportType.php b/src/Bundle/ChillMainBundle/Form/SavedExportType.php
index 16aa4e42e..7de44d5c9 100644
--- a/src/Bundle/ChillMainBundle/Form/SavedExportType.php
+++ b/src/Bundle/ChillMainBundle/Form/SavedExportType.php
@@ -13,15 +13,22 @@ namespace Chill\MainBundle\Form;
use Chill\MainBundle\Entity\SavedExport;
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\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
+use Symfony\Component\Security\Core\Security;
class SavedExportType extends AbstractType
{
+ public function __construct(private Security $security) {}
+
public function buildForm(FormBuilderInterface $builder, array $options)
{
+ $savedExport = $options['data'];
+
$builder
->add('title', TextType::class, [
'required' => true,
@@ -29,6 +36,14 @@ class SavedExportType extends AbstractType
->add('description', ChillTextareaType::class, [
'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)
diff --git a/src/Bundle/ChillMainBundle/Resources/views/SavedExport/edit.html.twig b/src/Bundle/ChillMainBundle/Resources/views/SavedExport/edit.html.twig
index 98cfd6281..a8a737c1e 100644
--- a/src/Bundle/ChillMainBundle/Resources/views/SavedExport/edit.html.twig
+++ b/src/Bundle/ChillMainBundle/Resources/views/SavedExport/edit.html.twig
@@ -2,6 +2,16 @@
{% 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('title') }}
@@ -10,6 +20,10 @@
{{ form_row(form.title) }}
{{ form_row(form.description) }}
+ {% if form.share is defined %}
+ {{ form_row(form.share) }}
+ {% endif %}
+
{{ form_end(form) }}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/src/Bundle/ChillMainBundle/Resources/views/SavedExport/new.html.twig b/src/Bundle/ChillMainBundle/Resources/views/SavedExport/new.html.twig
index 317f53e42..3fddcd270 100644
--- a/src/Bundle/ChillMainBundle/Resources/views/SavedExport/new.html.twig
+++ b/src/Bundle/ChillMainBundle/Resources/views/SavedExport/new.html.twig
@@ -2,6 +2,16 @@
{% 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('title') }}
@@ -10,6 +20,10 @@
{{ form_row(form.title) }}
{{ form_row(form.description) }}
+ {% if form.share is defined %}
+ {{ form_row(form.share) }}
+ {% endif %}
+
{{ form_end(form) }}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/SavedExportVoter.php b/src/Bundle/ChillMainBundle/Security/Authorization/SavedExportVoter.php
index 0e9a7da52..a29a38662 100644
--- a/src/Bundle/ChillMainBundle/Security/Authorization/SavedExportVoter.php
+++ b/src/Bundle/ChillMainBundle/Security/Authorization/SavedExportVoter.php
@@ -36,8 +36,16 @@ class SavedExportVoter extends Voter
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
+ /* @var SavedExport $subject */
+ $user = $token->getUser();
+
+ if (!$user instanceof User) {
+ return false;
+ }
+
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),
};
}
diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml
index f6b50cb57..f31829915 100644
--- a/src/Bundle/ChillMainBundle/config/services/form.yaml
+++ b/src/Bundle/ChillMainBundle/config/services/form.yaml
@@ -146,3 +146,5 @@ services:
Chill\MainBundle\Form\DataTransformer\IdToLocationDataTransformer: ~
Chill\MainBundle\Form\DataTransformer\IdToUserDataTransformer: ~
Chill\MainBundle\Form\DataTransformer\IdToUsersDataTransformer: ~
+
+ Chill\MainBundle\Form\SavedExportType: ~