Coverage for netrun_errors / authorization.py: 100%
9 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-15 18:37 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-15 18:37 +0000
1"""
2Authorization-related exceptions for Netrun Systems.
4All authorization exceptions return HTTP 403 Forbidden status codes
5for authenticated users lacking sufficient permissions.
6"""
8from typing import Any, Dict, Optional
10from fastapi import status
12from .base import NetrunException
15class InsufficientPermissionsError(NetrunException):
16 """
17 Raised when authenticated user lacks required permissions.
19 Status Code: 403 Forbidden
20 Error Code: AUTHZ_INSUFFICIENT_PERMISSIONS
21 """
23 def __init__(
24 self,
25 message: str = "You do not have permission to perform this action",
26 details: Optional[Dict[str, Any]] = None,
27 correlation_id: Optional[str] = None,
28 ):
29 super().__init__(
30 status_code=status.HTTP_403_FORBIDDEN,
31 error_code="AUTHZ_INSUFFICIENT_PERMISSIONS",
32 message=message,
33 details=details,
34 correlation_id=correlation_id,
35 )
38class TenantAccessDeniedError(NetrunException):
39 """
40 Raised when user attempts to access resources outside their tenant scope.
42 Status Code: 403 Forbidden
43 Error Code: AUTHZ_TENANT_ACCESS_DENIED
44 """
46 def __init__(
47 self,
48 message: str = "Access denied: resource belongs to a different tenant",
49 details: Optional[Dict[str, Any]] = None,
50 correlation_id: Optional[str] = None,
51 ):
52 super().__init__(
53 status_code=status.HTTP_403_FORBIDDEN,
54 error_code="AUTHZ_TENANT_ACCESS_DENIED",
55 message=message,
56 details=details,
57 correlation_id=correlation_id,
58 )