From f7bd2dfceb3c8945046aea33c5a303235b967232 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 17 Aug 2017 13:48:55 +0200 Subject: [PATCH] Imporoved zendesk reload feature at import time. Improved url validation. --- app/assets/javascripts/app/controllers/import_zendesk.coffee | 2 +- app/controllers/import_zendesk_controller.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/app/controllers/import_zendesk.coffee b/app/assets/javascripts/app/controllers/import_zendesk.coffee index ee12e9177..a4856e235 100644 --- a/app/assets/javascripts/app/controllers/import_zendesk.coffee +++ b/app/assets/javascripts/app/controllers/import_zendesk.coffee @@ -117,7 +117,7 @@ class Index extends App.ControllerContent e.preventDefault() @urlStatus.attr('data-state', '') url = @zendeskUrl.val() + '/agent/admin/api' - @zendeskUrlApiToken.attr('href', url.replace(/[^:]\/\//, '/')) + @zendeskUrlApiToken.attr('href', url.replace(/([^:])\/\/+/g, '$1/')) @zendeskUrlApiToken.val('HERE') @$('[data-slide=zendesk-url]').toggleClass('hide') @$('[data-slide=zendesk-credentials]').toggleClass('hide') diff --git a/app/controllers/import_zendesk_controller.rb b/app/controllers/import_zendesk_controller.rb index f762c2321..cd64441b9 100644 --- a/app/controllers/import_zendesk_controller.rb +++ b/app/controllers/import_zendesk_controller.rb @@ -7,7 +7,7 @@ class ImportZendeskController < ApplicationController return if setup_done_response # validate - if !params[:url] || params[:url] !~ %r{^(http|https)://.+?$} + if params[:url].blank? || params[:url] !~ %r{^(http|https)://.+?$} render json: { result: 'invalid', message: 'Invalid URL!', @@ -50,7 +50,7 @@ class ImportZendeskController < ApplicationController end endpoint = "#{params[:url]}/api/v2" - endpoint.gsub(%r{[^:]//}, '/') + endpoint.gsub!(%r{([^:])//+}, '\\1/') Setting.set('import_zendesk_endpoint', endpoint) render json: { @@ -94,6 +94,7 @@ class ImportZendeskController < ApplicationController def import_start return if setup_done_response Setting.set('import_mode', true) + Setting.set('import_backend', 'zendesk') # start migration Import::Zendesk.delay.start_bg