<s> """<STR_LIT>""" <EOL> from functools import wraps <EOL> import pecan <EOL> from st2common . rbac import utils <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> def request_user_is_admin ( ) : <EOL> def decorate ( func ) : <EOL> @ wraps ( func ) <EOL> def func_wrapper ( * args , ** kwargs ) : <EOL> utils . assert_request_user_is_admin ( request = pecan . request ) <EOL> return func ( * args , ** kwargs ) <EOL> return func_wrapper <EOL> return decorate <EOL> def request_user_is_system_admin ( ) : <EOL> def decorate ( func ) : <EOL> @ wraps ( func ) <EOL> def func_wrapper ( * args , ** kwargs ) : <EOL> utils . assert_request_user_is_system_admin ( request = pecan . request ) <EOL> return func ( * args , ** kwargs ) <EOL> return func_wrapper <EOL> return decorate <EOL> def request_user_has_permission ( permission_type ) : <EOL> def decorate ( func ) : <EOL> @ wraps ( func ) <EOL> def func_wrapper ( * args , ** kwargs ) : <EOL> utils . assert_request_user_has_permission ( request = pecan . request , <EOL> permission_type = permission_type ) <EOL> return func ( * args , ** kwargs ) <EOL> return func_wrapper <EOL> return decorate <EOL> def request_user_has_resource_api_permission ( permission_type ) : <EOL> """<STR_LIT>""" <EOL> def decorate ( func ) : <EOL> function_name = func . __name__ <EOL> if function_name not in [ '<STR_LIT>' ] : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> @ wraps ( func ) <EOL> def func_wrapper ( * args , ** kwargs ) : <EOL> resource_api = args [ <NUM_LIT:1> ] <EOL> utils . assert_request_user_has_resource_api_permission ( request = pecan . request , <EOL> resource_api = resource_api , <EOL> permission_type = permission_type ) <EOL> return func ( * args , ** kwargs ) <EOL> return func_wrapper <EOL> return decorate <EOL> def request_user_has_resource_db_permission ( permission_type ) : <EOL> """<STR_LIT>""" <EOL> valid_method_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def decorate ( func ) : <EOL> function_name = func . __name__ <EOL> if function_name not in valid_method_names : <EOL> raise Exception ( '<STR_LIT>' % <EOL> ( '<STR_LIT:U+002CU+0020>' . join ( valid_method_names ) ) ) <EOL> @ wraps ( func ) <EOL> def func_wrapper ( * args , ** kwargs ) : <EOL> controller_instance = args [ <NUM_LIT:0> ] <EOL> resource_id = args [ <NUM_LIT:1> ] <EOL> get_one_db_method = controller_instance . get_one_db_method <EOL> resource_db = get_one_db_method ( resource_id ) <EOL> utils . assert_request_user_has_resource_db_permission ( request = pecan . request , <EOL> resource_db = resource_db , <EOL> permission_type = permission_type ) <EOL> return func ( * args , ** kwargs ) <EOL> return func_wrapper <EOL> return decorate <EOL> def request_user_has_webhook_permission ( permission_type ) : <EOL> """<STR_LIT>""" <EOL> from st2common . models . db . webhook import WebhookDB <EOL> def decorate ( func ) : <EOL> @ wraps ( func ) <EOL> def func_wrapper ( * args , ** kwargs ) : <EOL> hook = '<STR_LIT:/>' . join ( args [ <NUM_LIT:1> : ] ) <EOL> webhook_db = WebhookDB ( name = hook ) <EOL> resource_db = webhook_db <EOL> utils . assert_request_user_has_resource_db_permission ( request = pecan . request , <EOL> resource_db = resource_db , <EOL> permission_type = permission_type ) <EOL> return func ( * args , ** kwargs ) <EOL> return func_wrapper <EOL> return decorate </s>
