From 737374b8cf79d853c2701b72b0a0a56f2ab3de35 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Mon, 7 Dec 2020 23:11:46 +0100 Subject: [PATCH 1/1] Remove default ROLE_USER role from user entity, group(s), by title(s), (is|are) now added from rapsys_user.default.group array at registration --- Entity/User.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Entity/User.php b/Entity/User.php index cca45c7..8286e55 100644 --- a/Entity/User.php +++ b/Entity/User.php @@ -319,9 +319,10 @@ class User implements UserInterface, \Serializable { $array[$group->getId()] = $group->getRole(); return $array; }, - //Init with ROLE_USER - //XXX: we assume that ROLE_USER has id 1 in database - [ 1 => 'ROLE_USER' ] + //Init with empty array + //XXX: on registration, add each group present in rapsys_user.default.group array to user + //XXX: see vendor/rapsys/userbundle/Controller/DefaultController.php +450 + [] )); } @@ -329,17 +330,23 @@ class User implements UserInterface, \Serializable { //Retrieve roles $roles = $this->getRoles(); + //With roles array empty + if ($roles === []) { + //Return null + return null; + } + //Return the role with max id //XXX: should be rewriten if it change in your configuration return $roles[array_reduce( array_keys($roles), function($cur, $id) { - if ($id > $cur) { + if ($cur === null || $id > $cur) { return $id; } return $cur; }, - 0 + null )]; } -- 2.41.1