Browse Source

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

Rolf Schmidt 7 years ago
parent
commit
4573308f66
2 changed files with 8 additions and 7 deletions
  1. 6 5
      app/controllers/form_controller.rb
  2. 2 2
      config/routes/form.rb

+ 6 - 5
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,

+ 2 - 2
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