Skip to content

Commit

Permalink
Beautify the little auth admin, drop the user permissions field
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Aug 19, 2024
1 parent 5d862d9 commit 7334ee7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Next version
- Added support for Django 5.1.
- Exempted our login views from the ``LoginRequiredMiddleware``.
- Dropped Django 4.1 from the CI. 3.2 is still there.
- Changed the default ``authlib.little_auth`` admin to hide the user
permissions field; permissions should preferrably be added via authlib roles,
or less preferrably via group permissions.


0.16 (2023-09-17)
Expand Down
6 changes: 5 additions & 1 deletion authlib/base_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class BaseUser(auth_models.AbstractBaseUser, auth_models.PermissionsMixin):

email = models.EmailField(_("email"), max_length=254, unique=True)
is_active = models.BooleanField(_("is active"), default=True)
is_staff = models.BooleanField(_("is staff"), default=False)
is_staff = models.BooleanField(
_("is staff"),
default=False,
help_text=_("Designates whether the user can log into this admin site."),
)
date_joined = models.DateTimeField(_("date joined"), default=timezone.now)

objects = BaseUserManager()
Expand Down
39 changes: 37 additions & 2 deletions authlib/little_auth/admin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as StockUserAdmin
from django.utils.translation import gettext_lazy as _

from authlib.little_auth.models import User


@admin.register(User)
class UserAdmin(StockUserAdmin):
fieldsets = None
add_fieldsets = (
(None, {"classes": ("wide",), "fields": ("email", "password1", "password2")}),
(None, {"classes": ["wide"], "fields": ("email", "password1", "password2")}),
)
fieldsets = [
(
None,
{
"fields": [
"is_active",
"email",
"password",
"full_name",
]
},
),
(
_("Permissions"),
{
"fields": [
"is_staff",
"is_superuser",
"role",
]
},
),
(
_("Advanced"),
{
"classes": ["collapse"],
"fields": [
"date_joined",
"last_login",
"groups",
],
},
),
]
list_display = (
"email",
"full_name",
Expand All @@ -24,3 +58,4 @@ class UserAdmin(StockUserAdmin):
search_fields = ("full_name", "email")
filter_horizontal = ("groups", "user_permissions")
radio_fields = {"role": admin.VERTICAL}
readonly_fields = ["last_login"]
6 changes: 5 additions & 1 deletion authlib/little_auth/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ class Migration(migrations.Migration):
),
(
"is_staff",
models.BooleanField(default=False, verbose_name="is staff"),
models.BooleanField(
default=False,
help_text="Designates whether the user can log into this admin site.",
verbose_name="is staff",
),
),
(
"date_joined",
Expand Down

0 comments on commit 7334ee7

Please sign in to comment.