-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: permission checking * fix: assert get query set * add TODOs * fix: permission operators
- Loading branch information
Showing
14 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
© Ocado Group | ||
Created on 02/02/2024 at 17:52:37(+00:00). | ||
Extends the permission operands provided by Django REST framework. | ||
""" | ||
|
||
import typing as t | ||
|
||
from rest_framework.permissions import AND as _AND | ||
from rest_framework.permissions import NOT as _NOT | ||
from rest_framework.permissions import OR as _OR | ||
from rest_framework.permissions import BasePermission | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring | ||
class AND(_AND): | ||
op1: BasePermission | ||
op2: BasePermission | ||
|
||
def __eq__(self, other): | ||
return ( | ||
isinstance(other, self.__class__) | ||
and self.op1 == other.op1 | ||
and self.op2 == other.op2 | ||
) | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring | ||
class NOT(_NOT): | ||
op1: BasePermission | ||
|
||
def __eq__(self, other): | ||
return isinstance(other, self.__class__) and self.op1 == other.op1 | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring | ||
class OR(_OR): | ||
op1: BasePermission | ||
op2: BasePermission | ||
|
||
def __eq__(self, other): | ||
return ( | ||
isinstance(other, self.__class__) | ||
and self.op1 == other.op1 | ||
and self.op2 == other.op2 | ||
) | ||
|
||
|
||
Permission = t.Union[BasePermission, AND, NOT, OR] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters