From aebf36c356b3128044de6f426f1b4153e240a8f4 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 19 Nov 2014 22:39:23 +0530 Subject: [PATCH] remove /download from csv file url --- app/controllers/admin/export_csv_controller.rb | 5 +++-- app/jobs/regular/export_csv_file.rb | 4 ++-- config/routes.rb | 6 +++--- spec/controllers/admin/export_csv_controller_spec.rb | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/export_csv_controller.rb b/app/controllers/admin/export_csv_controller.rb index f0e574105a9..82fec5d09e4 100644 --- a/app/controllers/admin/export_csv_controller.rb +++ b/app/controllers/admin/export_csv_controller.rb @@ -1,6 +1,6 @@ class Admin::ExportCsvController < Admin::AdminController - skip_before_filter :check_xhr, only: [:download] + skip_before_filter :check_xhr, only: [:show] def export_user_list # export csv file in a background thread @@ -8,7 +8,8 @@ class Admin::ExportCsvController < Admin::AdminController render json: success_json end - def download + # download + def show filename = params.fetch(:id) if export_csv_path = ExportCsv.get_download_path(filename) send_file export_csv_path diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rb index 2bd8a29894f..79f9ea38a6d 100644 --- a/app/jobs/regular/export_csv_file.rb +++ b/app/jobs/regular/export_csv_file.rb @@ -6,7 +6,7 @@ module Jobs class ExportCsvFile < Jobs::Base CSV_USER_ATTRS = ['id','name','username','email','title','created_at','trust_level','active','admin','moderator','ip_address'] CSV_USER_STATS = ['topics_entered','posts_read_count','time_read','topic_count','post_count','likes_given','likes_received'] - + sidekiq_options retry: false attr_accessor :current_user @@ -108,7 +108,7 @@ module Jobs def notify_user if @current_user if @file_name != "" && File.exists?("#{ExportCsv.base_directory}/#{@file_name}") - SystemMessage.create_from_system_user(@current_user, :csv_export_succeeded, download_link: "#{Discourse.base_url}/admin/export_csv/#{@file_name}/download", file_name: @file_name) + SystemMessage.create_from_system_user(@current_user, :csv_export_succeeded, download_link: "#{Discourse.base_url}/admin/export_csv/#{@file_name}", file_name: @file_name) else SystemMessage.create_from_system_user(@current_user, :csv_export_failed) end diff --git a/config/routes.rb b/config/routes.rb index f33712d4bb7..abcb00680e8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -156,12 +156,12 @@ Discourse::Application.routes.draw do end resources :export_csv, constraints: AdminConstraint.new do - member do - get "download" => "export_csv#download", constraints: { id: /[^\/]+/ } - end collection do get "users" => "export_csv#export_user_list" end + member do + get "" => "export_csv#show", constraints: { id: /[^\/]+/ } + end end resources :badges, constraints: AdminConstraint.new do diff --git a/spec/controllers/admin/export_csv_controller_spec.rb b/spec/controllers/admin/export_csv_controller_spec.rb index cbf037e4ccb..644deb6d900 100644 --- a/spec/controllers/admin/export_csv_controller_spec.rb +++ b/spec/controllers/admin/export_csv_controller_spec.rb @@ -19,12 +19,12 @@ describe Admin::ExportCsvController do export = ExportCsv.new() ExportCsv.expects(:get_download_path).with(export_filename).returns(export) subject.expects(:send_file).with(export) - get :download, id: export_filename + get :show, id: export_filename end it "returns 404 when the export file does not exist" do ExportCsv.expects(:get_download_path).returns(nil) - get :download, id: export_filename + get :show, id: export_filename response.should be_not_found end