Browse Source
* Add questions to page, wip * Add select as conditional question in radio like in logs * Add existing value * Add blank default * Add values to about this organisation page * Move grabbing values out of view * Update new org page with js * Selecting the profit status dependent on the provider type * Add to org edit page for support users * Add group logic * Fix bug on existing orgs when group remains unchanged * Clear group details if no longer part of a group * Lint * JS Lint * Restore schema * Remove manual_address_selected * Revert "Remove manual_address_selected" This reverts commitpull/3091/merge812787fd09
. * Revert "Revert "Remove manual_address_selected"" This reverts commit8ebd56036f
. * Update migration * Remove file * Move update after save * Move methods to controller * Update xml export * Lint * Update test xml file * Update current user logic * Lint * Lint * Reorder org js controller * Lint * Add tests to helper * Some tests on the organisation pages * Fix label text for profit status question in forms * Add CSV task to update organisation profit status and group member fields * only associate group on update if validation passes * Update import raketask to use provided csv looking into it I couldn't see a use for skip_group_member_validation. it temporarily disables validation but since it's not saved to database it'll make the organisation invalid in the future opted instead to make all properties valid when importing * Update tests to check more cases of organisation import * Make XML tests check unordered file contents stops tests flakily failing on the order of cols which is not important in xml * Fix final failing tests * restore manual_address_selected migration * fix it's to its * show the user the group they originally selected if possible when editing group else fallback to any (oldest) org in the group * update csv for ingest --------- Co-authored-by: Manny Dinssa <44172848+Dinssa@users.noreply.github.com>
25 changed files with 1445 additions and 44 deletions
@ -0,0 +1,27 @@
|
||||
import { Controller } from '@hotwired/stimulus' |
||||
|
||||
export default class extends Controller { |
||||
updateProfitStatusOptions (event) { |
||||
const profitStatusSelect = document.getElementById('organisation-profit-status-field') |
||||
if (!profitStatusSelect) return |
||||
|
||||
const localAuthorityOption = profitStatusSelect.querySelector('option[value="local_authority"]') |
||||
const nonProfitOption = profitStatusSelect.querySelector('option[value="non_profit"]') |
||||
const profitOption = profitStatusSelect.querySelector('option[value="profit"]') |
||||
const providerType = event.target.value |
||||
|
||||
profitStatusSelect.disabled = false |
||||
localAuthorityOption.hidden = false |
||||
nonProfitOption.hidden = false |
||||
profitOption.hidden = false |
||||
|
||||
if (providerType === 'LA') { |
||||
profitStatusSelect.value = 'local_authority' |
||||
nonProfitOption.hidden = true |
||||
profitOption.hidden = true |
||||
} else if (providerType === 'PRP') { |
||||
profitStatusSelect.value = '' |
||||
localAuthorityOption.hidden = true |
||||
} |
||||
} |
||||
} |
|
@ -0,0 +1,10 @@
|
||||
class AddNewQuestionFieldsToOrganisation < ActiveRecord::Migration[7.2] |
||||
def change |
||||
change_table :organisations, bulk: true do |t| |
||||
t.integer :profit_status |
||||
t.boolean :group_member |
||||
t.integer :group_member_id |
||||
t.integer :group |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,45 @@
|
||||
namespace :data_update do |
||||
desc "Update organisations with data from a CSV file" |
||||
task :update_organisations, [:csv_path] => :environment do |_task, args| |
||||
require "csv" |
||||
|
||||
csv_path = args[:csv_path] |
||||
unless csv_path |
||||
Rails.logger.error "Please provide the path to the CSV file. Example: rake data_update:update_organisations[csv_path]" |
||||
exit |
||||
end |
||||
|
||||
CSV.foreach(csv_path, headers: true) do |row| |
||||
organisation = Organisation.find_by(id: row["id"].to_i) |
||||
if organisation |
||||
organisation.update!( |
||||
profit_status: map_profit_status(row["profit_status"]), |
||||
) |
||||
# not all orgs have a group |
||||
if row["group"].present? |
||||
organisation.update!( |
||||
group_member: true, |
||||
group: row["group"].to_i, |
||||
# normally set to the ID of the other organisation you picked on the group form |
||||
# we can't set that here so we default to its own org ID |
||||
group_member_id: organisation.id, |
||||
) |
||||
end |
||||
|
||||
Rails.logger.info "Updated ORG#{row['id']}" |
||||
else |
||||
Rails.logger.warn "Organisation with ID #{row['id']} not found" |
||||
end |
||||
end |
||||
|
||||
Rails.logger.info "Organisation update task completed" |
||||
end |
||||
end |
||||
|
||||
def map_profit_status(profit_status) |
||||
return :non_profit if profit_status == "Non-profit" |
||||
return :profit if profit_status == "Profit" |
||||
return :local_authority if profit_status == "Local authority" |
||||
|
||||
nil |
||||
end |
|
|
@ -0,0 +1,63 @@
|
||||
require "rails_helper" |
||||
require "rake" |
||||
|
||||
RSpec.describe "data_update:update_organisations", type: :task do |
||||
let(:task) { Rake::Task["data_update:update_organisations"] } |
||||
|
||||
before do |
||||
Rake.application.rake_require("tasks/update_organisations_group_profit_status") |
||||
Rake::Task.define_task(:environment) |
||||
task.reenable |
||||
end |
||||
|
||||
context "when the CSV file is valid" do |
||||
let!(:organisation_la) { create(:organisation, id: 234, provider_type: "LA") } |
||||
let!(:organisation_prp_non_profit) { create(:organisation, id: 750, provider_type: "PRP") } |
||||
let!(:organisation_prp_profit) { create(:organisation, id: 642, provider_type: "PRP") } |
||||
let(:csv_path) { Rails.root.join("spec/fixtures/files/organisations_group_profit_status_valid.csv") } |
||||
|
||||
it "updates an organisation profit status field" do |
||||
expect { |
||||
task.invoke(csv_path.to_s) |
||||
} |
||||
.to change { organisation_la.reload.profit_status }.to("local_authority") |
||||
.and change { organisation_prp_non_profit.reload.profit_status }.to("non_profit") |
||||
.and change { organisation_prp_profit.reload.profit_status }.to("profit") |
||||
end |
||||
|
||||
it "updates an organisation group fields" do |
||||
task.invoke(csv_path.to_s) |
||||
organisation_la.reload |
||||
organisation_prp_non_profit.reload |
||||
organisation_prp_profit.reload |
||||
|
||||
expect(organisation_la.group).to eq(2) |
||||
expect(organisation_la.group_member).to be_truthy |
||||
expect(organisation_la.group_member_id).to eq(organisation_la.id) |
||||
|
||||
expect(organisation_prp_non_profit.group).to eq(2) |
||||
expect(organisation_prp_non_profit.group_member).to be_truthy |
||||
expect(organisation_prp_non_profit.group_member_id).to eq(organisation_prp_non_profit.id) |
||||
|
||||
expect(organisation_prp_profit.group).to be_nil |
||||
expect(organisation_prp_profit.group_member).to be_falsy |
||||
expect(organisation_prp_profit.group_member_id).to be_nil |
||||
end |
||||
end |
||||
|
||||
context "when the organisation is not found" do |
||||
let(:csv_path) { Rails.root.join("spec/fixtures/files/organisations_group_profit_status_invalid.csv") } |
||||
|
||||
it "logs a warning" do |
||||
expect(Rails.logger).to receive(:warn).with("Organisation with ID 2000 not found") |
||||
task.invoke(csv_path.to_s) |
||||
end |
||||
end |
||||
|
||||
context "when the CSV path is not provided" do |
||||
it "logs an error and exits" do |
||||
expect(Rails.logger).to receive(:error).with("Please provide the path to the CSV file. Example: rake data_update:update_organisations[csv_path]") |
||||
expect { task.invoke }.to raise_error(SystemExit) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue