#NEWLINE# def post( self ) : #NEWLINE# #INDENT# req = request . get_json ( True ) #NEWLINE# require_fields ( req , ( 'options' , 'name' , 'query_id' ) ) #NEWLINE# query = models . Query . get_by_id_and_org ( req [ 'query_id' ] , self . current_org ) #NEWLINE# require_access ( query . groups , self . current_user , view_only ) #NEWLINE# alert = models . Alert . create ( name = req [ 'name' ] , query = query , user = self . current_user , options = req [ 'options' ] ) #NEWLINE# self . record_event ( { #NEWLINE# #INDENT# 'action' : 'create' , #NEWLINE# 'timestamp' : int ( time . time ( ) ) , #NEWLINE# 'object_id' : alert . id , #NEWLINE# 'object_type' : 'alert' , #NEWLINE# #UNINDENT# } ) #NEWLINE# models . AlertSubscription . create ( alert = alert , user = self . current_user ) #NEWLINE# self . record_event ( { #NEWLINE# #INDENT# 'action' : 'subscribe' , #NEWLINE# 'timestamp' : int ( time . time ( ) ) , #NEWLINE# 'object_id' : alert . id , #NEWLINE# 'object_type' : 'alert' , #NEWLINE# #UNINDENT# } ) #NEWLINE# return alert . to_dict ( )