remove /download from csv file url

This commit is contained in:
Arpit Jalan 2014-11-19 22:39:23 +05:30
parent a211f542f5
commit aebf36c356
4 changed files with 10 additions and 9 deletions

View file

@ -1,6 +1,6 @@
class Admin::ExportCsvController < Admin::AdminController class Admin::ExportCsvController < Admin::AdminController
skip_before_filter :check_xhr, only: [:download] skip_before_filter :check_xhr, only: [:show]
def export_user_list def export_user_list
# export csv file in a background thread # export csv file in a background thread
@ -8,7 +8,8 @@ class Admin::ExportCsvController < Admin::AdminController
render json: success_json render json: success_json
end end
def download # download
def show
filename = params.fetch(:id) filename = params.fetch(:id)
if export_csv_path = ExportCsv.get_download_path(filename) if export_csv_path = ExportCsv.get_download_path(filename)
send_file export_csv_path send_file export_csv_path

View file

@ -108,7 +108,7 @@ module Jobs
def notify_user def notify_user
if @current_user if @current_user
if @file_name != "" && File.exists?("#{ExportCsv.base_directory}/#{@file_name}") 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 else
SystemMessage.create_from_system_user(@current_user, :csv_export_failed) SystemMessage.create_from_system_user(@current_user, :csv_export_failed)
end end

View file

@ -156,12 +156,12 @@ Discourse::Application.routes.draw do
end end
resources :export_csv, constraints: AdminConstraint.new do resources :export_csv, constraints: AdminConstraint.new do
member do
get "download" => "export_csv#download", constraints: { id: /[^\/]+/ }
end
collection do collection do
get "users" => "export_csv#export_user_list" get "users" => "export_csv#export_user_list"
end end
member do
get "" => "export_csv#show", constraints: { id: /[^\/]+/ }
end
end end
resources :badges, constraints: AdminConstraint.new do resources :badges, constraints: AdminConstraint.new do

View file

@ -19,12 +19,12 @@ describe Admin::ExportCsvController do
export = ExportCsv.new() export = ExportCsv.new()
ExportCsv.expects(:get_download_path).with(export_filename).returns(export) ExportCsv.expects(:get_download_path).with(export_filename).returns(export)
subject.expects(:send_file).with(export) subject.expects(:send_file).with(export)
get :download, id: export_filename get :show, id: export_filename
end end
it "returns 404 when the export file does not exist" do it "returns 404 when the export file does not exist" do
ExportCsv.expects(:get_download_path).returns(nil) ExportCsv.expects(:get_download_path).returns(nil)
get :download, id: export_filename get :show, id: export_filename
response.should be_not_found response.should be_not_found
end end