[Sprinkle-Admin] User_defaults.group doesn't work on Form "Create User"
H1ghSyst3m opened this issue · comments
In the Dashboard -> Users -> [Create User]
The predefined group is always the group of the current logged-in User that is creating the user.
Even when I change in default.php -> registration.user_defaults.group => 'example group'
As Example when my User is in the Group "Admin" then the predefined Group in the Create User Form is "Admin" and when my Group is "rater" then the predefined Group in the Form is "Rater".
The problem could lie in the file admin/src/Controller/UserController.php
in the line 623
at code:
$data = [
'group_id' => $currentUser->group_id,
'locale' => $config['site.registration.user_defaults.locale'],
'theme' => '',
];
Chat discussion : https://chat.userfrosting.com/channel/support?msg=ASwCH8JuSiq35unRF
Culprit is here :
UserFrosting/app/sprinkles/admin/src/Controller/UserController.php
Lines 623 to 624 in ca9cf96
It shouldn't be the current user group here, but the default group ID. And it must be an ID, since "edit" modal use the same template, and it's comparing ID with ID.
UserFrosting/app/sprinkles/admin/templates/forms/user.html.twig
Lines 31 to 32 in ca9cf96
Note it's not as easy as to switch like this :
// Determine if currentUser has permission to modify the group. If so, show the 'group' dropdown.
// Otherwise, set to the currentUser's group and disable the dropdown.
$defaultGroupSlug = $this->config->get('site.registration.user_defaults.group');
$defaultGroup = $this->groupModel::where('slug', $defaultGroupSlug)->firstOrFail();
if ($this->authenticator->checkAccess('create_user_field', [
'fields' => ['group'],
])) {
// Get a list of all groups
$groups = $this->groupModel::all();
} else {
// Get the current user's group
$groups = [$defaultGroup];
$fields['disabled'][] = 'group';
}
// Create a dummy user to pre-populate fields
$user = new $this->userModel([
'group_id' => $defaultGroup->id,
'locale' => $this->config->get('site.registration.user_defaults.locale'),
]);
This could work, however an error would be thrown if the $defaultGroupSlug
doesn't exist in the database. It also need to account "No Group" (empty string in config) could be a valid default group (and the new default in V5).
After consideration, In UF5 this is not really an issue. Default group is not selected when creating a user, but I think this is acceptable.
The real issue is the default group should be set in the database. It would then be easier to set. I'm closing this for now, until group is reworked in a future version.