diff --git a/backend/app/admin.py b/backend/app/admin.py deleted file mode 100644 index fd32481..0000000 --- a/backend/app/admin.py +++ /dev/null @@ -1,142 +0,0 @@ -""" -SQLAdmin configuration for administrative interface. - -This module provides a web-based admin panel for managing database models. -The admin panel is mounted at /admin and provides CRUD operations for: -- Users: View and manage OAuth-authenticated users -- Items: View and manage user-created items - -Access Control: -- In production, protect /admin with OAuth2 proxy or network policies -- The admin uses the same database connection as the main app -""" - -from sqladmin import Admin, ModelView -from sqlalchemy import Engine - -from app.models import Item, User - - -class UserAdmin(ModelView, model=User): - """Admin view for User model with OAuth context.""" - - name = "User" - name_plural = "Users" - icon = "fa-solid fa-user" - - # List view configuration - column_list = [ - User.id, - User.username, - User.email, - User.full_name, - User.admin, - User.active, - User.last_login, - ] - - # Search configuration - column_searchable_list = [User.username, User.email, User.full_name] - - # Filter configuration - column_sortable_list = [ - User.id, - User.username, - User.email, - User.admin, - User.active, - User.last_login, - User.created_at, - ] - - # Form configuration - exclude auto-generated fields - form_excluded_columns = [ - User.items, # Relationship managed separately - User.created_at, - User.updated_at, - ] - - # Detail view columns - column_details_list = [ - User.id, - User.username, - User.email, - User.full_name, - User.admin, - User.active, - User.created_at, - User.last_login, - User.updated_at, - ] - - # Export configuration - can_export = True - column_export_list = [ - User.id, - User.username, - User.email, - User.full_name, - User.admin, - User.active, - User.created_at, - User.last_login, - ] - - -class ItemAdmin(ModelView, model=Item): - """Admin view for Item model.""" - - name = "Item" - name_plural = "Items" - icon = "fa-solid fa-box" - - # List view configuration - column_list = [ - Item.id, - Item.title, - Item.description, - Item.owner, - ] - - # Search configuration - column_searchable_list = [Item.title, Item.description] - - # Filter configuration - column_sortable_list = [Item.id, Item.title] - - # Detail view columns - column_details_list = [ - Item.id, - Item.title, - Item.description, - Item.owner, - Item.owner_id, - ] - - # Export configuration - can_export = True - - -def setup_admin(app, engine: Engine) -> Admin: - """ - Set up SQLAdmin with the FastAPI application. - - Args: - app: FastAPI application instance - engine: SQLAlchemy engine for database connection - - Returns: - Admin instance configured with all model views - """ - admin = Admin( - app, - engine, - title="Template Admin", - logo_url=None, # Optional: Add logo URL - ) - - # Register model views - admin.add_view(UserAdmin) - admin.add_view(ItemAdmin) - - return admin diff --git a/backend/app/main.py b/backend/app/main.py index a2e8ced..95d9973 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -6,7 +6,7 @@ - Request logging middleware - API routes (REST) - GraphQL endpoint -- Admin panel (SQLAdmin) +- Health check and root endpoints - Lifespan handler with configuration logging - Background task for OAuth state cleanup """ @@ -23,7 +23,6 @@ from strawberry.fastapi import GraphQLRouter import uvicorn -from app.admin import setup_admin from app.api.router import router as api_router from app.api.deps import get_db, get_current_user from app.core.config import settings @@ -140,11 +139,6 @@ async def get_graphql_context( # Include GraphQL endpoint under /api for consistent proxy handling app.include_router(graphql_app, prefix="/api/graphql") -# Setup Admin panel (available at /admin) -# Note: In production, protect /admin with OAuth2 proxy or network policies -setup_admin(app, engine) - - @app.get("/") async def root(): """Root endpoint with API information""" @@ -154,7 +148,6 @@ async def root(): "rest_api": "/api/v1/", "graphql_api": "/api/graphql", "graphql_playground": "/api/graphql (open in browser)", - "admin": "/admin", "docs": "/docs", } diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 8b45d9a..9a49680 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -33,7 +33,6 @@ dependencies = [ "email-validator<3.0.0.0,>=2.1.0.post1", # GraphQL "strawberry-graphql[fastapi]>=0.245.0", - "sqladmin>=0.22.0", # HTTP client for Langflow integration "httpx>=0.28.1", "sse-starlette>=2.2.1", diff --git a/backend/tests/test_main.py b/backend/tests/test_main.py index 8861bc8..384bec3 100644 --- a/backend/tests/test_main.py +++ b/backend/tests/test_main.py @@ -18,7 +18,6 @@ def test_read_root(client: TestClient): assert "version" in data assert data["rest_api"] == "/api/v1/" assert data["graphql_api"] == "/api/graphql" - assert data["admin"] == "/admin" assert data["docs"] == "/docs" @@ -33,10 +32,3 @@ def test_health_check(client: TestClient): assert "database" in data assert data["database"]["status"] == "healthy" assert "message" in data["database"] - - -def test_admin_panel_accessible(client: TestClient): - """Test the admin panel is accessible.""" - response = client.get("/admin/") - # Admin redirects to login or renders directly - assert response.status_code in [200, 302]