diff --git a/api/admin.py b/api/admin.py index 33cadde7..e78b32d2 100644 --- a/api/admin.py +++ b/api/admin.py @@ -4,12 +4,15 @@ from django.contrib import admin, messages from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import Group, User from django_admin_relation_links import AdminChangeLinksMixin +from rest_framework.authtoken.admin import TokenAdmin +from rest_framework.authtoken.models import TokenProxy from api.logics import Logics from api.models import Currency, LNPayment, MarketTick, OnchainPayment, Order, Robot admin.site.unregister(Group) admin.site.unregister(User) +admin.site.unregister(TokenProxy) class RobotInline(admin.StackedInline): @@ -41,6 +44,22 @@ class EUserAdmin(AdminChangeLinksMixin, UserAdmin): return obj.robot.avatar_tag() +# extended tokens with raw id fields and avatars +@admin.register(TokenProxy) +class ETokenAdmin(AdminChangeLinksMixin, TokenAdmin): + raw_id_fields = ["user"] + list_display = ( + "avatar_tag", + "key", + "user_link", + ) + list_display_links = ("key",) + change_links = ("user",) + + def avatar_tag(self, obj): + return obj.user.robot.avatar_tag() + + @admin.register(Order) class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin): list_display = ( diff --git a/robosats/middleware.py b/robosats/middleware.py index fb13a280..fbd9878c 100644 --- a/robosats/middleware.py +++ b/robosats/middleware.py @@ -162,7 +162,8 @@ class TokenAuthMiddleware(BaseMiddleware): token_key = hex_to_base91(token_key) except ValueError: token_key = None + scope["user"] = ( - AnonymousUser() if token_key is None else await get_user(token_key) + scope["user"] if token_key is None else await get_user(token_key) ) return await super().__call__(scope, receive, send) diff --git a/robosats/urls.py b/robosats/urls.py index b73c16b9..2a988cd4 100644 --- a/robosats/urls.py +++ b/robosats/urls.py @@ -28,6 +28,6 @@ urlpatterns = [ path("", include("frontend.urls")), ] -admin.site.site_header = f"RoboSats Coordinator: {config('COORDINATOR_ALIAS', cast=str, default='NoAlias')} {config('NETWORK', cast=str, default='')} (v{VERSION['major']}.{VERSION['minor']}.{VERSION['patch']})" +admin.site.site_header = f"RoboSats Coordinator: {config('COORDINATOR_ALIAS', cast=str, default='NoAlias')} {config('NETWORK', cast=str, default='')} (v{VERSION['major']}.{VERSION['minor']}.{VERSION['patch']})".title() admin.site.index_title = "Coordinator administration" admin.site.site_title = "RoboSats Coordinator Admin"