]> source.dussan.org Git - redmine.git/commitdiff
Exporting UserQuery does not use the query name as file name (#37674, #38182).
authorGo MAEDA <maeda@farend.jp>
Wed, 1 Mar 2023 08:47:28 +0000 (08:47 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 1 Mar 2023 08:47:28 +0000 (08:47 +0000)
Patch by Takenori TAKAKI.

git-svn-id: https://svn.redmine.org/redmine/trunk@22121 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/users_controller.rb
test/functional/users_controller_test.rb

index a6cad6b2f07c85a03093cd0a9191453dc89d8183..77ec1a6013289724bc59e2711e2dfb4c4d729adc 100644 (file)
@@ -61,7 +61,7 @@ class UsersController < ApplicationController
         format.csv do
           # Export all entries
           @entries = scope.to_a
-          send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'users.csv')
+          send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => "#{filename_for_export(@query, 'users')}.csv")
         end
         format.api do
           @offset, @limit = api_offset_and_limit
index ccb40ce4cd331c887ed972d51aa1a9df33517dfc..e452371ff7e095e6e45f08a89f9259ce23ef3821 100644 (file)
@@ -280,6 +280,19 @@ class UsersControllerTest < Redmine::ControllerTest
     assert_equal 'text/csv; header=present', @response.media_type
   end
 
+  def test_index_csv_filename_without_query_id_param
+    get :index, :params => {:format => 'csv'}
+    assert_response :success
+    assert_match /users.csv/, @response.headers['Content-Disposition']
+  end
+
+  def test_index_csv_filename_with_query_id_param
+    query = UserQuery.create!(:name => 'My Query Name', :visibility => UserQuery::VISIBILITY_PUBLIC)
+    get :index, :params => {:query_id => query.id, :format => 'csv'}
+    assert_response :success
+    assert_match /my_query_name\.csv/, @response.headers['Content-Disposition']
+  end
+
   def test_show
     @request.session[:user_id] = nil
     get :show, :params => {:id => 2}