Skip to content

Commit 4e6bb75

Browse files
committed
sqladmin
1 parent 00edd59 commit 4e6bb75

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

auth_backend/admin/admin.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from sqladmin import ModelView
2+
3+
from auth_backend.models.db import Scope, Group, User
4+
5+
6+
class ScopeAdmin(ModelView, model=Scope):
7+
name = "Scope"
8+
name_plural = "Scopes"
9+
column_list = ["id", "name", "comment", "is_deleted", "create_ts"]
10+
column_searchable_list = ["name", "comment"]
11+
12+
13+
class GroupAdmin(ModelView, model=Group):
14+
name = "Group"
15+
name_plural = "Groups"
16+
column_list = ["id", "name", "parent_id", "is_deleted", "create_ts"]
17+
column_searchable_list = ["name"]
18+
19+
20+
class UserAdmin(ModelView, model=User):
21+
name = "User"
22+
name_plural = "Users"
23+
column_list = ["id", "is_deleted", "create_ts"]

auth_backend/routes/base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
from fastapi_sqlalchemy import DBSessionMiddleware
55
from starlette.middleware.cors import CORSMiddleware
66

7+
from sqladmin import Admin
8+
from sqlalchemy import create_engine
9+
from auth_backend.admin.admin import ScopeAdmin, GroupAdmin, UserAdmin
10+
711
from auth_backend import __version__
812
from auth_backend.auth_method import AuthPluginMeta
913
from auth_backend.kafka.kafka import get_kafka_producer
@@ -23,6 +27,9 @@ async def lifespan(app: FastAPI):
2327

2428

2529
settings = get_settings()
30+
31+
engine = create_engine(str(settings.DB_DSN))
32+
2633
app = FastAPI(
2734
title='Сервис аутентификации и авторизации',
2835
description=(
@@ -37,6 +44,8 @@ async def lifespan(app: FastAPI):
3744
lifespan=lifespan,
3845
)
3946

47+
admin=Admin(app, engine=engine, title='Admin panel')
48+
4049
app.add_middleware(
4150
DBSessionMiddleware,
4251
db_url=str(settings.DB_DSN),
@@ -51,6 +60,10 @@ async def lifespan(app: FastAPI):
5160
allow_headers=settings.CORS_ALLOW_HEADERS,
5261
)
5362

63+
admin.add_view(GroupAdmin)
64+
admin.add_view(ScopeAdmin)
65+
admin.add_view(UserAdmin)
66+
5467
app.include_router(groups_router)
5568
app.include_router(scopes_router)
5669
app.include_router(user_router)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ confluent-kafka
1616
event-schema-profcomff
1717
aiocache
1818
python-multipart
19+
sqladmin[full]
1920

2021
# Google Auth Method
2122
google-api-python-client

0 commit comments

Comments
 (0)