Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UnauthorisedAccessError(Exception):
- """ User does not have access priviledges """
- @bp.app_errorhandler(UnauthorisedAccessError)
- def handle_login_error(e):
- """Redirect to the login page when LoginError is raised."""
- flash("You do not have sufficient access rights to perform this action",
- 'error')
- return redirect(url_for('auth.login'))
- def check_user_group(required_groups):
- """
- Traverse list of required access groups to check for one or more matches
- """
- access = [current_user.has_access(PermissionGroups.query.filter_by(
- group_name=group
- ).first())
- for group in required_groups]
- if not any(access):
- raise UnauthorisedAccessError
- def group_required(*groups):
- """
- Decorate a function to require the user to have at least one of the groups.
- """
- def decorator(func):
- @wraps(func)
- def check_auth(*args, **kwargs):
- check_user_group(*groups)
- return func(*args, **kwargs)
- return check_auth
- return decorator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement