Enhance public access and error handling in site-related views and loaders

- Updated `DebugScopedRateThrottle` to allow public access for blueprint list requests with site filters.
- Modified `SiteViewSet` and `SiteBlueprintViewSet` to permit public read access for list requests.
- Enhanced `loadSiteDefinition` to resolve site slugs to IDs, improving the loading process for site definitions.
- Improved error handling in `SiteDefinitionView` and `loadSiteDefinition` for better user feedback.
- Adjusted CSS styles for better layout and alignment in shared components.
This commit is contained in:
IGNY8 VPS (Salman)
2025-11-18 22:40:00 +00:00
parent 8ab15d1d79
commit 6c6133a683
14 changed files with 361 additions and 76 deletions

View File

@@ -39,6 +39,47 @@ class SiteBlueprintViewSet(SiteSectorModelViewSet):
permission_classes = [IsAuthenticatedAndActive, IsEditorOrAbove]
throttle_scope = 'site_builder'
throttle_classes = [DebugScopedRateThrottle]
def get_permissions(self):
"""
Allow public read access for list requests with site filter (used by Sites Renderer fallback).
This allows the Sites Renderer to load blueprint data for deployed sites without authentication.
"""
# Allow public access for list requests with site filter (used by Sites Renderer)
if self.action == 'list' and self.request.query_params.get('site'):
from rest_framework.permissions import AllowAny
return [AllowAny()]
# Otherwise use default permissions
return super().get_permissions()
def get_throttles(self):
"""
Bypass throttling for public list requests with site filter (used by Sites Renderer).
"""
# Bypass throttling for public requests (no auth) with site filter
if self.action == 'list' and self.request.query_params.get('site'):
if not self.request.user or not self.request.user.is_authenticated:
return [] # No throttling for public blueprint access
return super().get_throttles()
def get_queryset(self):
"""
Override to allow public access when filtering by site_id.
"""
# If this is a public request (no auth) with site filter, bypass base class filtering
# and return deployed blueprints for that site
if not self.request.user or not self.request.user.is_authenticated:
site_id = self.request.query_params.get('site')
if site_id:
# Return queryset directly from model (bypassing base class account/site filtering)
from igny8_core.business.site_building.models import SiteBlueprint
return SiteBlueprint.objects.filter(
site_id=site_id,
status='deployed'
).prefetch_related('pages').order_by('-version')
# For authenticated users, use base class filtering
return super().get_queryset()
def perform_create(self, serializer):
from igny8_core.auth.models import Site, Sector