refactor: remove backward compatibility code for pre-launch baseline
Clean up accumulated backward-compat shims, deprecated wrappers, unused aliases, and legacy code across the codebase. Since the platform is not live yet, this establishes a clean baseline. Changes: - Delete deprecated middleware/context.py (RequestContext, get_request_context) - Remove unused factory get_store_email_settings_service() - Remove deprecated pagination_full macro, /admin/platform-homepage route - Remove ConversationResponse, InvoiceSettings* unprefixed aliases - Simplify celery_config.py (remove empty LEGACY_TASK_MODULES) - Standardize billing exceptions: *Error aliases → *Exception names - Consolidate duplicate TierNotFoundError/FeatureNotFoundError classes - Remove deprecated is_admin_request() from Store/PlatformContextManager - Remove is_platform_default field, MediaUploadResponse legacy flat fields - Remove MediaItemResponse.url alias, update JS to use file_url - Update all affected tests and documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -172,41 +172,6 @@ if FrontendDetector.is_storefront(host, path, has_store_context=True):
|
||||
| Custom domain | mybakery.lu | /products | STOREFRONT |
|
||||
| Platform root | oms.lu | /pricing | PLATFORM |
|
||||
|
||||
## Migration from RequestContext
|
||||
|
||||
The previous `RequestContext` enum is deprecated. Here's the mapping:
|
||||
|
||||
| Old (RequestContext) | New (FrontendType) |
|
||||
|---------------------|-------------------|
|
||||
| `API` | Use `FrontendDetector.is_api_request()` + FrontendType |
|
||||
| `ADMIN` | `FrontendType.ADMIN` |
|
||||
| `STORE_DASHBOARD` | `FrontendType.STORE` |
|
||||
| `SHOP` | `FrontendType.STOREFRONT` |
|
||||
| `FALLBACK` | `FrontendType.PLATFORM` |
|
||||
|
||||
### Code Migration
|
||||
|
||||
**Before (deprecated):**
|
||||
```python
|
||||
from middleware.context import RequestContext, get_request_context
|
||||
|
||||
context = get_request_context(request)
|
||||
if context == RequestContext.SHOP:
|
||||
# Storefront logic
|
||||
pass
|
||||
```
|
||||
|
||||
**After:**
|
||||
```python
|
||||
from middleware.frontend_type import get_frontend_type
|
||||
from app.modules.enums import FrontendType
|
||||
|
||||
frontend_type = get_frontend_type(request)
|
||||
if frontend_type == FrontendType.STOREFRONT:
|
||||
# Storefront logic
|
||||
pass
|
||||
```
|
||||
|
||||
## Request State
|
||||
|
||||
After `FrontendTypeMiddleware` runs, the following is available:
|
||||
@@ -255,10 +220,9 @@ pytest tests/unit/core/test_frontend_detector.py tests/unit/middleware/test_fron
|
||||
|
||||
### DON'T
|
||||
|
||||
1. **Don't use `RequestContext`** - it's deprecated
|
||||
2. **Don't duplicate path detection logic** - use FrontendDetector
|
||||
3. **Don't hardcode path patterns** in middleware - they're centralized in FrontendDetector
|
||||
4. **Don't check `request.state.context_type`** - use `request.state.frontend_type`
|
||||
1. **Don't duplicate path detection logic** - use FrontendDetector
|
||||
2. **Don't hardcode path patterns** in middleware - they're centralized in FrontendDetector
|
||||
3. **Don't check `request.state.context_type`** - use `request.state.frontend_type`
|
||||
|
||||
## Architecture Rules
|
||||
|
||||
|
||||
@@ -186,19 +186,19 @@ All middleware components follow a consistent naming pattern for maintainability
|
||||
```
|
||||
✅ Good:
|
||||
middleware/logging.py
|
||||
middleware/context.py
|
||||
middleware/store_context.py
|
||||
middleware/auth.py
|
||||
|
||||
❌ Avoid:
|
||||
middleware/logging_middleware.py
|
||||
middleware/context_middleware.py
|
||||
middleware/store_context_middleware.py
|
||||
middleware/auth_middleware.py
|
||||
```
|
||||
|
||||
**Rationale**:
|
||||
- Keeps names concise and consistent
|
||||
- Follows Django, Flask, and FastAPI conventions
|
||||
- Makes imports cleaner: `from middleware.logging import LoggingMiddleware`
|
||||
- Makes imports cleaner: `from middleware.store_context import StoreContextMiddleware`
|
||||
- Reduces redundancy (the `middleware/` directory already indicates the purpose)
|
||||
|
||||
#### Test File Naming: Mirror the Source File
|
||||
@@ -206,10 +206,9 @@ middleware/auth_middleware.py
|
||||
Test files directly mirror the middleware filename with a `test_` prefix:
|
||||
|
||||
```
|
||||
middleware/logging.py → tests/unit/middleware/test_logging.py
|
||||
middleware/context.py → tests/unit/middleware/test_context.py
|
||||
middleware/auth.py → tests/unit/middleware/test_auth.py
|
||||
middleware/logging.py → tests/unit/middleware/test_logging.py
|
||||
middleware/store_context.py → tests/unit/middleware/test_store_context.py
|
||||
middleware/auth.py → tests/unit/middleware/test_auth.py
|
||||
```
|
||||
|
||||
#### One Component Per File
|
||||
@@ -229,19 +228,15 @@ class FrontendTypeMiddleware: # ASGI wrapper for frontend detection
|
||||
class AuthManager: # Authentication logic
|
||||
```
|
||||
|
||||
> **Note**: The old `middleware/context.py` with `ContextMiddleware` and `RequestContext` is deprecated.
|
||||
> Use `FrontendTypeMiddleware` and `FrontendType` enum instead.
|
||||
> See [Frontend Detection Architecture](frontend-detection.md) for migration guide.
|
||||
|
||||
#### One Test File Per Component
|
||||
|
||||
Follow the Single Responsibility Principle - each test file tests exactly one component:
|
||||
|
||||
```
|
||||
✅ Good:
|
||||
tests/unit/middleware/test_logging.py # Tests only LoggingMiddleware
|
||||
tests/unit/middleware/test_context.py # Tests only ContextManager/Middleware
|
||||
tests/unit/middleware/test_decorators.py # Tests only rate_limit decorator
|
||||
tests/unit/middleware/test_logging.py # Tests only LoggingMiddleware
|
||||
tests/unit/middleware/test_store_context.py # Tests only StoreContextManager/Middleware
|
||||
tests/unit/middleware/test_decorators.py # Tests only rate_limit decorator
|
||||
|
||||
❌ Avoid:
|
||||
tests/unit/middleware/test_all_middleware.py # Tests multiple components
|
||||
@@ -261,12 +256,12 @@ When importing middleware components, use explicit imports:
|
||||
```python
|
||||
# ✅ Preferred - Explicit and clear
|
||||
from middleware.logging import LoggingMiddleware
|
||||
from middleware.context import ContextManager, RequestContext
|
||||
from middleware.store_context import StoreContextManager
|
||||
from middleware.auth import AuthManager
|
||||
|
||||
# ❌ Avoid - Less clear
|
||||
from middleware import logging_middleware
|
||||
from middleware import context_middleware
|
||||
from middleware import store_context_middleware
|
||||
```
|
||||
|
||||
**See**: [Complete Naming Conventions Guide](../development/naming-conventions.md) for project-wide standards.
|
||||
|
||||
Reference in New Issue
Block a user