Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rgarner committed Jan 9, 2025
1 parent 62b9dc8 commit 673e14b
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/controllers/exports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
58 changes: 58 additions & 0 deletions app/models/export/activity_level_b_column.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions app/policies/export_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions app/views/exports/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions config/locales/views/exports.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 32 additions & 0 deletions spec/controllers/exports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit 673e14b

Please sign in to comment.