chaoswg.admin.AuthAdminModelView.is_accessible()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 0
1
from flask import redirect
2
from flask_admin import Admin, AdminIndexView, expose
3
from flask_admin.contrib.peewee import ModelView
4
from flask_admin.form import SecureForm
5
from flask_admin.menu import MenuLink
6
from flask_login import current_user
7
8
from chaoswg.models import User, Task, History
9
10
11
# Custom flask-admin classes for authentication
12
class AuthAdminModelView(ModelView):
13
    form_base_class = SecureForm
14
15
    @staticmethod
16
    def is_accessible():
17
        return current_user.is_authenticated
18
19
20
class AuthAdminUserModelView(AuthAdminModelView):
21
    column_exclude_list = ['password']
22
23
24
class AuthAdminIndexView(AdminIndexView):
25
    @expose('/')
26
    def index(self):
27
        if not current_user.is_authenticated:
28
            return redirect('/login')
29
        return super(AuthAdminIndexView, self).index()
30
31
32
def init_admin(app):
33
    """
34
    initializes the flask-admin interface
35
    :param app:
36
    :return:
37
    """
38
    admin = Admin(app, index_view=AuthAdminIndexView(), name='ChaosWG Manager Admin',
39
                  template_mode='bootstrap3')
40
    admin.add_link(MenuLink(name='Back Home', url='/tasks'))
41
    admin.add_view(AuthAdminModelView(Task))
42
    admin.add_view(AuthAdminUserModelView(User))
43
    admin.add_view(AuthAdminModelView(History))
44