mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 02:21:35 +00:00
Fix new WS middleware for old auth method, improve auth token admin panel
This commit is contained in:
parent
2293a8922d
commit
af0289c264
19
api/admin.py
19
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 = (
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user