-
Notifications
You must be signed in to change notification settings - Fork 8
Add type hints to src/palace/manager/api/admin/ code. #3046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,17 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from palace.manager.sqlalchemy.model.admin import Admin | ||
|
|
||
|
|
||
| class AdminAuthenticationProvider: | ||
| def sign_in_template(self, redirect_url): | ||
| def sign_in_template(self, redirect_url: str | None) -> str: | ||
| # Returns HTML to be rendered on the sign in page for | ||
| # this authentication provider. | ||
| raise NotImplementedError() | ||
|
|
||
| def active_credentials(self, admin): | ||
| def active_credentials(self, admin: Admin) -> bool: | ||
| # Returns True if the admin's credentials are not expired. | ||
| raise NotImplementedError() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| from flask import render_template, url_for | ||
| from flask import Response, render_template, url_for | ||
| from sqlalchemy.orm.session import Session | ||
| from werkzeug.datastructures import ImmutableMultiDict | ||
| from werkzeug.wrappers.response import Response as WerkzeugResponse | ||
|
|
||
| from palace.manager.api.admin.admin_authentication_provider import ( | ||
| AdminAuthenticationProvider, | ||
|
|
@@ -28,7 +30,7 @@ def __init__(self, send_email: SendEmailCallable): | |
| def get_secret_key(db: Session) -> str: | ||
| return Key.get_key(db, KeyType.ADMIN_SECRET_KEY, raise_exception=True).value | ||
|
|
||
| def sign_in_template(self, redirect): | ||
| def sign_in_template(self, redirect: str | None) -> str: | ||
| password_sign_in_url = url_for("password_auth") | ||
| forgot_password_url = url_for("admin_forgot_password") | ||
| return render_template( | ||
|
|
@@ -44,7 +46,9 @@ def sign_in_template(self, redirect): | |
| ) | ||
|
|
||
| @staticmethod | ||
| def forgot_password_template(redirect): | ||
| def forgot_password_template( | ||
| redirect: str | None | Response | WerkzeugResponse, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be |
||
| ) -> str: | ||
| forgot_password_url = url_for("admin_forgot_password") | ||
| return render_template( | ||
| "admin/auth/forgot-password.html.jinja2", | ||
|
|
@@ -56,7 +60,11 @@ def forgot_password_template(redirect): | |
| ) | ||
|
|
||
| @staticmethod | ||
| def reset_password_template(reset_password_token, admin_id, redirect): | ||
| def reset_password_template( | ||
| reset_password_token: str, | ||
| admin_id: int, | ||
| redirect: str | None | Response | WerkzeugResponse, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) -> str: | ||
| reset_password_url = url_for( | ||
| "admin_reset_password", | ||
| reset_password_token=reset_password_token, | ||
|
|
@@ -71,7 +79,13 @@ def reset_password_template(reset_password_token, admin_id, redirect): | |
| button_style=button_style, | ||
| ) | ||
|
|
||
| def sign_in(self, _db, request={}): | ||
| def sign_in( | ||
| self, | ||
| _db: Session, | ||
| request: ImmutableMultiDict[str, str] | dict[str, str | None] | None = None, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we be more precise about this? Maybe |
||
| ) -> tuple[dict[str, str], str | None] | tuple[ProblemDetail, None]: | ||
| if request is None: | ||
| request = {} | ||
| email = request.get("email") | ||
| password = request.get("password") | ||
| redirect_url = request.get("redirect") | ||
|
|
@@ -91,7 +105,7 @@ def sign_in(self, _db, request={}): | |
|
|
||
| return INVALID_ADMIN_CREDENTIALS, None | ||
|
|
||
| def active_credentials(self, admin): | ||
| def active_credentials(self, admin: Admin) -> bool: | ||
| # Admins who have a password are always active. | ||
| return True | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change needed? I don't see a place where
LocalAnalyticsExporter.export()returns aProblemDetail.