Skip to content

Commit

Permalink
Add functionality to delete retired apps
Browse files Browse the repository at this point in the history
Retired apps are being flagged in the Out of sync release
alert and there is no way to remove them in the Release app.

This commit allows an app to have the option of being deleted on
the Edit page. There is a popup confirmation dialog when the delete
button is pressed to ensure it is not removed by mistake.
  • Loading branch information
deborahchua committed Jul 26, 2024
1 parent 23b63ed commit 1bce3cf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//= require_tree .
//= require govuk_publishing_components/dependencies
//= require govuk_publishing_components/all_components

//= require rails-ujs
7 changes: 6 additions & 1 deletion app/controllers/applications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ApplicationsController < ApplicationController
before_action :find_application, only: %i[show edit update deploy stats]
before_action :find_application, only: %i[show edit update deploy stats destroy]

include ActionView::Helpers::DateHelper

Expand Down Expand Up @@ -74,6 +74,11 @@ def update
end
end

def destroy
@application.destroy!
redirect_to applications_path, notice: "Successfully deleted application"
end

private

def find_application
Expand Down
12 changes: 12 additions & 0 deletions app/views/applications/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,17 @@

<%= render "govuk_publishing_components/components/button", {
text: @application.new_record? ? "Create Application" : "Update application",
margin_bottom: 4,
} %>
<% end %>

<% unless current_page?(action: 'new') %>
<%= form_for @application, method: :delete do |f| %>
<%= render "govuk_publishing_components/components/button", {
text: "Delete application",
destructive: true,
data_attributes: { confirm: "Are you sure you wish to delete this application?" },
info_text: "You can remove this app if it is retired.",
} %>
<% end %>
<% end %>
18 changes: 18 additions & 0 deletions test/functional/applications_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,24 @@ class ApplicationsControllerTest < ActionController::TestCase
end
end

context "POST destroy" do
setup do
stub_request(:get, Repo::REPO_JSON_URL).to_return(status: 200)
@app = FactoryBot.create(:application)
end

should "delete the application" do
assert_difference "Application.count", -1 do
post :destroy, params: { id: @app.id }
end
end

should "redirect to the index page" do
post :destroy, params: { id: @app.id }
assert_redirected_to applications_path
end
end

private

def random_sha
Expand Down

0 comments on commit 1bce3cf

Please sign in to comment.