-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[User] Implement groups to simplify roles and permissions.
- Loading branch information
1 parent
fc65bfa
commit b15d646
Showing
16 changed files
with
385 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Clastic package. | ||
* | ||
* (c) Dries De Peuter <dries@nousefreak.be> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Clastic\UserBundle\Controller; | ||
|
||
use Clastic\BackofficeBundle\Controller\AbstractModuleController; | ||
use Clastic\UserBundle\Entity\Group; | ||
use Clastic\UserBundle\Form\Type\GroupFormType; | ||
use Symfony\Component\Form\Form; | ||
|
||
/** | ||
* GroupController. | ||
* | ||
* @author Dries De Peuter <dries@nousefreak.be> | ||
*/ | ||
class GroupController extends AbstractModuleController | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
protected function getType() | ||
{ | ||
return 'user_group'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getListTemplate() | ||
{ | ||
return 'ClasticUserBundle:Backoffice:group_list.html.twig'; | ||
} | ||
|
||
/** | ||
* @param Group $data | ||
* | ||
* @return Form | ||
*/ | ||
protected function buildForm($data) | ||
{ | ||
return $this->createForm(new GroupFormType(), $data); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getEntityName() | ||
{ | ||
return 'ClasticUserBundle:Group'; | ||
} | ||
|
||
/** | ||
* @param Group $data | ||
* | ||
* @return string | ||
*/ | ||
protected function resolveDataTitle($data) | ||
{ | ||
if (!$data->getId()) { | ||
return 'New'; | ||
} | ||
|
||
return $data->getName(); | ||
} | ||
|
||
/** | ||
* @param int $id | ||
* | ||
* @return Group | ||
*/ | ||
protected function resolveData($id) | ||
{ | ||
if (!is_null($id)) { | ||
return $this->getDoctrine()->getRepository('ClasticUserBundle:Group') | ||
->find($id); | ||
} | ||
|
||
return new Group(''); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Clastic package. | ||
* | ||
* (c) Dries De Peuter <dries@nousefreak.be> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Clastic\UserBundle\Entity; | ||
|
||
use FOS\UserBundle\Model\Group as BaseGroup; | ||
|
||
/** | ||
* @author Dries De Peuter <dries@nousefreak.be> | ||
*/ | ||
class Group extends BaseGroup | ||
{ | ||
function __toString() | ||
{ | ||
return $this->getName(); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Clastic package. | ||
* | ||
* (c) Dries De Peuter <dries@nousefreak.be> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Clastic\UserBundle\Entity; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
|
||
/** | ||
* GroupRepository. | ||
* | ||
* @author Dries De Peuter <dries@nousefreak.be> | ||
*/ | ||
class GroupRepository extends EntityRepository | ||
{ | ||
} |
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,102 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Clastic package. | ||
* | ||
* (c) Dries De Peuter <dries@nousefreak.be> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Clastic\UserBundle\Form\Type; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
|
||
/** | ||
* UserType. | ||
* | ||
* @author Dries De Peuter <dries@nousefreak.be> | ||
*/ | ||
class GroupFormType extends AbstractType | ||
{ | ||
/** | ||
* @param FormBuilderInterface $builder | ||
* @param array $options | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder | ||
->add( | ||
$builder->create('tabs', 'tabs', ['inherit_data' => true]) | ||
->add($this->createGeneralTab($builder)) | ||
->add($this->createActionTab($builder)) | ||
); | ||
} | ||
|
||
private function getAvailableRoles(FormBuilderInterface $builder) | ||
{ | ||
$roles = [ | ||
'ROLE_ADMIN' => 'Admin', | ||
'ROLE_USER' => 'User', | ||
]; | ||
|
||
return $roles; | ||
} | ||
|
||
private function createGeneralTab(FormBuilderInterface $builder) | ||
{ | ||
return $this->createTab( | ||
$builder, | ||
'general', | ||
['label' => 'user.form.tab.general.label'] | ||
) | ||
->add('name', 'text', ['label' => 'user_group.form.tab.general.field.name']) | ||
->add('roles', 'multi_select', [ | ||
'choices' => $this->getAvailableRoles($builder), | ||
'label' => 'user.form.tab.role.field.roles', | ||
]); | ||
} | ||
|
||
private function createActionTab(FormBuilderInterface $builder) | ||
{ | ||
return $builder->create('actions', 'tabs_tab_actions', [ | ||
'mapped' => false, | ||
'inherit_data' => true, | ||
]) | ||
->add('save', 'submit', [ | ||
'label' => 'node.form.tab.action.field.save', | ||
'attr' => ['class' => 'btn btn-success'], | ||
]); | ||
} | ||
|
||
private function createTab(FormBuilderInterface $builder, $name, $options = array()) | ||
{ | ||
$options = array_replace( | ||
$options, | ||
['inherit_data' => true] | ||
); | ||
|
||
return $builder->create($name, 'tabs_tab', $options); | ||
} | ||
|
||
/** | ||
* @param OptionsResolverInterface $resolver | ||
*/ | ||
public function setDefaultOptions(OptionsResolverInterface $resolver) | ||
{ | ||
$resolver->setDefaults([ | ||
'translation_domain' => 'clastic', | ||
]); | ||
} | ||
|
||
/** | ||
* Returns the name of this type. | ||
* | ||
* @return string The name of this type | ||
*/ | ||
public function getName() | ||
{ | ||
return 'clastic_user_group'; | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Clastic package. | ||
* | ||
* (c) Dries De Peuter <dries@nousefreak.be> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Clastic\UserBundle\Module; | ||
|
||
use Clastic\CoreBundle\Module\AdministrationModuleInterface; | ||
use Clastic\CoreBundle\Module\ModuleInterface; | ||
|
||
/** | ||
* @author Dries De Peuter <dries@nousefreak.be> | ||
*/ | ||
class GroupModule implements ModuleInterface, AdministrationModuleInterface | ||
{ | ||
/** | ||
* The name of the module. | ||
* | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return 'Group'; | ||
} | ||
|
||
/** | ||
* The the unique identifier of the module. | ||
* | ||
* @return string | ||
*/ | ||
public function getIdentifier() | ||
{ | ||
return 'user_group'; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Clastic/UserBundle/Resources/config/doctrine/Group.orm.xml
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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | ||
<entity table="Groups" repository-class="Clastic\UserBundle\Entity\GroupRepository" name="Clastic\UserBundle\Entity\Group"> | ||
<id name="id" type="integer" column="id"> | ||
<generator strategy="AUTO"/> | ||
</id> | ||
</entity> | ||
</doctrine-mapping> |
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
Oops, something went wrong.