Skip to content

Commit

Permalink
[#55021] project list export drops the id and identifier default
Browse files Browse the repository at this point in the history
From now on, if you want to export these columns, you must explicitly
select these in the view configuration before exporting. Your export
will always reflect the columns that you see in the web view.
  • Loading branch information
Tobias Dillmann committed Sep 11, 2024
1 parent 439e21b commit a8d365e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
9 changes: 1 addition & 8 deletions app/models/projects/exports/query_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class QueryExporter < Exports::Exporter
alias :query :object

def columns
@columns ||= (forced_columns + selected_columns)
@columns ||= selected_columns
end

def page
Expand All @@ -51,13 +51,6 @@ def projects

private

def forced_columns
[
{ name: :id, caption: Project.human_attribute_name(:id) },
{ name: :identifier, caption: Project.human_attribute_name(:identifier) }
]
end

def selected_columns
query
.selects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@

it "performs a successful export" do
expect(rows.count).to eq(1)
expect(sheet.row(1)).to eq [project.id.to_s, project.identifier,
project.name, project.description, "Off track", "false"]
expect(sheet.row(1)).to eq [project.name, project.description, "Off track", "false"]
end

context "with project description containing html" do
Expand All @@ -38,8 +37,7 @@

it "performs a successful export" do
expect(rows.count).to eq(1)
expect(sheet.row(1)).to eq [project.id.to_s, project.identifier, project.name,
"This is an html description.", "Off track", "false"]
expect(sheet.row(1)).to eq [project.name, "This is an html description.", "Off track", "false"]
end
end

Expand All @@ -48,12 +46,21 @@

it "performs a successful export" do
expect(rows.count).to eq(1)
expect(sheet.row(1)).to eq [project.id.to_s, project.identifier,
project.name, project.description,
expect(sheet.row(1)).to eq [project.name, project.description,
"Off track", project.status_explanation, "false"]
end
end

context "with id and identifier enabled" do
let(:query_columns) { %w[name description project_status public id identifier] }

it "performs a successful export" do
expect(rows.count).to eq(1)
expect(sheet.row(1)).to eq [project.name, project.description, "Off track",
"false", project.id.to_s, project.identifier]
end
end

describe "custom field columns selected" do
let(:query_columns) { %w[name description project_status public] + global_project_custom_fields.map(&:column_name) }

Expand All @@ -66,7 +73,7 @@

it "renders all those columns" do
cf_names = global_project_custom_fields.map(&:name)
expect(header).to eq ["ID", "Identifier", "Name", "Description", "Status", "Public", *cf_names]
expect(header).to eq ["Name", "Description", "Status", "Public", *cf_names]

expect(header).to include not_used_string_cf.name
expect(header).to include hidden_cf.name
Expand All @@ -85,8 +92,7 @@
end

expect(sheet.row(1))
.to eq [project.id.to_s, project.identifier, project.name, project.description, "Off track", "false",
*custom_values]
.to eq [project.name, project.description, "Off track", "false", *custom_values]

# The column for the project-level-disabled custom field is blank
expect(sheet.row(1)[header.index(not_used_string_cf.name)]).to be_nil
Expand All @@ -97,7 +103,7 @@
it "renders available project custom fields in the header if enabled in any project" do
cf_names = global_project_custom_fields.map(&:name)

expect(header).to eq ["ID", "Identifier", "Name", "Description", "Status", "Public", *cf_names]
expect(header).to eq ["Name", "Description", "Status", "Public", *cf_names]

expect(header).not_to include not_used_string_cf.name
expect(header).not_to include hidden_cf.name
Expand All @@ -116,19 +122,18 @@
end

expect(sheet.row(1))
.to eq [project.id.to_s, project.identifier, project.name, project.description, "Off track", "false",
*custom_values]
.to eq [project.name, project.description, "Off track", "false", *custom_values]
end
end

context "without view_project_attributes permission" do
let(:permissions) { %i(view_projects) }

it "does not render project custom fields in the header" do
expect(header).to eq ["ID", "Identifier", "Name", "Description", "Status", "Public"]
expect(header).to eq %w[Name Description Status Public]

expect(sheet.row(1))
.to eq [project.id.to_s, project.identifier, project.name, project.description, "Off track", "false"]
.to eq [project.name, project.description, "Off track", "false"]
end
end
end
Expand Down
31 changes: 18 additions & 13 deletions spec/models/projects/exporter/csv_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,29 @@

it "performs a successful export" do
expect(parsed.size).to eq(2)
expect(parsed.last).to eq [project.id.to_s, project.identifier,
project.name, project.description, "Off track", "false"]
expect(parsed.last).to eq [project.name, project.description, "Off track", "false"]
end

context "with status_explanation enabled" do
let(:query_columns) { %w[name description project_status status_explanation public] }

it "performs a successful export" do
expect(parsed.size).to eq(2)
expect(parsed.last).to eq [project.id.to_s, project.identifier,
project.name, project.description,
expect(parsed.last).to eq [project.name, project.description,
"Off track", "some explanation", "false"]
end
end

context "with id and identifier selected" do
let(:query_columns) { %w[name description id identifier project_status public] }

it "performs a successful export" do
expect(parsed.size).to eq(2)
expect(parsed.last).to eq [project.name, project.description, project.id.to_s,
project.identifier, "Off track", "false"]
end
end

describe "custom field columns selected" do
let(:query_columns) do
%w[name description project_status public] + global_project_custom_fields.map(&:column_name)
Expand All @@ -74,13 +82,12 @@
it "does not render project custom fields in the header" do
expect(parsed.size).to eq 2

expect(header).to eq ["\xEF\xBB\xBFid", "Identifier", "Name", "Description", "Status", "Public"]
expect(header).to eq ["\xEF\xBB\xBFName", "Description", "Status", "Public"]
end

it "does not render the custom field values in the rows if enabled for a project" do
expect(rows.first)
.to eq [project.id.to_s, project.identifier, project.name,
project.description, "Off track", "false"]
.to eq [project.name, project.description, "Off track", "false"]
end
end

Expand All @@ -93,7 +100,7 @@
expect(cf_names).not_to include(not_used_string_cf.name)
expect(cf_names).not_to include(hidden_cf.name)

expect(header).to eq ["\xEF\xBB\xBFid", "Identifier", "Name", "Description", "Status", "Public", *cf_names]
expect(header).to eq ["\xEF\xBB\xBFName", "Description", "Status", "Public", *cf_names]
end

it "renders the custom field values in the rows if enabled for a project" do
Expand All @@ -110,8 +117,7 @@
end
end
expect(rows.first)
.to eq [project.id.to_s, project.identifier, project.name,
project.description, "Off track", "false", *custom_values]
.to eq [project.name, project.description, "Off track", "false", *custom_values]
end
end

Expand All @@ -126,7 +132,7 @@
expect(cf_names).to include(not_used_string_cf.name)
expect(cf_names).to include(hidden_cf.name)

expect(header).to eq ["\xEF\xBB\xBFid", "Identifier", "Name", "Description", "Status", "Public", *cf_names]
expect(header).to eq ["\xEF\xBB\xBFName", "Description", "Status", "Public", *cf_names]
end

it "renders the custom field values in the rows if enabled for a project" do
Expand All @@ -145,8 +151,7 @@
end
end
expect(rows.first)
.to eq [project.id.to_s, project.identifier, project.name,
project.description, "Off track", "false", *custom_values]
.to eq [project.name, project.description, "Off track", "false", *custom_values]
end
end
end
Expand Down

0 comments on commit a8d365e

Please sign in to comment.