Python flask_login.current_user.roles() Examples
The following are 8
code examples of flask_login.current_user.roles().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_login.current_user
, or try the search function
.
Example #1
Source File: permissions.py From gitmark with GNU General Public License v2.0 | 8 votes |
def on_identity_loaded(sender, identity): # Set the identity user object identity.user = current_user # Add the UserNeed to the identity if hasattr(current_user, 'username'): identity.provides.add(UserNeed(current_user.username)) # Assuming the User model has a list of roles, update the # identity with the roles that the user provides if hasattr(current_user, 'role'): # for role in current_user.roles: identity.provides.add(RoleNeed(current_user.role)) # if current_user.is_superuser: if hasattr(current_user, 'is_superuser') and current_user.is_superuser: identity.provides.add(su_need) # return current_user.role identity.allow_su = su_permission.allows(identity) identity.allow_admin = admin_permission.allows(identity) identity.allow_edit = editor_permission.allows(identity) identity.allow_general = general_permission.allows(identity)
Example #2
Source File: decorators.py From comport with BSD 3-Clause "New" or "Revised" License | 6 votes |
def requires_roles(required_roles): ''' Takes in a list of roles and checks whether the user has access to those role ''' def check_roles(view_function): @wraps(view_function) def decorated_function(*args, **kwargs): def names(role): return role.name if not all(r in map(names, current_user.roles) for r in required_roles): flash('You do not have sufficient permissions to do that', 'alert alert-danger') return redirect(request.args.get('next') or '/') return view_function(*args, **kwargs) return decorated_function return check_roles
Example #3
Source File: controllers.py From Mastering-Flask-Web-Development-Second-Edition with MIT License | 5 votes |
def make_cache_key(*args, **kwargs): path = request.path args = str(hash(frozenset(request.args.items()))) messages = str(hash(frozenset(get_flashed_messages()))) if current_user.is_authenticated: roles = str(current_user.roles) else: roles = "" return (path + args + roles + session.get('locale', '') + messages).encode('utf-8')
Example #4
Source File: controllers.py From Mastering-Flask-Web-Development-Second-Edition with MIT License | 5 votes |
def make_cache_key(*args, **kwargs): path = request.path args = str(hash(frozenset(request.args.items()))) messages = str(hash(frozenset(get_flashed_messages()))) if current_user.is_authenticated: roles = str(current_user.roles) else: roles = "" return (path + args + roles + session.get('locale', '') + messages).encode('utf-8')
Example #5
Source File: controllers.py From Mastering-Flask-Web-Development-Second-Edition with MIT License | 5 votes |
def make_cache_key(*args, **kwargs): path = request.path args = str(hash(frozenset(request.args.items()))) messages = str(hash(frozenset(get_flashed_messages()))) if current_user.is_authenticated: roles = str(current_user.roles) else: roles = "" return (path + args + roles + session.get('locale', '') + messages).encode('utf-8')
Example #6
Source File: controllers.py From Mastering-Flask-Web-Development-Second-Edition with MIT License | 5 votes |
def make_cache_key(*args, **kwargs): path = request.path args = str(hash(frozenset(request.args.items()))) messages = str(hash(frozenset(get_flashed_messages()))) if current_user.is_authenticated: roles = str(current_user.roles) else: roles = "" return (path + args + roles + session.get('locale', '') + messages).encode('utf-8')
Example #7
Source File: attribute.py From contextualise with MIT License | 4 votes |
def index(map_identifier, topic_identifier): topic_store = get_topic_store() if "admin" not in current_user.roles: abort(403) topic_map = topic_store.get_topic_map(map_identifier, current_user.id) if topic_map is None: abort(404) # If the map doesn't belong to the user and they don't have the right # collaboration mode on the map, then abort if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT: abort(403) topic = topic_store.get_topic( map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES, ) if topic is None: abort(404) attributes = [] entity_attributes = topic_store.get_attributes(map_identifier, topic_identifier) for entity_attribute in entity_attributes: attributes.append( { "identifier": entity_attribute.identifier, "name": entity_attribute.name, "value": entity_attribute.value, "type": str(entity_attribute.data_type).lower(), "scope": entity_attribute.scope, } ) creation_date_attribute = topic.get_attribute_by_name("creation-timestamp") creation_date = maya.parse(creation_date_attribute.value) if creation_date_attribute else "Undefined" entity_type = "topic" return_url = "topic.view" return render_template( "attribute/index.html", topic_map=topic_map, topic=topic, entity_type=entity_type, return_url=return_url, attributes=attributes, creation_date=creation_date, )
Example #8
Source File: attribute.py From contextualise with MIT License | 4 votes |
def delete(map_identifier, topic_identifier, attribute_identifier): topic_store = get_topic_store() if "admin" not in current_user.roles: abort(403) topic_map = topic_store.get_topic_map(map_identifier, current_user.id) if topic_map is None: abort(404) # If the map doesn't belong to the user and they don't have the right # collaboration mode on the map, then abort if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT: abort(403) topic = topic_store.get_topic( map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES, ) if topic is None: abort(404) attribute = topic_store.get_attribute(map_identifier, attribute_identifier) if attribute is None: abort(404) form_attribute_name = attribute.name form_attribute_value = attribute.value form_attribute_type = str(attribute.data_type).capitalize() form_attribute_scope = attribute.scope if request.method == "POST": # Delete attribute from topic store topic_store.delete_attribute(map_identifier, attribute.identifier) flash("Attribute successfully deleted.", "warning") return redirect( url_for("attribute.index", map_identifier=topic_map.identifier, topic_identifier=topic.identifier,) ) entity_type = "topic" post_url = "attribute.delete" cancel_url = "attribute.index" return render_template( "attribute/delete.html", topic_map=topic_map, topic=topic, attribute=attribute, entity_type=entity_type, post_url=post_url, cancel_url=cancel_url, attribute_name=form_attribute_name, attribute_value=form_attribute_value, attribute_type=form_attribute_type, attribute_scope=form_attribute_scope, )