I have managed to get roles working with this code but!
class Roled(object):
def is_accessible(self):
roles_accepted = getattr(self, 'roles_accepted', None)
if flask_login.current_user.is_authenticated:
user = CustomUser.objects.get(email=flask_login.current_user.id)
for role in user.roles:
for permission in role.permissions:
if permission == "admin":
return flask_login.current_user.is_authenticated
def inaccessible_callback(self, name, **kwargs):
# redirect to login page if user doesn't have access
return redirect(url_for('login', next=request.url))
class AdminView(Roled, ModelView):
def __init__(self, *args, **kwargs):
self.roles_accepted = kwargs.pop('roles_accepted', list())
super(AdminView, self).__init__(*args, **kwargs)
class TranslationView(Roled, ModelView):
column_filters = ['eng']
column_searchable_list = ('eng','geo', 'name')
Now I have a problem adding roles_accapted to each add_view when adding flask admin views as it was in this question
Your TranslationView
should inherit from the AdminView
class. i.e.
class TranslationView(AdminView):
column_filters = ['eng']
column_searchable_list = ('eng','geo', 'name')