From 4573308f6676cc2729d24789088c7b3849d7c8e9 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Tue, 5 Sep 2017 16:54:22 +0200 Subject: [PATCH] Fixed issue #1318 - 'Access-Control-Allow-Origin' error when submitting web form. --- app/controllers/form_controller.rb | 11 ++++++----- config/routes/form.rb | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index ce52e72dd..9e1328748 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -5,7 +5,7 @@ class FormController < ApplicationController before_action :cors_preflight_check_execute after_action :set_access_control_headers_execute - def config + def configuration return if !enabled? return if !fingerprint_exists? return if limit_reached? @@ -16,17 +16,17 @@ class FormController < ApplicationController endpoint = "#{http_type}://#{fqdn}#{api_path}/form_submit" - config = { + result = { enabled: Setting.get('form_ticket_create'), endpoint: endpoint, token: token_gen(params[:fingerprint]) } if params[:test] && current_user && current_user.permissions?('admin.channel_formular') - config[:enabled] = true + result[:enabled] = true end - render json: config, status: :ok + render json: result, status: :ok end def submit @@ -127,11 +127,12 @@ class FormController < ApplicationController ) if params[:file] + params[:file].each { |file| Store.add( object: 'Ticket::Article', o_id: article.id, - data: File.read(file.tempfile), + data: file.read, filename: file.original_filename, preferences: { 'Mime-Type' => file.content_type, diff --git a/config/routes/form.rb b/config/routes/form.rb index b9c6974eb..fbe08b640 100644 --- a/config/routes/form.rb +++ b/config/routes/form.rb @@ -2,7 +2,7 @@ Zammad::Application.routes.draw do api_path = Rails.configuration.api_path # forms - match api_path + '/form_submit', to: 'form#submit', via: :post - match api_path + '/form_config', to: 'form#config', via: :post + match api_path + '/form_submit', to: 'form#submit', via: :post + match api_path + '/form_config', to: 'form#configuration', via: :post end