-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Helper function to get flask.request.admin (#2179)
* Function to load flask.request.admin * Code review feedback
- Loading branch information
1 parent
9a6e727
commit 1d1b4eb
Showing
11 changed files
with
66 additions
and
25 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
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
Empty file.
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,34 @@ | ||
from typing import Literal, TypeVar, overload | ||
|
||
from palace.manager.api.util.flask import get_request_var | ||
from palace.manager.sqlalchemy.model.admin import Admin | ||
from palace.manager.util.sentinel import SentinelType | ||
|
||
TDefault = TypeVar("TDefault") | ||
|
||
|
||
@overload | ||
def get_request_admin() -> Admin: ... | ||
|
||
|
||
@overload | ||
def get_request_admin(*, default: TDefault) -> Admin | TDefault: ... | ||
|
||
|
||
def get_request_admin( | ||
*, default: TDefault | Literal[SentinelType.NotGiven] = SentinelType.NotGiven | ||
) -> Admin | TDefault: | ||
""" | ||
Retrieve the 'admin' attribute from the current Flask request object. | ||
This attribute should be set by using the @requires_admin decorator on the route | ||
or by calling the AdminController.authenticated_admin_from_request | ||
method. | ||
:param default: The default value to return if the 'admin' attribute is not set. | ||
If not provided, a `PalaceValueError` will be raised if the attribute is missing | ||
or has an incorrect type. | ||
:return: The `Admin` object from the request, or the default value if provided. | ||
""" | ||
return get_request_var("admin", Admin, default=default) |
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