-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify jobserver.models.User
#4627
Comments
We once used django.contrib.admin but no longer do (instead having a completely custom staff app). These User model fields were present to mirror django.contrib.auth.models.AbstractUser as django.contrib.admin required. The User model has, for quite some timed, sub-classed AbstractBaseUser, not AbstractUser, to be more customizable. The removed fields were not used anywhere and they and related code were not required. UserManager needed a custom create_user function, as django.contrib.auth.models.UserManager.create_user sets a default for is_staff and is_superuser. This is a hint we should be using BaseUserManager over UserManager. See #4627. The `create_user` management command does not touch these fields explicitly, so no changes.
The User.is_staff and User.is_superuser models fields were not used anywhere so they and related code have been removed. We once used django.contrib.admin but no longer do (instead having a completely custom staff app). The User model has, for some time, sub-classed AbstractBaseUser, not AbstractUser, to be more customizable. The removed User fields are present on AbstractUser but not AbstractBaseUser. They were only present on our User model because django.contrib.admin required them to be present, when we used it. UserManager needed a custom create_user function adding, as django.contrib.auth.models.UserManager.create_user sets a default for is_staff and is_superuser. This may be a hint we should be using BaseUserManager over UserManager. See comments and #4627. The `create_user` management command does not touch these fields explicitly, so no changes there.
The User.is_staff and User.is_superuser models fields were not used anywhere so they and related code have been removed. We once used django.contrib.admin but no longer do (instead having a completely custom staff app). The User model has, for some time, sub-classed AbstractBaseUser, not AbstractUser, to be more customizable. The removed User fields are present on AbstractUser but not AbstractBaseUser. They were only present on our User model because django.contrib.admin required them to be present, when we used it. UserManager needed a custom create_user function adding, as django.contrib.auth.models.UserManager.create_user sets a default for is_staff and is_superuser. This may be a hint we should be using BaseUserManager over UserManager. See comments and #4627. The `create_user` management command does not touch these fields explicitly, so no changes there.
The User.is_staff and User.is_superuser models fields were not used anywhere so they and related code have been removed. We once used django.contrib.admin but no longer do (instead having a completely custom staff app). The User model has, for some time, sub-classed AbstractBaseUser, not AbstractUser, to be more customizable. The removed User fields are present on AbstractUser but not AbstractBaseUser. They were only present on our User model because django.contrib.admin required them to be present, when we used it. UserManager needed a custom create_user function adding, as django.contrib.auth.models.UserManager.create_user sets a default for is_staff and is_superuser. This may be a hint we should be using BaseUserManager over UserManager. See comments and #4627. The `create_user` management command does not touch these fields explicitly, so no changes there.
The User.is_staff and User.is_superuser models fields were not used anywhere so they and related code have been removed. We once used django.contrib.admin but no longer do (instead having a completely custom staff app). The User model has, for some time, sub-classed AbstractBaseUser, not AbstractUser, to be more customizable. The removed User fields are present on AbstractUser but not AbstractBaseUser. They were only present on our User model because django.contrib.admin required them to be present, when we used it. UserManager needed a custom create_user function adding, as django.contrib.auth.models.UserManager.create_user sets a default for is_staff and is_superuser. This may be a hint we should be using BaseUserManager over UserManager. See comments and #4627. The `create_user` management command does not touch these fields explicitly, so no changes there.
The User.is_staff and User.is_superuser models fields were not used anywhere so they and related code have been removed. We once used django.contrib.admin but no longer do (instead having a completely custom staff app). The User model has, for some time, sub-classed AbstractBaseUser, not AbstractUser, to be more customizable. The removed User fields are present on AbstractUser but not AbstractBaseUser. They were only present on our User model because django.contrib.admin required them to be present, when we used it. UserManager needed a custom create_user function adding, as django.contrib.auth.models.UserManager.create_user sets a default for is_staff and is_superuser. This may be a hint we should be using BaseUserManager over UserManager. See comments and #4627. The `create_user` management command does not touch these fields explicitly, so no changes there.
The User.is_staff and User.is_superuser models fields were not used anywhere so they and related code have been removed. We once used django.contrib.admin but no longer do (instead having a completely custom staff app). The User model has, for some time, sub-classed AbstractBaseUser, not AbstractUser, to be more customizable. The removed User fields are present on AbstractUser but not AbstractBaseUser. They were only present on our User model because django.contrib.admin required them to be present, when we used it. UserManager needed a custom create_user function adding, as django.contrib.auth.models.UserManager.create_user sets a default for is_staff and is_superuser. This may be a hint we should be using BaseUserManager over UserManager. See comments and #4627. The `create_user` management command does not touch these fields explicitly, so no changes there.
@mikerkelly to break this into smaller issues. |
This comment investigates the first two bullets from the issue description. How much of Do we need
|
A quick prototype showed that most of the troublesome code in the The only outstanding thing from the description is this:
Raised #4699 for this for triage. |
#4625 removed
User.is_staff
andUser.is_superuser
as no longer required. They were present as we once useddjango.contrib.admin
but no longer do (instead having a completely custom staff app).While working on #4625 I noticed some possible further simplifications to the
models.User
module. There are several more bits of code or peculiarities that may exist for historical reasons but are no longer required. Simplifying the module and using less custom-behaviour where appropriate would aid understanding and maintenance.This might need breaking up into multiple issues. Possible changes to investigate:
BaseUserManager
, as we extendAbstractBaseUser
, rather thanUserManager
that is intended for managingBaseUser
. The names are a little confusing here, careful.super()._create_user
.UserManager.create_user
behaviour around normalizing username and e-mail and hashing the password as we use social auth, but this needs investigation.name
and remove thename
property once all users have filledin their names"get_full_name
needed?UserQuerySet
for sortingorder_by(Lower("fullname"))
once all users havefullname
populated"UserManager
-- as above. Could it be the default?create_user
-- could this be default, or at least be calledUser.objects.create()
to be idiomatic?get_or_create_user
-- if we do the above, is this function then needed or do we get it "for free" by the normalUser.objects.get_or_create_user
machinery?Separate email and username properties if these are always the same?UserQuerySet
docstring / TODOThe text was updated successfully, but these errors were encountered: