discourse/app/controllers/draft_controller.rb

33 lines
980 B
Ruby
Raw Normal View History

2013-02-06 03:16:51 +08:00
class DraftController < ApplicationController
requires_login
skip_before_action :check_xhr, :preload_json
2013-02-06 03:16:51 +08:00
def show
seq = params[:sequence] || DraftSequence.current(current_user, params[:draft_key])
2017-07-28 09:20:09 +08:00
render json: { draft: Draft.get(current_user, params[:draft_key], seq), draft_sequence: seq }
2013-02-06 03:16:51 +08:00
end
def update
2013-02-07 23:45:24 +08:00
Draft.set(current_user, params[:draft_key], params[:sequence].to_i, params[:data])
if data = JSON::parse(params[:data])
if data["postId"].present? && data["originalText"].present?
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
end
end
render json: success_json
2013-02-06 03:16:51 +08:00
end
def destroy
Draft.clear(current_user, params[:draft_key], params[:sequence].to_i)
render json: success_json
2013-02-06 03:16:51 +08:00
end
end