Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ jobs:
enable-cache: false
version: "0.9.12"

- name: Set up Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2

- name: Build frontend
working-directory: frontend
run: |
bun install --frozen-lockfile
bun run build

- name: Copy frontend build into package static directory
run: |
rm -rf src/litestar_admin/static
cp -r frontend/out src/litestar_admin/static

- name: Build package
run: uv build

Expand Down Expand Up @@ -95,7 +109,7 @@ jobs:
args: --current --strip header

- name: Create GitHub Release (Draft)
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2
uses: softprops/action-gh-release@26e8ad27a09a225049a7075d7ec1caa2df6ff332 # v2.6.0
with:
draft: true
files: |
Expand Down Expand Up @@ -138,7 +152,7 @@ jobs:
contents: write
steps:
- name: Mark Release as Published
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2
uses: softprops/action-gh-release@26e8ad27a09a225049a7075d7ec1caa2df6ff332 # v2.6.0
with:
draft: false

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ frontend-build: ## Build frontend without copying

##@ Build & Release

build: clean ## Build package
build: clean frontend ## Build package (includes frontend)
@uv build

clean: ## Clean build artifacts and caches
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies = [
"advanced-alchemy>=0.10.0",
"sqlalchemy[asyncio]>=2.0.0",
"aiofiles>=25.1.0",
"typing-extensions>=4.0.0; python_version < '3.11'",
]

[project.optional-dependencies]
Expand Down Expand Up @@ -138,6 +139,7 @@ max-complexity = 12
]
"examples/**/*" = ["ARG", "B008", "D", "FAST", "FBT", "PLR1714", "RET504", "RUF012", "S101", "S104", "S106", "SIM108", "T201", "TC002"]
"src/litestar_admin/controllers/**/*" = ["B008"] # Litestar Parameter defaults
"docs/conf.py" = ["INP001", "PTH100"]

[tool.ruff.lint.pydocstyle]
convention = "google"
Expand Down Expand Up @@ -262,6 +264,7 @@ test = [
"pyjwt>=2.8.0", # Required for JWT auth tests
"structlog>=24.1.0", # Required for structlog logging tests
"fakeredis[lua]>=2.26.0", # Required for Redis store tests
"litestar-permissions>=0.1.3; python_version >= '3.12'", # Required for permissions integration tests
]
dev = [
{include-group = "docs"},
Expand Down
3 changes: 2 additions & 1 deletion src/litestar_admin/audit/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ async def query(self, filters: AuditQueryFilters) -> list[AuditEntry]:
Returns:
List of matching audit entries, sorted by timestamp descending.
"""
results = list(self._entries)
# Newest-inserted first so entries with equal timestamps stay most-recent-first after the stable sort
results = list(reversed(self._entries))

# Apply filters
if filters.action is not None:
Expand Down
5 changes: 3 additions & 2 deletions src/litestar_admin/audit/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import contextlib
import re
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, ClassVar
from typing import TYPE_CHECKING, Any, Literal

from litestar.enums import ScopeType
from litestar.middleware import AbstractMiddleware
from litestar.status_codes import HTTP_200_OK, HTTP_300_MULTIPLE_CHOICES

Expand Down Expand Up @@ -107,7 +108,7 @@ class AuditMiddleware(AbstractMiddleware):
middleware = AuditMiddleware(logger, config=config)
"""

scopes: ClassVar[set[str]] = {"http"}
scopes: set[Literal[ScopeType.HTTP, ScopeType.WEBSOCKET]] = {ScopeType.HTTP} # noqa: RUF012

def __init__(
self,
Expand Down
10 changes: 8 additions & 2 deletions src/litestar_admin/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ class CustomAdminUser(AdminUserBase):

from __future__ import annotations

import sys
import uuid
from datetime import datetime, timezone
from typing import Any, ClassVar, Self
from typing import Any

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

from sqlalchemy import JSON, Boolean, DateTime, Index, String
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
Expand Down Expand Up @@ -123,7 +129,7 @@ class AdminUser(AdminUserBase):
await session.commit()
"""

__tablename__: ClassVar[str] = "admin_users"
__tablename__: str = "admin_users"

# Primary key
id: Mapped[str] = mapped_column(
Expand Down
6 changes: 3 additions & 3 deletions src/litestar_admin/auth/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def hash(self, password: str) -> str:
if not PasswordHasher._available or PasswordHasher._context is None:
msg = "No password hashing backend available. Install 'litestar-admin[auth]' or 'passlib[argon2]'."
raise RuntimeError(msg)
return PasswordHasher._context.hash(password) # type: ignore[union-attr]
return PasswordHasher._context.hash(password) # type: ignore[union-attr] # ty: ignore[unresolved-attribute]

def verify(self, password: str, password_hash: str) -> bool:
"""Verify a password against its hash.
Expand All @@ -195,7 +195,7 @@ def verify(self, password: str, password_hash: str) -> bool:
if not PasswordHasher._available or PasswordHasher._context is None:
msg = "No password hashing backend available. Install 'litestar-admin[auth]' or 'passlib[argon2]'."
raise RuntimeError(msg)
return PasswordHasher._context.verify(password, password_hash) # type: ignore[union-attr]
return PasswordHasher._context.verify(password, password_hash) # type: ignore[union-attr] # ty: ignore[unresolved-attribute]

def needs_rehash(self, password_hash: str) -> bool:
"""Check if a password hash needs to be rehashed.
Expand Down Expand Up @@ -224,7 +224,7 @@ def needs_rehash(self, password_hash: str) -> bool:
if not PasswordHasher._available or PasswordHasher._context is None:
msg = "No password hashing backend available. Install 'litestar-admin[auth]' or 'passlib[argon2]'."
raise RuntimeError(msg)
return PasswordHasher._context.needs_update(password_hash) # type: ignore[union-attr]
return PasswordHasher._context.needs_update(password_hash) # type: ignore[union-attr] # ty: ignore[unresolved-attribute]

@classmethod
def is_available(cls) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion src/litestar_admin/contrib/providers/in_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async def delete(self, item_id: str) -> bool:
return True

@staticmethod
def _apply_filter_operator(
def _apply_filter_operator( # noqa: PLR0912, C901
items: list[dict[str, Any]],
field: str,
operator: str,
Expand Down
6 changes: 3 additions & 3 deletions src/litestar_admin/controllers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import TYPE_CHECKING, ClassVar
from typing import TYPE_CHECKING

from litestar import Controller, get, post
from litestar.exceptions import NotAuthorizedException, PermissionDeniedException
Expand Down Expand Up @@ -139,7 +139,7 @@ class AuthController(Controller):
"""

path = "/api/auth"
tags: ClassVar[list[str]] = ["Authentication"]
tags: list[str] = ["Authentication"] # noqa: RUF012

@post(
"/login",
Expand Down Expand Up @@ -333,7 +333,7 @@ async def change_password(
if not hasattr(admin_config.auth_backend, "change_password"):
raise PermissionDeniedException(detail="Password change is not supported by this authentication backend")

success = await admin_config.auth_backend.change_password(
success = await admin_config.auth_backend.change_password( # ty: ignore[call-non-callable]
request,
data.current_password,
data.new_password,
Expand Down
6 changes: 3 additions & 3 deletions src/litestar_admin/controllers/bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, ClassVar
from typing import TYPE_CHECKING, Any

from litestar import Controller, post
from litestar.exceptions import HTTPException, NotFoundException
Expand Down Expand Up @@ -127,7 +127,7 @@ async def bulk_activate(
"""

path = "/api/models"
tags: ClassVar[list[str]] = ["Bulk Actions"]
tags: list[str] = ["Bulk Actions"] # noqa: RUF012

@post(
"/{model_name:str}/bulk/delete",
Expand Down Expand Up @@ -324,4 +324,4 @@ def _get_view_or_raise(
status_code=HTTP_404_NOT_FOUND,
detail=f"Model '{model_name}' not found",
)
return registry.get_view_by_name(model_name)
return registry.get_view_by_name(model_name) # ty: ignore[invalid-return-type]
7 changes: 3 additions & 4 deletions src/litestar_admin/controllers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

from dataclasses import dataclass, field
from typing import ClassVar

from litestar import Controller, get
from litestar.status_codes import HTTP_200_OK
Expand Down Expand Up @@ -84,7 +83,7 @@ class ConfigController(Controller):
"""

path = "/api/config"
tags: ClassVar[list[str]] = ["Configuration"]
tags: list[str] = ["Configuration"] # noqa: RUF012

@get(
"/",
Expand Down Expand Up @@ -130,11 +129,11 @@ async def get_config(
)
)
# Also check if auth_backend has OAuth providers
elif admin_config.auth_backend is not None:
elif admin_config.auth_backend is not None: # noqa: SIM102
if hasattr(admin_config.auth_backend, "available_providers"):
provider_names = admin_config.auth_backend.available_providers
base_url = admin_config.base_url
for name in provider_names:
for name in provider_names: # ty: ignore[not-iterable]
# Create display name (capitalize, handle special cases)
display_name = {
"github": "GitHub",
Expand Down
14 changes: 7 additions & 7 deletions src/litestar_admin/controllers/custom_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, ClassVar, Literal, cast
from typing import TYPE_CHECKING, Any, Literal, cast

from litestar import Controller, Request, delete, get, post, put
from litestar.exceptions import NotFoundException, PermissionDeniedException
Expand Down Expand Up @@ -368,7 +368,7 @@ class CustomViewsController(Controller):
"""

path = "/api/views/custom"
tags: ClassVar[list[str]] = ["Custom Views"]
tags: list[str] = ["Custom Views"] # noqa: RUF012

@get(
"/",
Expand Down Expand Up @@ -458,7 +458,7 @@ async def list_items(
effective_limit = limit or page_size or 25
effective_limit = min(max(1, effective_limit), 100)

if offset is not None:
if offset is not None: # noqa: SIM108
effective_page = (offset // effective_limit) + 1
else:
effective_page = page or 1
Expand Down Expand Up @@ -767,7 +767,7 @@ class ActionsController(Controller):
"""

path = "/api/views/actions"
tags: ClassVar[list[str]] = ["Actions"]
tags: list[str] = ["Actions"] # noqa: RUF012

@get(
"/",
Expand Down Expand Up @@ -925,7 +925,7 @@ class PagesController(Controller):
"""

path = "/api/views/pages"
tags: ClassVar[list[str]] = ["Pages"]
tags: list[str] = ["Pages"] # noqa: RUF012

@get(
"/",
Expand Down Expand Up @@ -1099,7 +1099,7 @@ class EmbedsController(Controller):
"""

path = "/api/views/embeds"
tags: ClassVar[list[str]] = ["Embeds"]
tags: list[str] = ["Embeds"] # noqa: RUF012

@get(
"/",
Expand Down Expand Up @@ -1247,7 +1247,7 @@ class LinksController(Controller):
"""

path = "/api/views/links"
tags: ClassVar[list[str]] = ["Links"]
tags: list[str] = ["Links"] # noqa: RUF012

@get(
"/",
Expand Down
6 changes: 3 additions & 3 deletions src/litestar_admin/controllers/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from dataclasses import dataclass, field
from datetime import datetime
from typing import Any, ClassVar
from typing import Any

from litestar import Controller, get
from litestar.status_codes import HTTP_200_OK
Expand Down Expand Up @@ -115,7 +115,7 @@ class DashboardController(Controller):
"""

path = "/api/dashboard"
tags: ClassVar[list[str]] = ["Dashboard"]
tags: list[str] = ["Dashboard"] # noqa: RUF012

@get(
"/stats",
Expand Down Expand Up @@ -151,7 +151,7 @@ async def get_stats(

# Attempt to get record count if session is available
if db_session is not None:
count = await self._get_model_count(db_session, view_class.model)
count = await self._get_model_count(db_session, view_class.model) # ty: ignore[invalid-argument-type]

total_records += count

Expand Down
4 changes: 2 additions & 2 deletions src/litestar_admin/controllers/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
from dataclasses import dataclass
from io import BytesIO, StringIO
from typing import TYPE_CHECKING, Any, ClassVar, Literal
from typing import TYPE_CHECKING, Any, Literal

from litestar import Controller, get, post
from litestar.exceptions import NotFoundException, ValidationException
Expand Down Expand Up @@ -95,7 +95,7 @@ class ExportController(Controller):
"""

path = "/api/models"
tags: ClassVar[list[str]] = ["Export"]
tags: list[str] = ["Export"] # noqa: RUF012

@get(
"/{model_name:str}/export",
Expand Down
Loading
Loading