def edit_message(id):
"""
Modify an existing message.
This endpoint is requires a valid user token.
Note: users are only allowed to modify their own messages.
"""
msg = Message.query.get_or_404(id)
if msg.user_id != g.jwt_claims.get('user_id'):
abort(403)
msg.from_dict(request.get_json() or {})
db.session.add(msg)
db.session.commit()
# render the markdown and expand the links in a background task
if app.config['TESTING']:
# for unit tests, render synchronously
render_message(msg.id)
else:
# asynchronous rendering
render_thread = threading.Thread(target=render_message,
args=(msg.id,))
render_thread.start()
return '', 204
评论列表
文章目录