Skip to content

Commit f2af822

Browse files
authored
Merge pull request #92 from eadwinCode/refactor_auth_execution
Moved auth exception to happen under routecontext
2 parents 25204c1 + c39a60e commit f2af822

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

ninja_extra/operation.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,15 @@ def _prep_run(
178178
ROUTE_CONTEXT_VAR.set(None)
179179

180180
def run(self, request: HttpRequest, **kw: Any) -> HttpResponseBase:
181-
error = self._run_checks(request)
182-
if error:
183-
return error
184181
try:
185182
temporal_response = self.api.create_temporal_response(request)
186183
with self._prep_run(
187184
request, temporal_response=temporal_response, **kw
188185
) as ctx:
186+
error = self._run_checks(request)
187+
if error:
188+
return error
189+
189190
values = self._get_values(request, kw, temporal_response)
190191
ctx.kwargs.update(values)
191192
result = self.view_func(request, **values)
@@ -278,14 +279,15 @@ async def _prep_run( # type:ignore
278279
ROUTE_CONTEXT_VAR.set(None)
279280

280281
async def run(self, request: HttpRequest, **kw: Any) -> HttpResponseBase: # type: ignore
281-
error = await self._run_checks(request)
282-
if error:
283-
return error
284282
try:
285283
temporal_response = self.api.create_temporal_response(request)
286284
async with self._prep_run(
287285
request, temporal_response=temporal_response, **kw
288286
) as ctx:
287+
error = await self._run_checks(request)
288+
if error:
289+
return error
290+
289291
values = await self._get_values(request, kw, temporal_response) # type: ignore
290292
ctx.kwargs.update(values)
291293
result = await self.view_func(request, **values)

ninja_extra/permissions/base.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,34 @@
1717

1818

1919
class OperationHolderMixin:
20-
def __and__(
21-
self, other: Union[Type["BasePermission"], "BasePermission"]
20+
def __and__( # type:ignore[misc]
21+
self: Union[Type["BasePermission"], "BasePermission"],
22+
other: Union[Type["BasePermission"], "BasePermission"],
2223
) -> "OperandHolder[AND]":
23-
return OperandHolder(AND, self, other) # type: ignore
24+
return OperandHolder(AND, self, other)
2425

25-
def __or__(
26-
self, other: Union[Type["BasePermission"], "BasePermission"]
26+
def __or__( # type:ignore[misc]
27+
self: Union[Type["BasePermission"], "BasePermission"],
28+
other: Union[Type["BasePermission"], "BasePermission"],
2729
) -> "OperandHolder[OR]":
28-
return OperandHolder(OR, self, other) # type: ignore
30+
return OperandHolder(OR, self, other)
2931

30-
def __rand__(
31-
self, other: Union[Type["BasePermission"], "BasePermission"]
32+
def __rand__( # type:ignore[misc]
33+
self: Union[Type["BasePermission"], "BasePermission"],
34+
other: Union[Type["BasePermission"], "BasePermission"],
3235
) -> "OperandHolder[AND]": # pragma: no cover
33-
return OperandHolder(AND, other, self) # type: ignore
36+
return OperandHolder(AND, other, self)
3437

35-
def __ror__(
36-
self, other: Union[Type["BasePermission"], "BasePermission"]
38+
def __ror__( # type:ignore[misc]
39+
self: Union[Type["BasePermission"], "BasePermission"],
40+
other: Union[Type["BasePermission"], "BasePermission"],
3741
) -> "OperandHolder[OR]": # pragma: no cover
38-
return OperandHolder(OR, other, self) # type: ignore
42+
return OperandHolder(OR, other, self)
3943

40-
def __invert__(self) -> "SingleOperandHolder[NOT]":
41-
return SingleOperandHolder(NOT, self) # type: ignore
44+
def __invert__( # type:ignore[misc]
45+
self: Union[Type["BasePermission"], "BasePermission"]
46+
) -> "SingleOperandHolder[NOT]":
47+
return SingleOperandHolder(NOT, self)
4248

4349

4450
class BasePermissionMetaclass(OperationHolderMixin, ABCMeta):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ test = [
6060
"pytest-cov",
6161
"pytest-django",
6262
"pytest-asyncio",
63-
"mypy == 1.5.1",
63+
"mypy == 1.6.1",
6464
"ruff ==0.0.275",
6565
"black == 23.7.0",
6666
"injector >= 0.19.0",

0 commit comments

Comments
 (0)