Skip to content

Commit

Permalink
[User] Fix super admin losing permissions after save.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoUseFreak committed Mar 22, 2015
1 parent 6e1ae8f commit ba82fc4
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/Clastic/UserBundle/Form/UserType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
* UserType
*
* @author Dries De Peuter <dries@nousefreak.be>
*/
class UserType extends AbstractType
{
private $isNew;

/**
* @param bool $isNew
*/
public function __construct($isNew)
{
$this->isNew = $isNew;
}

/**
* @param FormBuilderInterface $builder
* @param array $options
Expand All @@ -40,6 +46,21 @@ public function buildForm(FormBuilderInterface $builder, array $options)
);
}

private function getAvailableRoles(FormBuilderInterface $builder)
{
$roles = array(
'ROLE_ADMIN' => 'Admin',
'ROLE_USER' => 'User',
);

if ($builder->getData() && $builder->getData()->getId() === 1) {
$roles['ROLE_SUPER_ADMIN'] = sprintf('%s (super)', $roles['ROLE_ADMIN']);
unset($roles['ROLE_ADMIN']);
}

return $roles;
}

private function createGeneralTab(FormBuilderInterface $builder)
{
return $this->createTab($builder, 'general', array('label' => 'General'))
Expand Down Expand Up @@ -70,10 +91,7 @@ private function createRoleTab(FormBuilderInterface $builder)
{
return $this->createTab($builder, 'role', array('label' => 'Role'))
->add('roles', 'multi_select', array(
'choices' => array(
'ROLE_ADMIN' => 'Admin',
'ROLE_USER' => 'User',
),
'choices' => $this->getAvailableRoles($builder),
));
}

Expand Down

0 comments on commit ba82fc4

Please sign in to comment.