flask-rbac icon indicating copy to clipboard operation
flask-rbac copied to clipboard

Unable to use @rbac.exempt with Blueprints

Open daobeng opened this issue 3 years ago • 1 comments

PR-29 Added the ability to specify endpoints for the @rbac.allow and @rbac.deny to allow them to play nicely with blueprints

@rbac.exempt still uses the view_func.__name__ and hence, doesn't work with blueprints. For backwards compatibility, I suppose it might be useful to provide another exempt function that can take an endpoint parameter

If this is affecting any, the work around to inhert the RBAC and redefine the exempt decorator

class MRBAC(RBAC):
    def exempt(self, endpoint=None):
        def decorator(view_func):
            self.acl.exempt(endpoint or view_func.__name__)
            return view_func

        return decorator

rbac = MRBAC()

@blueprint.route('/everyone/can/access')
@rbac.exempt(endpoint='blueprint.everyone_can_access')
def everyone_can_access():
    return 'Hello~'

daobeng avatar Jun 08 '21 15:06 daobeng

Same issue here, thanks for reporting daobeng & for workaround

elanor-sparx avatar Apr 26 '22 20:04 elanor-sparx