Commit 937bbfda authored by Nicolas Widart's avatar Nicolas Widart

Fix the update and sync roles method

parent d0de62e0
......@@ -75,11 +75,27 @@ class SentryUserRepository implements UserRepository
{
$user = Sentry::findUserById($userId);
$user->update($data);
if (!empty($roles)) {
// Get the user roles
$userRoles = $user->groups()->get()->toArray();
$cleanedRoles = [];
foreach ($userRoles as $role) {
$cleanedRoles[$role['id']] = $role;
}
// Set the new roles
foreach ($roles as $roleId) {
if (isset($cleanedRoles[$roleId])) {
unset($cleanedRoles[$roleId]);
}
$group = Sentry::findGroupById($roleId);
$user->addGroup($group);
}
// Unset the unchecked roles
foreach ($cleanedRoles as $roleId => $role) {
$group = Sentry::findGroupById($roleId);
$user->removeGroup($group);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment