Skip to content

Commit

Permalink
fix: improve ModelAdmins for ADGroupMapping and ADGroup
Browse files Browse the repository at this point in the history
Adds new columns, sorting, searching, filtering and default ordering.

Refs: RAT-173
  • Loading branch information
voneiden authored and charn committed Jun 3, 2024
1 parent dc3e452 commit 8135f14
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions helusers/admin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
from django.conf import settings
from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from .models import ADGroup, ADGroupMapping, OIDCBackChannelLogoutEvent


@admin.register(ADGroupMapping)
class ADGroupMappingAdmin(admin.ModelAdmin):
pass


admin.site.register(ADGroup)
list_display = [
"get_str",
"get_ad_group_name",
"get_ad_group_display_name",
"group",
]
list_filter = ("group",)
search_fields = (
"group__name",
"ad_group__name",
"ad_group__display_name",
)

ordering = ("ad_group__display_name", "group")

@admin.display(description="Mapping")
def get_str(self, obj):
return str(obj)

@admin.display(description=_("AD group name"), ordering="ad_group__name")
def get_ad_group_name(self, obj):
return obj.ad_group.name

@admin.display(
description=_("AD group display name"), ordering="ad_group__display_name"
)
def get_ad_group_display_name(self, obj):
return obj.ad_group.display_name


@admin.register(ADGroup)
class ADGroupAdmin(admin.ModelAdmin):
list_display = [
"display_name",
"name",
]
search_fields = (
"display_name",
"name",
)
ordering = ("display_name", "name")


if getattr(settings, "HELUSERS_BACK_CHANNEL_LOGOUT_ENABLED", False):
Expand Down

0 comments on commit 8135f14

Please sign in to comment.