2013-02-05 14:16:51 -05:00
|
|
|
class DraftController < ApplicationController
|
2018-01-31 23:17:59 -05:00
|
|
|
requires_login
|
|
|
|
|
2017-08-31 00:06:56 -04: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-27 21:20:09 -04: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 10:45:24 -05:00
|
|
|
Draft.set(current_user, params[:draft_key], params[:sequence].to_i, params[:data])
|
2018-11-14 06:56:25 -05:00
|
|
|
|
2018-11-14 11:47:59 -05:00
|
|
|
if data = JSON::parse(params[:data])
|
2018-11-14 21:14:07 -05:00
|
|
|
# this is a bit of a kludge we need to remove (all the parsing) too many special cases here
|
|
|
|
# we need to catch action edit and action editSharedDraft
|
|
|
|
if data["postId"].present? && data["originalText"].present? && data["action"].to_s.start_with?("edit")
|
2018-11-14 11:47:59 -05:00
|
|
|
post = Post.find_by(id: data["postId"])
|
|
|
|
if post && post.raw != data["originalText"]
|
|
|
|
conflict_user = BasicUserSerializer.new(post.last_editor, root: false)
|
|
|
|
return render json: success_json.merge(conflict_user: conflict_user)
|
|
|
|
end
|
2018-11-14 06:56:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-11 02:18:46 -04: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 02:18:46 -04:00
|
|
|
render json: success_json
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|