Fix new WS middleware for old auth method, improve auth token admin panel

This commit is contained in:
Reckless_Satoshi 2023-05-07 14:28:44 -07:00
parent 2293a8922d
commit af0289c264
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
3 changed files with 22 additions and 2 deletions

View File

@ -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 = (

View File

@ -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)

View File

@ -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"