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:
@@ -478,16 +478,26 @@ class SiteViewSet(AccountModelViewSet):
|
||||
|
||||
def get_permissions(self):
|
||||
"""Allow normal users (viewer) to create sites, but require editor+ for other operations."""
|
||||
# Allow public read access for list requests with slug filter (used by Sites Renderer)
|
||||
if self.action == 'list' and self.request.query_params.get('slug'):
|
||||
from rest_framework.permissions import AllowAny
|
||||
return [AllowAny()]
|
||||
if self.action == 'create':
|
||||
return [permissions.IsAuthenticated()]
|
||||
return [IsEditorOrAbove()]
|
||||
|
||||
def get_queryset(self):
|
||||
"""Return sites accessible to the current user."""
|
||||
user = self.request.user
|
||||
if not user or not user.is_authenticated:
|
||||
# If this is a public request (no auth) with slug filter, return site by slug
|
||||
if not self.request.user or not self.request.user.is_authenticated:
|
||||
slug = self.request.query_params.get('slug')
|
||||
if slug:
|
||||
# Return queryset directly from model (bypassing base class account filtering)
|
||||
return Site.objects.filter(slug=slug, is_active=True)
|
||||
return Site.objects.none()
|
||||
|
||||
user = self.request.user
|
||||
|
||||
# ADMIN/DEV OVERRIDE: Both admins and developers can see all sites
|
||||
if user.is_admin_or_developer():
|
||||
return Site.objects.all().distinct()
|
||||
|
||||
Reference in New Issue
Block a user