-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update documentation for permissions
- Loading branch information
Showing
3 changed files
with
68 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from esmerald import Request | ||
from esmerald.permissions.base import BaseAbstractUserPermission | ||
from esmerald.types import APIGateHandler | ||
|
||
|
||
class IsUserAdmin(BaseAbstractUserPermission): | ||
""" | ||
Simply check if a user has admin access or not. | ||
BaseAbstractUserPermission inherits from BasePermission. | ||
""" | ||
|
||
def is_user_authenticated(self, request: "Request") -> bool: | ||
""" | ||
Logic to check if the user is authenticated | ||
""" | ||
... | ||
|
||
def is_user_staff(self, request: "Request") -> bool: | ||
""" | ||
Logic to check if user is staff | ||
""" | ||
... | ||
|
||
async def has_permission(self, request: "Request", apiview: "APIGateHandler"): | ||
super().has_permission(request, apiview) | ||
return bool(request.user and self.is_user_staff(request)) |
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,12 @@ | ||
from esmerald import BasePermission, Request | ||
from esmerald.types import APIGateHandler | ||
|
||
|
||
class IsProjectAllowed(BasePermission): | ||
""" | ||
Permission to validate if has access to a given project | ||
""" | ||
|
||
async def has_permission(self, request: "Request", apiview: "APIGateHandler"): | ||
allow_project = request.headers.get("allow_access") | ||
return bool(allow_project) |