#NEWLINE# @ put ( '/s/topics/{topic_id}/posts/{post_id}' ) #NEWLINE# def update_post_route( request , topic_id , post_id ) : #NEWLINE# #INDENT# "\n    Update an existing post. Must be one's own post.\n\n    For post:\n    - Only the body field may be changed.\n\n    For proposals:\n    - Only the name, body, and status fields can be changed.\n    - The status can only be changed to declined, and only when\n      the current status is pending or blocked.\n\n    For votes:\n    - The only fields that can be updated are body and response.\n    " #NEWLINE# db_conn = request [ 'db_conn' ] #NEWLINE# current_user = get_current_user ( request ) #NEWLINE# if ( not current_user ) : #NEWLINE# #INDENT# return abort ( 401 ) #NEWLINE# #UNINDENT# post_ = get_post_facade ( db_conn , post_id ) #NEWLINE# if ( not post_ ) : #NEWLINE# #INDENT# return abort ( 404 ) #NEWLINE# #UNINDENT# if ( post_ [ 'user_id' ] != current_user [ 'id' ] ) : #NEWLINE# #INDENT# return abort ( 403 ) #NEWLINE# #UNINDENT# post_kind = post_ [ 'kind' ] #NEWLINE# post_data = request [ 'params' ] [ 'post' ] #NEWLINE# if ( post_kind is 'post' ) : #NEWLINE# #INDENT# post_data = pick ( post_data , ( 'body' , ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( post_kind is 'proposal' ) : #NEWLINE# #INDENT# post_data = pick ( post_data , ( 'name' , 'body' , 'status' ) ) #NEWLINE# if ( ( post_data . get ( 'status' ) != 'declined' ) or ( post_data . get ( 'status' ) not in ( 'pending' , 'blocked' ) ) ) : #NEWLINE# #INDENT# del post_data [ 'status' ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( post_kind is 'vote' ) : #NEWLINE# #INDENT# post_data = pick ( post_data , ( 'body' , 'response' ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# ( post_ , errors ) = post_ . update ( db_conn , post_data ) #NEWLINE# if errors : #NEWLINE# #INDENT# errors = prefix_error_names ( 'post.' , errors ) #NEWLINE# return ( 400 , { #NEWLINE# #INDENT# 'errors' : errors , #NEWLINE# 'ref' : 'E4LFwRv2WEJZks7use7TCpww' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if ( post_kind == 'proposal' ) : #NEWLINE# #INDENT# update_entity_status ( db_conn , post_ ) #NEWLINE# #UNINDENT# if ( post_kind == 'vote' ) : #NEWLINE# #INDENT# proposal = Proposal . get ( db_conn , id = post_ [ 'replies_to_id' ] ) #NEWLINE# update_entity_status ( db_conn , proposal ) #NEWLINE# #UNINDENT# return ( 200 , { #NEWLINE# #INDENT# 'post' : post_ . deliver ( ) , #NEWLINE# #UNINDENT# } )