From: Raphaƫl Gertz Date: Mon, 7 Dec 2020 22:11:46 +0000 (+0100) Subject: Remove default ROLE_USER role from user entity, group(s), by title(s), (is|are) now... X-Git-Tag: 0.1.4~4 X-Git-Url: https://git.rapsys.eu/userbundle/commitdiff_plain/737374b8cf79d853c2701b72b0a0a56f2ab3de35?ds=sidebyside;hp=6381d6c9672c4b85800b3c4339cf7aac7cba4637 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 --- 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 )]; }