#NEWLINE# def process_api_request( self , request ) : #NEWLINE# #INDENT# reference = request . reference #NEWLINE# if ( reference . kind == 'subdocument' ) : #NEWLINE# #INDENT# ( _ , auth_target , _ , _ ) = reference . value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# auth_target = reference . value #NEWLINE# #UNINDENT# permission_name = self . _get_permission_name ( request ) #NEWLINE# authentication_target = self . authentication_requirement ( auth_target , permission_name ) #NEWLINE# authorization_target = self . authorization_requirement ( auth_target , permission_name ) #NEWLINE# if ( authentication_target is None ) : #NEWLINE# #INDENT# return request #NEWLINE# #UNINDENT# if ( reference . format == 'schema' ) : #NEWLINE# #INDENT# return request #NEWLINE# #UNINDENT# if ( reference . format == 'help' ) : #NEWLINE# #INDENT# return request #NEWLINE# #UNINDENT# auth_token = request . api_arguments . get ( '_auth' , None ) #NEWLINE# if ( not auth_token ) : #NEWLINE# #INDENT# bearer = request . headers . get ( 'Authorization' , None ) #NEWLINE# if bearer : #NEWLINE# #INDENT# auth_token = bearer [ 7 : ] #NEWLINE# #UNINDENT# #UNINDENT# if auth_token : #NEWLINE# #INDENT# user = request . suite [ 'auth' ] . check ( auth_token ) #NEWLINE# request . user = user #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# request . user = None #NEWLINE# user = None #NEWLINE# #UNINDENT# if ( ( ( authentication_target is not None ) or ( authorization_target is not None ) ) and ( not user ) ) : #NEWLINE# #INDENT# print ( 'Permission error!!!!!' ) #NEWLINE# raise PermissionError ( 'Target {url} requires authentication or authorization, but user is anonymous' . format ( url = reference . url ) ) #NEWLINE# #UNINDENT# if ( user and user [ 'admin' ] ) : #NEWLINE# #INDENT# return request #NEWLINE# #UNINDENT# if ( authorization_target is None ) : #NEWLINE# #INDENT# return request #NEWLINE# #UNINDENT# for role in user . fetch ( 'roles' ) : #NEWLINE# #INDENT# if role . authorizes ( authorization_target , permission_name ) : #NEWLINE# #INDENT# return request #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# msg = "Permission '{name}' denied for '{user}' accessing '{url}'" . format ( user = user , url = reference . url , name = permission_name ) #NEWLINE# request . suite . log . error ( msg ) #NEWLINE# raise PermissionError ( msg )