-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require group edit role to change user groups
- Loading branch information
Showing
6 changed files
with
96 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the NucleosUserAdminBundle package. | ||
* | ||
* (c) Christian Gripp <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nucleos\UserAdminBundle\Form\Type; | ||
|
||
use Nucleos\UserBundle\Model\GroupInterface; | ||
use Nucleos\UserBundle\Model\GroupManager; | ||
use Sonata\AdminBundle\Admin\AdminInterface; | ||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
final class GroupType extends AbstractType | ||
{ | ||
/** | ||
* @var GroupManager<GroupInterface> | ||
*/ | ||
private readonly GroupManager $groupManager; | ||
|
||
/** | ||
* @var AdminInterface<GroupInterface> | ||
*/ | ||
private readonly AdminInterface $groupAdmin; | ||
|
||
/** | ||
* @param GroupManager<GroupInterface> $groupManager | ||
* @param AdminInterface<GroupInterface> $groupAdmin | ||
*/ | ||
public function __construct( | ||
GroupManager $groupManager, | ||
AdminInterface $groupAdmin, | ||
) { | ||
$this->groupManager = $groupManager; | ||
$this->groupAdmin = $groupAdmin; | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver | ||
->setDefaults([ | ||
'status' => null, | ||
'class' => $this->groupManager->getClass(), | ||
'multiple' => true, | ||
'expanded' => true, | ||
'disabled' => !$this->isMaster(), | ||
]) | ||
; | ||
} | ||
|
||
public function getParent(): string | ||
{ | ||
return EntityType::class; | ||
} | ||
|
||
private function isMaster(): bool | ||
{ | ||
return $this->groupAdmin->isGranted('EDIT'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters