fix(loyalty): pass merchant name server-side to admin on-behalf headers

Load merchant name in page route handlers and pass to template context.
Headers now render as "Cards: Fashion Group S.A." using server-side
Jinja2 variables instead of relying on JS program.merchant_name which
was not in the ProgramResponse schema.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 14:15:05 +01:00
parent a423bcf03e
commit 1107de989b
4 changed files with 18 additions and 8 deletions

View File

@@ -15,9 +15,15 @@ from sqlalchemy.orm import Session
from app.api.deps import get_db, require_menu_access
from app.modules.core.utils.page_context import get_admin_context
from app.modules.enums import FrontendType
from app.modules.tenancy.models import User
from app.modules.tenancy.models import Merchant, User
from app.templates_config import templates
def _get_merchant_name(db: Session, merchant_id: int) -> str:
"""Look up merchant name for page header context."""
merchant = db.query(Merchant).filter(Merchant.id == merchant_id).first()
return merchant.name if merchant else ""
router = APIRouter()
# Route configuration for module route discovery
@@ -139,9 +145,10 @@ async def admin_loyalty_merchant_cards(
Render merchant loyalty cards list page.
Shows all loyalty cards for a specific merchant.
"""
merchant_name = _get_merchant_name(db, merchant_id)
return templates.TemplateResponse(
"loyalty/admin/merchant-cards.html",
get_admin_context(request, db, current_user, merchant_id=merchant_id),
get_admin_context(request, db, current_user, merchant_id=merchant_id, merchant_name=merchant_name),
)
@@ -161,9 +168,10 @@ async def admin_loyalty_merchant_card_detail(
Render merchant loyalty card detail page.
Shows detailed info for a specific loyalty card.
"""
merchant_name = _get_merchant_name(db, merchant_id)
return templates.TemplateResponse(
"loyalty/admin/merchant-card-detail.html",
get_admin_context(request, db, current_user, merchant_id=merchant_id, card_id=card_id),
get_admin_context(request, db, current_user, merchant_id=merchant_id, card_id=card_id, merchant_name=merchant_name),
)
@@ -182,9 +190,10 @@ async def admin_loyalty_merchant_transactions(
Render merchant loyalty transactions list page.
Shows all loyalty transactions for a specific merchant.
"""
merchant_name = _get_merchant_name(db, merchant_id)
return templates.TemplateResponse(
"loyalty/admin/merchant-transactions.html",
get_admin_context(request, db, current_user, merchant_id=merchant_id),
get_admin_context(request, db, current_user, merchant_id=merchant_id, merchant_name=merchant_name),
)
@@ -203,9 +212,10 @@ async def admin_loyalty_merchant_pins(
Render merchant staff PINs page (read-only).
Shows all staff PINs for a specific merchant.
"""
merchant_name = _get_merchant_name(db, merchant_id)
return templates.TemplateResponse(
"loyalty/admin/merchant-pins.html",
get_admin_context(request, db, current_user, merchant_id=merchant_id),
get_admin_context(request, db, current_user, merchant_id=merchant_id, merchant_name=merchant_name),
)