Skip to content

Commit

Permalink
Add rake task to mark an organisation as closed
Browse files Browse the repository at this point in the history
The `OrganisationFetcher` does not handle the situation of an
organisation having been deleted in Whitehall without first being
closed.

This means a deleted organisation remains marked as open, and can have
users assigned to it in Signon.

Adding a rake task to manually mark organisations as closed, in the
event this occurs again, so the organisation no longer appears as an
option to which users can be assigned in the user interface.
  • Loading branch information
brucebolt committed Jan 21, 2025
1 parent 3496cce commit ce21dae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/tasks/data_hygiene.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ namespace :data_hygiene do
abort "bulk updating organisations encountered errors"
end
end

desc "Mark an organisation as closed"
task :close_organisation, %i[content_id] => :environment do |_, args|
organisation = Organisation.find_by(content_id: args[:content_id])
organisation.update!(closed: true)
puts "Marked organisation #{organisation.slug} as closed"
end
end
19 changes: 19 additions & 0 deletions test/lib/tasks/data_hygiene_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "test_helper"

class DataHygieneTaskTest < ActiveSupport::TestCase
setup do
Signon::Application.load_tasks if Rake::Task.tasks.empty?

$stdout.stubs(:write)
end

context "#close_organisation" do
should "mark the organisation as closed" do
organisation = create(:organisation, slug: "department-of-health", closed: false)

Rake::Task["data_hygiene:close_organisation"].invoke(organisation.content_id)

assert organisation.reload.closed?
end
end
end

0 comments on commit ce21dae

Please sign in to comment.