2013-02-05 14:16:51 -05:00
|
|
|
class DraftController < ApplicationController
|
2018-02-01 15:17:59 +11:00
|
|
|
requires_login
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
skip_before_action :check_xhr, :preload_json
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
def show
|
|
|
|
seq = params[:sequence] || DraftSequence.current(current_user, params[:draft_key])
|
2017-07-28 10:20:09 +09:00
|
|
|
render json: { draft: Draft.get(current_user, params[:draft_key], seq), draft_sequence: seq }
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2013-02-07 16:45:24 +01:00
|
|
|
Draft.set(current_user, params[:draft_key], params[:sequence].to_i, params[:data])
|
2018-11-14 13:56:25 +02:00
|
|
|
|
|
|
|
if params[:post_id] && params[:original_text]
|
|
|
|
post = Post.find_by(id: params[:post_id])
|
|
|
|
if post && post.raw != params[:original_text]
|
|
|
|
conflict_user = BasicUserSerializer.new(post.last_editor, root: false)
|
|
|
|
return render json: success_json.merge(conflict_user: conflict_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-11 16:18:46 +10:00
|
|
|
render json: success_json
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
Draft.clear(current_user, params[:draft_key], params[:sequence].to_i)
|
2013-09-11 16:18:46 +10:00
|
|
|
render json: success_json
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|