Commit 4074cb3b authored by James Edwards-Jones's avatar James Edwards-Jones

Fixed filter by label for issues CSV export

parent 31bde06d
...@@ -81,7 +81,7 @@ module IssuableCollections ...@@ -81,7 +81,7 @@ module IssuableCollections
# @filter_params[:authorized_only] = true # @filter_params[:authorized_only] = true
end end
@filter_params @filter_params.permit(IssuableFinder::VALID_PARAMS)
end end
def set_default_scope def set_default_scope
......
...@@ -146,8 +146,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -146,8 +146,7 @@ class Projects::IssuesController < Projects::ApplicationController
end end
def export_csv def export_csv
csv_params = filter_params.permit(IssuableFinder::VALID_PARAMS) ExportCsvWorker.perform_async(@current_user.id, @project.id, filter_params)
ExportCsvWorker.perform_async(@current_user.id, @project.id, csv_params)
index_path = namespace_project_issues_path(@project.namespace, @project) index_path = namespace_project_issues_path(@project.namespace, @project)
redirect_to(index_path, notice: "Your CSV export has started. It will be emailed to #{current_user.notification_email} when complete.") redirect_to(index_path, notice: "Your CSV export has started. It will be emailed to #{current_user.notification_email} when complete.")
......
...@@ -20,7 +20,10 @@ ...@@ -20,7 +20,10 @@
# #
class IssuableFinder class IssuableFinder
NONE = '0'.freeze NONE = '0'.freeze
VALID_PARAMS = %i(scope state group_id project_id milestone_title assignee_id search label_name sort assignee_username author_id author_username authorized_only due_date iids non_archived weight).freeze
SCALAR_PARAMS = %i(scope state group_id project_id milestone_title assignee_id search label_name sort assignee_username author_id author_username authorized_only due_date iids non_archived weight).freeze
ARRAY_PARAMS = { label_name: [], iids: [] }.freeze
VALID_PARAMS = (SCALAR_PARAMS + [ARRAY_PARAMS]).freeze
attr_accessor :current_user, :params attr_accessor :current_user, :params
......
...@@ -17,4 +17,4 @@ ...@@ -17,4 +17,4 @@
%strong= @current_user.notification_email %strong= @current_user.notification_email
in an attachment. in an attachment.
.modal-footer .modal-footer
= link_to 'Export issues', export_csv_namespace_project_issues_path(@project.namespace, @project, params.permit(IssuableFinder::VALID_PARAMS)), method: :post, class: 'btn btn-success pull-left', title: 'Export issues' = link_to 'Export issues', export_csv_namespace_project_issues_path(@project.namespace, @project, request.query_parameters), method: :post, class: 'btn btn-success pull-left', title: 'Export issues'
...@@ -63,6 +63,14 @@ describe 'Issues csv', feature: true do ...@@ -63,6 +63,14 @@ describe 'Issues csv', feature: true do
expect(csv.count).to eq 0 expect(csv.count).to eq 0
end end
it 'uses array filters, such as label_name' do
issue.update!(labels: [idea_label])
request_csv("label_name[]" => 'Bug')
expect(csv.count).to eq 0
end
it 'avoids excessive database calls' do it 'avoids excessive database calls' do
control_count = ActiveRecord::QueryRecorder.new{ request_csv }.count control_count = ActiveRecord::QueryRecorder.new{ request_csv }.count
create_list(:labeled_issue, create_list(:labeled_issue,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment