We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi everyone,
Sometimes may be useful to know about rights (roles) of a user for a particular view by its URL.
Something like this:
{% if current_user.can_view('myapp.list_objects') %} <a href="{{ url_for('myapp.list_objects') }}">Link</a> {% endif %}
Of course, we can write:
{% if current_user.has_roles('role1', 'role2') %} ...
And then for a view:
@myapp.route('/list') @roles_required('role1', 'role2') def list_objects(): ...
But in this case, we have a duplicate list of roles and we need to maintain these two pieces.
I propose are two things:
@roles_required
def roles_required(*role_names): def wrapper(func): func.ROLES = role_names @wraps(func) def decorated_view(*args, **kwargs): ...
UserMixin.has_roles_for_view
def has_roles_for_view(self, url): default = True # If it's not deny - is allow try: view_func = app.view_functions['users.users_list'] except KeyError: return default roles = getattr(view_func, 'ROLES', None) if roles is None: return default return self.has_roles(*roles)
I can prepare PR with these changes if needed.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hi everyone,
Sometimes may be useful to know about rights (roles) of a user for a particular view by its URL.
Something like this:
Of course, we can write:
And then for a view:
But in this case, we have a duplicate list of roles and we need to maintain these two pieces.
I propose are two things:
@roles_required
decorator for tracking views and their roles, e.g. like this:UserMixin.has_roles_for_view
method. Something like this:I can prepare PR with these changes if needed.
The text was updated successfully, but these errors were encountered: