diff --git a/app/controllers/exports_controller.rb b/app/controllers/exports_controller.rb index 2f195ffd4..8a6d54800 100644 --- a/app/controllers/exports_controller.rb +++ b/app/controllers/exports_controller.rb @@ -43,6 +43,22 @@ def budgets end end + def level_b + authorize :export, :show_level_b? + + fund = Fund.new(params[:fund_id]) + + respond_to do |format| + format.csv do + export = Export::ActivityLevelBColumn.new(fund:) + + stream_csv_download(filename: export.filename, headers: export.headers) do |csv| + export.rows.each { |row| csv << row } + end + end + end + end + def spending_breakdown authorize :export, :show_external_income? diff --git a/app/models/export/activity_level_b_column.rb b/app/models/export/activity_level_b_column.rb new file mode 100644 index 000000000..954e8f450 --- /dev/null +++ b/app/models/export/activity_level_b_column.rb @@ -0,0 +1,58 @@ +class Export::ActivityLevelBColumn + HEADERS = [ + "Partner Organisation", + "Activity level", + "Parent activity", + "ODA or Non-ODA", + "Partner organisation identifier", + "RODA identifier", + "IATI identifier", + "Linked activity", + "Activity title", + "Activity description", + "Aims or objectives", + "Sector", + "Original commitment figure", + "Activity status", + "Planned start date", + "Planned end date", + "Actual start date", + "Actual end date", + "ISPF ODA partner countries", + "Benefitting countries", + "Benefitting region", + "Global Development Impact", + "Sustainable Development Goals", + "ISPF themes", + "Aid type", + "ODA eligibility", + "Publish to IATI?", + "Tags", + "Budget 2023-2024", + "Budget 2024-2025", + "Budget 2025-2026", + "Budget 2026-2027", + "Budget 2027-2028", + "Budget 2028-2029", + "Comments" + ].freeze + + def initialize(fund:) + @fund = fund + end + + def headers + HEADERS + end + + def filename + "LevelB_#{@fund.name.tr(" ", "_")}_#{Time.zone.now.strftime("%Y-%m-%d_%H-%M-%S")}.csv" + end + + def rows + [ + headers.map { "placeholder" }, + headers.map { "placeholder2" } + ] + end +end diff --git a/app/policies/export_policy.rb b/app/policies/export_policy.rb index e59dc4449..480b0a952 100644 --- a/app/policies/export_policy.rb +++ b/app/policies/export_policy.rb @@ -11,6 +11,10 @@ def show_budgets? user.service_owner? end + def show_level_b? + user.service_owner? + end + def show_spending_breakdown? user.service_owner? end diff --git a/app/views/exports/index.html.haml b/app/views/exports/index.html.haml index 0b5190610..421cf07fc 100644 --- a/app/views/exports/index.html.haml +++ b/app/views/exports/index.html.haml @@ -50,6 +50,28 @@ - else = a11y_action_link("Request", spending_breakdown_exports_path(fund_id: fund.id), t("table.export.spending_breakdown.name", fund: fund.name), ["govuk-link--no-visited-state"]) + %h1.govuk-heading-m + Level B exports + + %table.govuk-table + %thead.govuk-table__head + %tr.govuk-table__row + %th.govuk-table__header{scope: "col"} + Fund + %th.govuk-table__header{scope: "col"} + = t("table.export.header.format") + %th.govuk-table__header{scope: "col"} + = t("table.header.default.actions") + %tbody.govuk-table__body + - @funds.each do |fund| + %tr.govuk-table__row + %td.govuk-table__cell + = t("table.export.level_b.name", fund: fund.name) + %td.govuk-table__cell + CSV + %td.govuk-table__cell + = a11y_action_link("Download", level_b_exports_path(fund_id: fund.id, format: "csv"), t("table.export.level_b.name", fund: fund.name), ["govuk-link--no-visited-state"]) + %h1.govuk-heading-m Ad-hoc exports diff --git a/config/locales/views/exports.en.yml b/config/locales/views/exports.en.yml index ddfb525d1..10c769b0e 100644 --- a/config/locales/views/exports.en.yml +++ b/config/locales/views/exports.en.yml @@ -25,6 +25,8 @@ en: format: Format external_income: name: External income for %{fund} + level_b: + name: Level B activities for %{fund} budgets: name: Budgets for %{fund} spending_breakdown: diff --git a/config/routes.rb b/config/routes.rb index d69f9da33..e69221379 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -45,6 +45,7 @@ resources :exports, only: [:index] do get "external_income", on: :collection get "budgets", on: :collection + get "level_b", on: :collection get "spending_breakdown", on: :collection member do get "spending_breakdown_download" diff --git a/spec/controllers/exports_controller_spec.rb b/spec/controllers/exports_controller_spec.rb index 2961e00ba..27fde570c 100644 --- a/spec/controllers/exports_controller_spec.rb +++ b/spec/controllers/exports_controller_spec.rb @@ -93,6 +93,38 @@ end end + describe "#level_b" do + before do + get "level_b", params: {fund_id: fund.id, format: :csv} + end + + context "when logged in as a partner organisation user" do + let(:user) { create(:partner_organisation_user) } + + it "does not allow the user to access the download" do + expect(response).to have_http_status(:unauthorized) + end + end + + context "when logged in as a BEIS user" do + let(:user) { create(:beis_user) } + + it "responds with status 200 OK" do + expect(response).to have_http_status(:ok) + end + + it "sets the CSV headers correctly" do + expect(response.headers.to_h).to include({ + "Content-Type" => "text/csv" + }) + end + + it "returns a CSV of all of the exports" do + expect(CSV.parse(response.body.delete_prefix("\uFEFF")).first).to match_array(Export::ActivityLevelBColumn::HEADERS) + end + end + end + describe "#spending_breakdown" do render_views let(:user) { create(:beis_user) }