I have been going over the source code for a couple of days now. Is there a way to check if a user has a particular role in a template. My use case is simple. I only want to make a menu item available to certain users. it would be useful to do this:
{% if current_user.has_role('admin') %}
<li><a href="{% url_for('dashboard') %}">Dashboard</a></li>
{% endif %}
It was as simple as I thought it should be: I just had to add a has_role method to the User model. This allowed what I wanted above to work. This could be added to the user mixin:
def has_role(self, role):
return role in self.roles
Most helpful comment
It was as simple as I thought it should be: I just had to add a
has_rolemethod to the User model. This allowed what I wanted above to work. This could be added to the user mixin: