11import typing as t
22from functools import partial
33
4- from ellar .common import APIException , GuardCanActivate , IExecutionContext
4+ from ellar .common import APIException , EllarInterceptor , IExecutionContext
55from ellar .di import injectable
66from starlette import status
77
1010
1111
1212@injectable
13- class AuthorizationGuard ( GuardCanActivate ):
13+ class AuthorizationInterceptor ( EllarInterceptor ):
1414 status_code = status .HTTP_403_FORBIDDEN
1515 exception_class = APIException
1616
@@ -31,14 +31,16 @@ def _get_policy_instance(
3131 return context .get_service_provider ().get (policy )
3232 return policy
3333
34- async def can_activate (self , context : IExecutionContext ) -> bool :
34+ async def intercept (
35+ self , context : IExecutionContext , next_interceptor : t .Callable [..., t .Coroutine ]
36+ ) -> t .Any :
3537 if not context .user .is_authenticated :
3638 raise self .exception_class (status_code = 401 )
3739
3840 policies = self .get_route_handler_policy (context )
3941
4042 if not policies :
41- return True
43+ return await next_interceptor ()
4244
4345 partial_get_policy_instance = partial (self ._get_policy_instance , context )
4446
@@ -48,7 +50,7 @@ async def can_activate(self, context: IExecutionContext) -> bool:
4850 if not result :
4951 self .raise_exception ()
5052
51- return True
53+ return await next_interceptor ()
5254
5355 def raise_exception (self ) -> None :
5456 raise self .exception_class (status_code = self .status_code )
0 commit comments