Browse Source

Add delete button

pull/2459/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
15a3e7ba49
  1. 2
      app/controllers/organisations_controller.rb
  2. 4
      app/helpers/organisations_helper.rb
  3. 8
      app/policies/organisation_policy.rb
  4. 4
      app/views/organisations/show.html.erb
  5. 41
      spec/requests/organisations_controller_spec.rb

2
app/controllers/organisations_controller.rb

@ -153,6 +153,8 @@ class OrganisationsController < ApplicationController
end end
def delete def delete
authorize @organisation
@organisation.discard! @organisation.discard!
redirect_to organisations_path, notice: I18n.t("notification.organisation_deleted", name: @organisation.name) redirect_to organisations_path, notice: I18n.t("notification.organisation_deleted", name: @organisation.name)
end end

4
app/helpers/organisations_helper.rb

@ -44,4 +44,8 @@ module OrganisationsHelper
result[period_code] = period_value.merge(checked: checked_periods.nil? || checked_periods.include?(period_code)) result[period_code] = period_value.merge(checked: checked_periods.nil? || checked_periods.include?(period_code))
end end
end end
def delete_organisation_link(organisation)
govuk_button_link_to "Delete this organisation", delete_confirmation_organisation_path(organisation), warning: true
end
end end

8
app/policies/organisation_policy.rb

@ -13,4 +13,12 @@ class OrganisationPolicy
def reactivate? def reactivate?
user.support? && organisation.status == :deactivated user.support? && organisation.status == :deactivated
end end
def delete_confirmation?
delete?
end
def delete?
user.support? && (organisation.status == :deactivated || organisation.status == :merged)
end
end end

4
app/views/organisations/show.html.erb

@ -52,3 +52,7 @@
<%= govuk_button_link_to "Reactivate this organisation", reactivate_organisation_path(@organisation) %> <%= govuk_button_link_to "Reactivate this organisation", reactivate_organisation_path(@organisation) %>
</span> </span>
<% end %> <% end %>
<% if OrganisationPolicy.new(current_user, @organisation).delete? %>
<%= delete_organisation_link(@organisation) %>
<% end %>

41
spec/requests/organisations_controller_spec.rb

@ -1523,6 +1523,45 @@ RSpec.describe OrganisationsController, type: :request do
end end
end end
describe "#show" do
let(:organisation) { create(:organisation) }
before do
get "/organisations/#{organisation.id}", headers:, params: {}
end
context "with an active organisation" do
it "does not render delete this organisation" do
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).not_to have_link("Delete this organisation", href: "/organisations/#{organisation.id}/delete-confirmation")
end
end
context "with an inactive organisation" do
let(:organisation) { create(:organisation, active: false) }
it "renders delete this organisation" do
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_link("Delete this organisation", href: "/organisations/#{organisation.id}/delete-confirmation")
end
end
context "with merged organisation" do
before do
organisation.update!(merge_date: Time.zone.yesterday)
get "/organisations/#{organisation.id}", headers:, params: {}
end
it "renders delete this organisation" do
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_link("Delete this organisation", href: "/organisations/#{organisation.id}/delete-confirmation")
end
end
end
describe "#update" do describe "#update" do
let(:params) { { id: organisation.id, organisation: { active:, rent_periods: [], all_rent_periods: [] } } } let(:params) { { id: organisation.id, organisation: { active:, rent_periods: [], all_rent_periods: [] } } }
@ -1709,7 +1748,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
describe "#delete" do describe "#delete" do
let(:organisation) { create(:organisation) } let(:organisation) { create(:organisation, active: false) }
before do before do
delete "/organisations/#{organisation.id}/delete" delete "/organisations/#{organisation.id}/delete"

Loading…
Cancel
Save