Make a hierarchy in roles

This is more understandable for users.
This commit is contained in:
2017-04-19 21:24:35 +02:00
parent b6d1f05e00
commit 0e5ab47474
7 changed files with 190 additions and 33 deletions

View File

@@ -108,6 +108,8 @@ class PermissionsGroupController extends Controller
$translatableStringHelper = $this->get('chill.main.helper.translatable_string');
$roleScopes = $permissionsGroup->getRoleScopes()->toArray();
// sort $roleScopes by name
usort($roleScopes,
function(RoleScope $a, RoleScope $b) use ($translatableStringHelper) {
if ($a->getScope() === NULL) {
@@ -122,10 +124,21 @@ class PermissionsGroupController extends Controller
$translatableStringHelper->localize($b->getScope()->getName())
);
});
// sort role scope by title
/* @var $roleProvider \Chill\MainBundle\Security\RoleProvider */
$roleProvider = $this->get('chill.main.role_provider');
$roleScopesSorted = array();
foreach($roleScopes as $roleScope) {
/* @var $roleScope RoleScope */
$title = $roleProvider->getRoleTitle($roleScope->getRole());
$roleScopesSorted[$title][] = $roleScope;
}
ksort($roleScopesSorted);
return $this->render('ChillMainBundle:PermissionsGroup:show.html.twig', array(
'entity' => $permissionsGroup,
'role_scopes' => $roleScopes,
'role_scopes_sorted' => $roleScopesSorted,
'expanded_roles' => $this->getExpandedRoles($roleScopes)
));
}
@@ -171,6 +184,7 @@ class PermissionsGroupController extends Controller
throw $this->createNotFoundException('Unable to find PermissionsGroup entity.');
}
// create all the forms
$editForm = $this->createEditForm($permissionsGroup);
$deleteRoleScopesForm = array();
@@ -180,9 +194,21 @@ class PermissionsGroupController extends Controller
}
$addRoleScopesForm = $this->createAddRoleScopeForm($permissionsGroup);
// sort role scope by title
/* @var $roleProvider \Chill\MainBundle\Security\RoleProvider */
$roleProvider = $this->get('chill.main.role_provider');
$roleScopesSorted = array();
foreach($permissionsGroup->getRoleScopes()->toArray() as $roleScope) {
/* @var $roleScope RoleScope */
$title = $roleProvider->getRoleTitle($roleScope->getRole());
$roleScopesSorted[$title][] = $roleScope;
}
ksort($roleScopesSorted);
return $this->render('ChillMainBundle:PermissionsGroup:edit.html.twig', array(
'entity' => $permissionsGroup,
'role_scopes_sorted' => $roleScopesSorted,
'edit_form' => $editForm->createView(),
'expanded_roles' => $this->getExpandedRoles($permissionsGroup->getRoleScopes()->toArray()),
'delete_role_scopes_form' => array_map( function($form) {