#NEWLINE# def permission_required( permission = None , methods = None ) : #NEWLINE# #INDENT# def permission_decorator( f ) : #NEWLINE# #INDENT# decorator_order_guard ( f , 'auth.permission_required' ) #NEWLINE# perm = ( permission or f . func_name ) #NEWLINE# meths = ( [ m . upper ( ) for m in methods ] if methods else None ) #NEWLINE# permission_registered . send ( f , permission = perm ) #NEWLINE# @ functools . wraps ( f ) #NEWLINE# def decorated_function( * args , **kwargs ) : #NEWLINE# #INDENT# if ( meths and ( flask . request . method . upper ( ) not in meths ) ) : #NEWLINE# #INDENT# return f ( * args , ** kwargs ) #NEWLINE# #UNINDENT# if ( is_logged_in ( ) and current_user_db ( ) . has_permission ( perm ) ) : #NEWLINE# #INDENT# return f ( * args , ** kwargs ) #NEWLINE# #UNINDENT# if ( not is_logged_in ( ) ) : #NEWLINE# #INDENT# if flask . request . path . startswith ( '/api/' ) : #NEWLINE# #INDENT# return flask . abort ( 401 ) #NEWLINE# #UNINDENT# return flask . redirect ( flask . url_for ( 'signin' , next = flask . request . url ) ) #NEWLINE# #UNINDENT# return flask . abort ( 403 ) #NEWLINE# #UNINDENT# return decorated_function #NEWLINE# #UNINDENT# return permission_decorator