diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 00000000..e956557a --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,175 @@ +# Gitea Actions CI/CD Configuration +# ================================== +# Equivalent of the GitLab CI pipeline, using GitHub Actions-compatible syntax. +# Requires Gitea 1.19+ with Actions enabled. + +name: CI + +on: + push: + branches: [master] + pull_request: + branches: [master] + +env: + PYTHON_VERSION: "3.11" + +jobs: + # --------------------------------------------------------------------------- + # Lint + # --------------------------------------------------------------------------- + ruff: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install uv + run: pip install uv + + - name: Install dependencies + run: uv sync --frozen + + - name: Run ruff + run: .venv/bin/ruff check . + + # --------------------------------------------------------------------------- + # Tests + # --------------------------------------------------------------------------- + pytest: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:15 + env: + POSTGRES_DB: wizamart_test + POSTGRES_USER: test_user + POSTGRES_PASSWORD: test_password + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U test_user -d wizamart_test" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + env: + TEST_DATABASE_URL: "postgresql://test_user:test_password@localhost:5432/wizamart_test" + DATABASE_URL: "postgresql://test_user:test_password@localhost:5432/wizamart_test" + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Cache pip & venv + uses: actions/cache@v4 + with: + path: | + ~/.cache/pip + .venv + key: ${{ runner.os }}-pip-${{ hashFiles('uv.lock', 'pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install uv + run: pip install uv + + - name: Install dependencies + run: uv sync --frozen + + - name: Run tests + run: .venv/bin/python -m pytest tests/ -v --tb=short + + architecture: + runs-on: ubuntu-latest + env: + DATABASE_URL: "postgresql://dummy:dummy@localhost:5432/dummy" + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install uv + run: pip install uv + + - name: Install dependencies + run: uv sync --frozen + + - name: Validate architecture + run: .venv/bin/python scripts/validate/validate_architecture.py + + # --------------------------------------------------------------------------- + # Security (non-blocking) + # --------------------------------------------------------------------------- + dependency-scanning: + runs-on: ubuntu-latest + continue-on-error: true + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install pip-audit + run: pip install pip-audit + + - name: Run pip-audit + run: pip-audit --requirement requirements.txt || true + + audit: + runs-on: ubuntu-latest + continue-on-error: true + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install uv + run: pip install uv + + - name: Install dependencies + run: uv sync --frozen + + - name: Run audit + run: .venv/bin/python scripts/validate/validate_audit.py + + # --------------------------------------------------------------------------- + # Build (docs - only on push to master) + # --------------------------------------------------------------------------- + docs: + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + needs: [ruff, pytest, architecture] + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install uv + run: pip install uv + + - name: Install dependencies + run: uv sync --frozen + + - name: Build docs + run: .venv/bin/mkdocs build + + - name: Upload docs artifact + uses: actions/upload-artifact@v4 + with: + name: docs-site + path: site/ diff --git a/Makefile b/Makefile index 1a86ef57..2c420bcd 100644 --- a/Makefile +++ b/Makefile @@ -399,26 +399,22 @@ tailwind-install: @mv tailwindcss-linux-x64 $(TAILWIND_CLI) @echo "Tailwind CLI installed: $$($(TAILWIND_CLI) --help | head -1)" +# All frontends that have a Tailwind build (static//css/tailwind.css) +TAILWIND_FRONTENDS := admin store storefront platform merchant + tailwind-dev: @echo "Building Tailwind CSS (development)..." - $(TAILWIND_CLI) -i static/admin/css/tailwind.css -o static/admin/css/tailwind.output.css - $(TAILWIND_CLI) -i static/store/css/tailwind.css -o static/store/css/tailwind.output.css - $(TAILWIND_CLI) -i static/shop/css/tailwind.css -o static/shop/css/tailwind.output.css - $(TAILWIND_CLI) -i static/platform/css/tailwind.css -o static/platform/css/tailwind.output.css - @echo "Tailwind CSS built (admin + store + shop + platform)" + @$(foreach fe,$(TAILWIND_FRONTENDS),$(TAILWIND_CLI) -i static/$(fe)/css/tailwind.css -o static/$(fe)/css/tailwind.output.css &&) true + @echo "Tailwind CSS built ($(TAILWIND_FRONTENDS))" tailwind-build: @echo "Building Tailwind CSS (production - minified)..." - $(TAILWIND_CLI) -i static/admin/css/tailwind.css -o static/admin/css/tailwind.output.css --minify - $(TAILWIND_CLI) -i static/store/css/tailwind.css -o static/store/css/tailwind.output.css --minify - $(TAILWIND_CLI) -i static/shop/css/tailwind.css -o static/shop/css/tailwind.output.css --minify - $(TAILWIND_CLI) -i static/platform/css/tailwind.css -o static/platform/css/tailwind.output.css --minify + @$(foreach fe,$(TAILWIND_FRONTENDS),$(TAILWIND_CLI) -i static/$(fe)/css/tailwind.css -o static/$(fe)/css/tailwind.output.css --minify &&) true @echo "Tailwind CSS built and minified for production" tailwind-watch: - @echo "Watching Tailwind CSS for changes..." - @echo "Note: This watches admin CSS only. Run in separate terminal." - $(TAILWIND_CLI) -i static/admin/css/tailwind.css -o static/admin/css/tailwind.output.css --watch + @echo "Watching Tailwind CSS for changes ($(fe))..." + $(TAILWIND_CLI) -i static/$(fe)/css/tailwind.css -o static/$(fe)/css/tailwind.output.css --watch # ============================================================================= # CELERY / TASK QUEUE @@ -593,7 +589,7 @@ help: @echo " tailwind-install - Install Tailwind standalone CLI" @echo " tailwind-dev - Build Tailwind CSS (development)" @echo " tailwind-build - Build Tailwind CSS (production, minified)" - @echo " tailwind-watch - Watch and rebuild on changes" + @echo " tailwind-watch fe=X - Watch and rebuild on changes (specify frontend)" @echo "" @echo "=== CELERY / TASK QUEUE ===" @echo " celery-worker - Start Celery worker" diff --git a/app/core/frontend_detector.py b/app/core/frontend_detector.py index 4e26d15c..00d12efb 100644 --- a/app/core/frontend_detector.py +++ b/app/core/frontend_detector.py @@ -50,6 +50,7 @@ class FrontendDetector: "/api/v1/shop", # Legacy support "/stores/", # Path-based store access ) + MERCHANT_PATH_PREFIXES = ("/merchants", "/api/v1/merchants") PLATFORM_PATH_PREFIXES = ("/api/v1/platform",) @classmethod @@ -94,6 +95,10 @@ class FrontendDetector: logger.debug("[FRONTEND_DETECTOR] Detected ADMIN from path") return FrontendType.ADMIN + if cls._matches_any(path, cls.MERCHANT_PATH_PREFIXES): + logger.debug("[FRONTEND_DETECTOR] Detected MERCHANT from path") + return FrontendType.MERCHANT + # Check storefront BEFORE store since /api/v1/storefront starts with /api/v1/store if cls._matches_any(path, cls.STOREFRONT_PATH_PREFIXES): logger.debug("[FRONTEND_DETECTOR] Detected STOREFRONT from path") diff --git a/app/exceptions/handler.py b/app/exceptions/handler.py index 636ee5ee..0cc3b86d 100644 --- a/app/exceptions/handler.py +++ b/app/exceptions/handler.py @@ -393,6 +393,9 @@ def _redirect_to_login(request: Request) -> RedirectResponse: if frontend_type == FrontendType.ADMIN: logger.debug("Redirecting to /admin/login") return RedirectResponse(url="/admin/login", status_code=302) + if frontend_type == FrontendType.MERCHANT: + logger.debug("Redirecting to /merchants/login") + return RedirectResponse(url="/merchants/login", status_code=302) if frontend_type == FrontendType.STORE: # Extract store code from the request path # Path format: /store/{store_code}/... diff --git a/app/modules/billing/routes/pages/merchant.py b/app/modules/billing/routes/pages/merchant.py index 3824a3fb..0b9174d6 100644 --- a/app/modules/billing/routes/pages/merchant.py +++ b/app/modules/billing/routes/pages/merchant.py @@ -3,14 +3,14 @@ Merchant Billing Page Routes (HTML rendering). Page routes for the merchant billing portal: -- Dashboard (overview of stores, subscriptions) - Subscriptions list - Subscription detail per platform - Billing history / invoices -- Login page Authentication: merchant_token cookie or Authorization header. -Login page uses optional auth to check if already logged in. + +Login and dashboard routes have moved to core module +(app/modules/core/routes/pages/merchant.py) to match the admin pattern. Auto-discovered by the route system (merchant.py in routes/pages/ triggers registration under /merchants/billing/*). @@ -20,10 +20,7 @@ from fastapi import APIRouter, Depends, Path, Request from fastapi.responses import HTMLResponse, RedirectResponse from sqlalchemy.orm import Session -from app.api.deps import ( - get_current_merchant_from_cookie_or_header, - get_current_merchant_optional, -) +from app.api.deps import get_current_merchant_from_cookie_or_header from app.core.database import get_db from app.modules.core.utils.page_context import get_context_for_frontend from app.modules.enums import FrontendType @@ -53,15 +50,6 @@ def _get_merchant_context( Uses the module-driven context builder with FrontendType.MERCHANT, and adds the authenticated user to the context. - - Args: - request: FastAPI request - db: Database session - current_user: Authenticated merchant user context - **extra_context: Additional template variables - - Returns: - Dict of context variables for template rendering """ return get_context_for_frontend( FrontendType.MERCHANT, @@ -73,26 +61,14 @@ def _get_merchant_context( # ============================================================================ -# DASHBOARD +# BILLING ROOT # ============================================================================ -@router.get("/", response_class=HTMLResponse, include_in_schema=False) -async def merchant_dashboard_page( - request: Request, - current_user: UserContext = Depends(get_current_merchant_from_cookie_or_header), - db: Session = Depends(get_db), -): - """ - Render merchant dashboard page. - - Shows an overview of the merchant's stores and subscriptions. - """ - context = _get_merchant_context(request, db, current_user) - return templates.TemplateResponse( - "billing/merchant/dashboard.html", - context, - ) +@router.get("/", response_class=RedirectResponse, include_in_schema=False) +async def merchant_billing_root(): + """Redirect /merchants/billing/ to subscriptions page.""" + return RedirectResponse(url="/merchants/billing/subscriptions", status_code=302) # ============================================================================ @@ -164,35 +140,3 @@ async def merchant_billing_history_page( "billing/merchant/billing-history.html", context, ) - - -# ============================================================================ -# LOGIN -# ============================================================================ - - -@router.get("/login", response_class=HTMLResponse, include_in_schema=False) -async def merchant_login_page( - request: Request, - current_user: UserContext | None = Depends(get_current_merchant_optional), - db: Session = Depends(get_db), -): - """ - Render merchant login page. - - If the user is already authenticated as a merchant owner, - redirects to the merchant dashboard. - """ - # Redirect to dashboard if already logged in - if current_user is not None: - return RedirectResponse(url="/merchants/billing/", status_code=302) - - context = get_context_for_frontend( - FrontendType.MERCHANT, - request, - db, - ) - return templates.TemplateResponse( - "billing/merchant/login.html", - context, - ) diff --git a/app/modules/billing/templates/billing/merchant/billing-history.html b/app/modules/billing/templates/billing/merchant/billing-history.html index 2a736b9e..b7238860 100644 --- a/app/modules/billing/templates/billing/merchant/billing-history.html +++ b/app/modules/billing/templates/billing/merchant/billing-history.html @@ -7,22 +7,22 @@
-
-

Billing History

-

View your invoices and payment history.

+
+

Billing History

+

View your invoices and payment history.

-
-

+
+

-
+
- + @@ -30,11 +30,11 @@ - +
Date Invoice # AmountActions