Flask-AppBuilder icon indicating copy to clipboard operation
Flask-AppBuilder copied to clipboard

Adding links to Index

Open michaelzdrav opened this issue 1 year ago • 2 comments

I am currently trying to add links to my index page and all pages where the user has not authenticated to. Everytime I add these, it is only visible once I am authenticated.

I have tried to use the Public role, but this has not been working.

I am passing the IndexView correctly, and it sets fine.

appbuilder = AppBuilder(app, db.session, indexview=MyIndexView)
appbuilder.add_link('My Index','MyIndexView.index')    # This only appears when the user is authenticated

This is the IndexView

class MyIndexView(IndexView):
    index_template = 'index.html'
    default_view = 'index'
    route_base= ''
    unauth_template = 'mybase.html'

    @expose("/")
    def index(self):
        if g.user is not None and g.user.is_authenticated:

            return self.render_template(self.index_template, appbuilder=self.appbuilder)

        return self.render_template(self.unauth_template, appbuilder=self.appbuilder)

My config.py is as follows:

AUTH_ROLE_PUBLIC = 'Public'

FAB_ROLES = {
    "Public": [
        ["MyIndexView", "menu_access"],
        ["MyIndexView", "can_info"],
        ["MyIndexView", "can_show"],
        ["MyIndexView", "can_get"],
    ]
}

There must be something I am obviously missing, i've followed the example at https://flask-appbuilder.readthedocs.io/en/latest/security.html with the .* for each permission, but this did not work either.

Is this a permissions issue? How am I doing it wrong? Thanks in advance!

michaelzdrav avatar Sep 25 '23 10:09 michaelzdrav

Interesting, have you tried adding those permissions manually using the UI without using FAB_ROLES?

dpgaspar avatar Oct 11 '23 23:10 dpgaspar

I was able to reproduce this aswell at first. Adding it via the UI seems to work. But even if i use the exact name in the backend database for permission and view it didnt seem to work. This also seems to be the issue with "menu_access" on menu categories.

After adding the permission to the public role it did seem to work, and even after deleting those it did work.

Then i was wondering if there was a problem reloading the configuration in my docker container.

After doing a new install of my appbuilder app all seems to work well.

@michaelzdrav Are you running this app in a docker container, ifso: maybe you are still using the old configuration. What happens if you do a docker-compose down and docker-compose up

Yoyasp avatar Dec 19 '23 08:12 Yoyasp