app/controllers/documents_v2_controller.rb
def save
    @document = Document.find_by(id: params[:id])
    render_not_found && return unless @document

    if ENV['SHARED_DOCS_DISABLED'] && @document.shared
      render_shared_docs_error && return
    end

    return unless require_valid_read_write_access_key

    if params[:reset].present?
      @document.content = @document.original_content
    elsif params[:source].present?
      source_document = Document.find_by(id: params[:source])
      if !source_document
        render json: {status: "Error", errors: ['Source document not found'], valid: false, message: 'error.writeFailed' }, status: 400
        return
      elsif !source_document.shared
        render json: {status: "Error", errors: ['Source document is not a shared document'], valid: false, message: 'error.writeFailed' }, status: 400
        return
      end
      @document.content = source_document.content
    else
      @document.form_content = request.raw_post
    end

    @document.shared = shared_param_value() if params[:shared].present?

    if @document.save
      render json: {status: "Saved", valid: true, id: @document.id }, status: 200
    else
      render json: {status: "Error", errors: @document.errors.full_messages, valid: false, message: 'error.writeFailed' }, status: 400
    end
  end
# don't check for csrf token
don't check for csrf token
don ' t check for csrf token
def save
    @document = Document.find_by(id: params[:id])
    render_not_found && return unless @document
    if ENV['SHARED_DOCS_DISABLED'] && @document.shared
      render_shared_docs_error && return
    end
    return unless require_valid_read_write_access_key
    if params[:reset].present?
      @document.content = @document.original_content
    elsif params[:source].present?
      source_document = Document.find_by(id: params[:source])
      if !source_document
        render json: {status: "Error", errors: ['Source document not found'], valid: false, message: 'error.writeFailed' }, status: 400
        return
      elsif !source_document.shared
        render json: {status: "Error", errors: ['Source document is not a shared document'], valid: false, message: 'error.writeFailed' }, status: 400
        return
      end
      @document.content = source_document.content
    else
      @document.form_content = request.raw_post
    end
    @document.shared = shared_param_value() if params[:shared].present?
    if @document.save
      render json: {status: "Saved", valid: true, id: @document.id }, status: 200
    else
      render json: {status: "Error", errors: @document.errors.full_messages, valid: false, message: 'error.writeFailed' }, status: 400
    end
  end
def save @document = Document . find_by ( id : params [ :id ] ) render_not_found && return unless @document if ENV [ 'SHARED_DOCS_DISABLED' ] && @document . shared render_shared_docs_error && return end return unless require_valid_read_write_access_key if params [ :reset ] . present? @document . content = @document . original_content elsif params [ :source ] . present? source_document = Document . find_by ( id : params [ :source ] ) if ! source_document render json : { status : "Error" , errors : [ 'Source document not found' ] , valid : false , message : 'error.writeFailed' } , status : 400 return elsif ! source_document . shared render json : { status : "Error" , errors : [ 'Source document is not a shared document' ] , valid : false , message : 'error.writeFailed' } , status : 400 return end @document . content = source_document . content else @document . form_content = request . raw_post end @document . shared = shared_param_value ( ) if params [ :shared ] . present? if @document . save render json : { status : "Saved" , valid : true , id : @document . id } , status : 200 else render json : { status : "Error" , errors : @document . errors . full_messages , valid : false , message : 'error.writeFailed' } , status : 400 end end
don't check for csrf token
don ' t check for csrf token