From b038cdfdf5f1a2261e52ac473c95127ad301b380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 20 Apr 2017 16:27:33 +0200 Subject: [PATCH] fix bug when the form "add role" fails --- Controller/PermissionsGroupController.php | 33 ++++++++++++++++++++--- Resources/translations/validators.fr.yml | 2 ++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Controller/PermissionsGroupController.php b/Controller/PermissionsGroupController.php index 38b893e74..fb32f6c8d 100644 --- a/Controller/PermissionsGroupController.php +++ b/Controller/PermissionsGroupController.php @@ -246,10 +246,13 @@ class PermissionsGroupController extends Controller { $em = $this->getDoctrine()->getManager(); - $permissionsGroup = $em->getRepository('ChillMainBundle:PermissionsGroup')->find($id); + $permissionsGroup = $em + ->getRepository('ChillMainBundle:PermissionsGroup') + ->find($id); if (!$permissionsGroup) { - throw $this->createNotFoundException('Unable to find PermissionsGroup entity.'); + throw $this->createNotFoundException('Unable to find Permissions' + . 'Group entity.'); } $editForm = $this->createEditForm($permissionsGroup); @@ -269,9 +272,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) { @@ -418,10 +433,22 @@ 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, 'edit_form' => $editForm->createView(), + 'role_scopes_sorted' => $roleScopesSorted, 'expanded_roles' => $this->getExpandedRoles($permissionsGroup->getRoleScopes()->toArray()), 'delete_role_scopes_form' => array_map( function($form) { diff --git a/Resources/translations/validators.fr.yml b/Resources/translations/validators.fr.yml index d350da82c..4307be2fb 100644 --- a/Resources/translations/validators.fr.yml +++ b/Resources/translations/validators.fr.yml @@ -4,3 +4,5 @@ The role "%role%" require to be associated with a scope.: Le rôle "%role%" doit The role "%role%" should not be associated with a scope.: Le rôle "%role%" ne doit pas être associé à un cercle. "The password must contains one letter, one capitalized letter, one number and one special character as *[@#$%!,;:+\"'-/{}~=µ()£]). Other characters are allowed.": "Le mot de passe doit contenir une majuscule, une minuscule, et au moins un caractère spécial parmi *[@#$%!,;:+\"'-/{}~=µ()£]). Les autres caractères sont autorisés." The password fields must match: Les mots de passe doivent correspondre + +A permission is already present for the same role and scope: Une permission est déjà présente pour le même rôle et cercle. \ No newline at end of file