Fixed issue #1318 - 'Access-Control-Allow-Origin' error when submitting web form.

This commit is contained in:
Rolf Schmidt 2017-09-05 16:54:22 +02:00
parent ce2ed08e1b
commit 4573308f66
2 changed files with 8 additions and 7 deletions

View file

@ -5,7 +5,7 @@ class FormController < ApplicationController
before_action :cors_preflight_check_execute before_action :cors_preflight_check_execute
after_action :set_access_control_headers_execute after_action :set_access_control_headers_execute
def config def configuration
return if !enabled? return if !enabled?
return if !fingerprint_exists? return if !fingerprint_exists?
return if limit_reached? return if limit_reached?
@ -16,17 +16,17 @@ class FormController < ApplicationController
endpoint = "#{http_type}://#{fqdn}#{api_path}/form_submit" endpoint = "#{http_type}://#{fqdn}#{api_path}/form_submit"
config = { result = {
enabled: Setting.get('form_ticket_create'), enabled: Setting.get('form_ticket_create'),
endpoint: endpoint, endpoint: endpoint,
token: token_gen(params[:fingerprint]) token: token_gen(params[:fingerprint])
} }
if params[:test] && current_user && current_user.permissions?('admin.channel_formular') if params[:test] && current_user && current_user.permissions?('admin.channel_formular')
config[:enabled] = true result[:enabled] = true
end end
render json: config, status: :ok render json: result, status: :ok
end end
def submit def submit
@ -127,11 +127,12 @@ class FormController < ApplicationController
) )
if params[:file] if params[:file]
params[:file].each { |file| params[:file].each { |file|
Store.add( Store.add(
object: 'Ticket::Article', object: 'Ticket::Article',
o_id: article.id, o_id: article.id,
data: File.read(file.tempfile), data: file.read,
filename: file.original_filename, filename: file.original_filename,
preferences: { preferences: {
'Mime-Type' => file.content_type, 'Mime-Type' => file.content_type,

View file

@ -3,6 +3,6 @@ Zammad::Application.routes.draw do
# forms # forms
match api_path + '/form_submit', to: 'form#submit', via: :post match api_path + '/form_submit', to: 'form#submit', via: :post
match api_path + '/form_config', to: 'form#config', via: :post match api_path + '/form_config', to: 'form#configuration', via: :post
end end