Closed davidcr01 closed 1 year ago
This behavior has not been seen until now. It seems there are problems with the permissions of the staff users. Although they are staff, they can not see the Djapi models.
It has been observed that, if a staff user has assigned the permissions to manage these models, they appear in the Admin site.
So, it is necessary to assign permissions when creating a staff user. To perform this, a new code snippet has been created:
@receiver(post_save, sender=CustomUser)
def assign_permissions(sender, instance, created, **kwargs):
if created and instance.is_staff:
staff_group, created = Group.objects.get_or_create(name='Staff')
if created:
# Obtener los permisos necesarios para gestionar CustomUser y Player
customuser_content_type = ContentType.objects.get(app_label='djapi', model='customuser')
player_content_type = ContentType.objects.get(app_label='djapi', model='player')
customuser_permissions = Permission.objects.filter(content_type=customuser_content_type)
player_permissions = Permission.objects.filter(content_type=player_content_type)
# Asignar los permisos al grupo "Staff"
staff_group.permissions.set(customuser_permissions | player_permissions)
# Agregar el usuario al grupo "Staff"
staff_group.user_set.add(instance)
This snippet is added in the models.py
, after the definition of the models.
The code is executed when a post_save signal is received from the CustomUser model. If the instance is created and is a staff member, the code creates or gets a group called Staff.
If the Staff group is not created, it assigns to the group the CustomUser
and Player
permissions and always assigns to the staff user the group Staff.
The conditional of if created
avoids assigning the permissions to the group every time a staff member is created.
There are no groups:
A new staff member is created and the group "Staff" is created and assigned:
And the staff members now can see the User and Player models:
Description
It has been observed that when creating a new Administrator (is_staff is True) they can not see anything on the Admin site, but they can access the Admin site.
Is necessary to investigate this and fix it.