From 75f505bbad8fb34c25c3d2fdc5f0fec6f9273480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Tue, 23 Jul 2019 08:56:44 +0200 Subject: [PATCH 1/4] upgrades to admin: search_fields, list_filters and raw_id_field --- oauth2_provider/admin.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/oauth2_provider/admin.py b/oauth2_provider/admin.py index 58b5308fd..5b2c3c6e4 100644 --- a/oauth2_provider/admin.py +++ b/oauth2_provider/admin.py @@ -1,4 +1,5 @@ from django.contrib import admin +from django.contrib.auth import get_user_model from oauth2_provider.models import ( get_access_token_admin_class, @@ -13,6 +14,8 @@ get_refresh_token_model, ) +has_email = hasattr(get_user_model(), 'email') + class ApplicationAdmin(admin.ModelAdmin): list_display = ("id", "name", "user", "client_type", "authorization_grant_type") @@ -28,6 +31,8 @@ class AccessTokenAdmin(admin.ModelAdmin): list_display = ("token", "user", "application", "expires") list_select_related = ("application", "user") raw_id_fields = ("user", "source_refresh_token") + search_fields = ("token",) + (("user__email",) if has_email else ()) + list_filter = ("application",) class GrantAdmin(admin.ModelAdmin): @@ -37,12 +42,18 @@ class GrantAdmin(admin.ModelAdmin): class IDTokenAdmin(admin.ModelAdmin): list_display = ("jti", "user", "application", "expires") - raw_id_fields = ("user",) + raw_id_fields = ("user", ) + search_fields = ("token",) + (("user__email",) if has_email else ()) + list_filter = ("application",) + + class RefreshTokenAdmin(admin.ModelAdmin): list_display = ("token", "user", "application") raw_id_fields = ("user", "access_token") + search_fields = ("token",) + (("user__email",) if has_email else ()) + list_filter = ("application",) application_model = get_application_model() From e8be373076c58744e5c643775e9a47e8bc29d4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Thu, 16 Dec 2021 15:02:53 +0100 Subject: [PATCH 2/4] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36615dcc4..768e577ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * #967 OpenID: Add claims to Well know * #1019 #1024 #1026 #1030 #1033 #1036 [pre-commit.ci] pre-commit autoupdate * #1021 Jazzband: Synced file(s) with jazzband/.github +* #1041 Admin: make extensive fields raw_id, add search fields ## [Changed] * #1022 Replaced pkg_resources usage with importlib.metadata From 6c2fe91de337f48c49169a69501c231b42fb25f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Thu, 16 Dec 2021 15:04:13 +0100 Subject: [PATCH 3/4] add name to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index e47665e66..deb0c7ce4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -47,6 +47,7 @@ Paul Dekkers Paul Oswald Pavel Tvrdík Peter Carnesciali +Petr Dlouhý Rodney Richardson Rustem Saiargaliev Sandro Rodrigues From ddeb758c0832a74545f8aab81700abf119eae324 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 Dec 2021 14:09:39 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- oauth2_provider/admin.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/oauth2_provider/admin.py b/oauth2_provider/admin.py index 5b2c3c6e4..bd26dddb1 100644 --- a/oauth2_provider/admin.py +++ b/oauth2_provider/admin.py @@ -14,7 +14,8 @@ get_refresh_token_model, ) -has_email = hasattr(get_user_model(), 'email') + +has_email = hasattr(get_user_model(), "email") class ApplicationAdmin(admin.ModelAdmin): @@ -42,13 +43,11 @@ class GrantAdmin(admin.ModelAdmin): class IDTokenAdmin(admin.ModelAdmin): list_display = ("jti", "user", "application", "expires") - raw_id_fields = ("user", ) + raw_id_fields = ("user",) search_fields = ("token",) + (("user__email",) if has_email else ()) list_filter = ("application",) - - class RefreshTokenAdmin(admin.ModelAdmin): list_display = ("token", "user", "application") raw_id_fields = ("user", "access_token")