Skip to content

Commit

Permalink
Merge pull request #9188 from alphagov/close-governments-transactionally
Browse files Browse the repository at this point in the history
Close government / update ministers transactionally
  • Loading branch information
richardTowers authored Jun 24, 2024
2 parents 61eb33b + ba37433 commit 0c8ed1e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/controllers/admin/governments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ def prepare_to_close
def close
government = Government.find(params[:id])

government.update!(end_date: Time.zone.today) unless government.end_date
ActiveRecord::Base.transaction do
government.update!(end_date: Time.zone.today) unless government.end_date

current_active_ministerial_appointments.each do |appointment|
appointment.ended_at = government.end_date
appointment.save!(validate: false)
current_active_ministerial_appointments.each do |appointment|
appointment.ended_at = government.end_date
appointment.save!(validate: false)
end
end

redirect_to edit_admin_government_path(government), notice: "Government closed"
Expand Down

0 comments on commit 0c8ed1e

Please sign in to comment.