Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosenpfand committed Aug 6, 2023
1 parent e0d122b commit 5783c83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 4 additions & 8 deletions app/extended_security/admin.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import typing
from flask import abort, current_app
from flask_admin.form import SecureForm
from flask_admin.contrib.sqla import ModelView
from flask_admin.base import AdminIndexView
from flask_security import current_user


def user_formatter(view, context, model, name):
return f"{model.user.email}"


class AdminSecurityMixIn:
def is_accessible(self):
def is_accessible(self) -> bool:
return (
current_user.is_active
and current_user.is_authenticated
and current_user.has_role(current_app.config["ADMIN_ROLE_NAME"])
)

def inaccessible_callback(self, name, **kwargs):
return abort(404)
def inaccessible_callback(self, name: str, **kwargs: typing.Any) -> typing.NoReturn:
abort(404)


class AdminModelView(AdminSecurityMixIn, ModelView):
Expand All @@ -27,7 +24,6 @@ class AdminModelView(AdminSecurityMixIn, ModelView):
can_view_details = True
can_export = True
form_base_class = SecureForm
column_formatters = dict(user=user_formatter)


class ExtendedAdminIndex(AdminSecurityMixIn, AdminIndexView):
Expand Down
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ ignore_missing_imports = True
ignore_missing_imports = True

[mypy-flask_talisman.*]
ignore_missing_imports = True

[mypy-flask_admin.*]
ignore_missing_imports = True

0 comments on commit 5783c83

Please sign in to comment.