0

Below code can give access to superadmin: What if I have to build another admin page for role admin which is created by superamin

class MyModelView(sqla.ModelView):
def is_accessible(self):
    return (current_user.is_active and
            current_user.is_authenticated and
            current_user.has_role('superadmin')
    )

def _handle_view(self, name, **kwargs):

    if not self.is_accessible():
        if current_user.is_authenticated:

            abort(403)
        else:
 
            return redirect(url_for('security.login', next=request.url))

Any help or suggestion would be really appreciated!!

  • Does this answer your question? [flask-admin is\_accessible usage](https://stackoverflow.com/questions/33646165/flask-admin-is-accessible-usage) – pjcunningham Feb 16 '22 at 16:48

1 Answers1

0

Make another template(of admin) and add a new role in your table- Admin, then in,

@roles_required

decorator give the role of the Admin and give the route by

@app.route

. By this the user having a role of Admin will have access to that page.

chirkut
  • 16
  • 1
  • May be my answer can relate different to your question because I did not understand your question well. It would be better if detail your question and some more codes like your User Model and Role Model, feel free to ask any further query. – chirkut Feb 16 '22 at 05:44
  • what I want to make is there are three roles (SuperAdmin, Admin, User). Here, if superadmin login he can do a CRUD operation on manager and under manager SuperAdmin can create user. Later on if manager login, he/she can do CRUD operation to his/her users only . – Kenil Shah Feb 16 '22 at 06:56
  • https://flask-user.readthedocs.io/en/latest/basic_app.html . Go through this documentation . And on thing you will need more for use and that this @ has_role. I dont know much about @ has_role so just google it read official documentation. Thank you. – chirkut Feb 16 '22 at 10:37