aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-05-27 20:56:32 +0100
committerChristopher Baines <mail@cbaines.net>2019-05-30 08:33:03 +0100
commit1acde9a21a50f4227930afb5b6b9eda1cace54b8 (patch)
tree65684552ab89c4b65abb9088092da1b1d7b7e15d
parent040d50d46d699c18133fbe5bd8c88623890244a6 (diff)
downloadgovuk-mini-environment-admin-1acde9a21a50f4227930afb5b6b9eda1cace54b8.tar
govuk-mini-environment-admin-1acde9a21a50f4227930afb5b6b9eda1cace54b8.tar.gz
Guard against deleting backends in the controller
-rw-r--r--app/controllers/backends/terraform_aws_controller.rb8
-rw-r--r--app/controllers/backends/terraform_libvirt_controller.rb8
2 files changed, 12 insertions, 4 deletions
diff --git a/app/controllers/backends/terraform_aws_controller.rb b/app/controllers/backends/terraform_aws_controller.rb
index b09001d..3902679 100644
--- a/app/controllers/backends/terraform_aws_controller.rb
+++ b/app/controllers/backends/terraform_aws_controller.rb
@@ -49,8 +49,12 @@ class Backends::TerraformAwsController < ApplicationController
def destroy
backend = Backends::TerraformAws.find(params[:id])
- flash[:success] = "Backend #{backend.label} deleted"
- backend.delete
+ if backend.mini_environments.empty?
+ flash[:success] = "Backend #{backend.label} deleted"
+ backend.delete
+ else
+ flash[:error] = "Unable to delete backend, as mini environments using this backend still exist."
+ end
redirect_to setup_path
end
diff --git a/app/controllers/backends/terraform_libvirt_controller.rb b/app/controllers/backends/terraform_libvirt_controller.rb
index 1bf37cd..159fbb1 100644
--- a/app/controllers/backends/terraform_libvirt_controller.rb
+++ b/app/controllers/backends/terraform_libvirt_controller.rb
@@ -51,8 +51,12 @@ class Backends::TerraformLibvirtController < ApplicationController
def destroy
backend = Backends::TerraformLibvirt.find(params['id'])
- flash[:success] = "Backend #{backend.label} deleted"
- backend.delete
+ if backend.mini_environments.empty?
+ flash[:success] = "Backend #{backend.label} deleted"
+ backend.delete
+ else
+ flash[:error] = "Unable to delete backend, as mini environments using this backend still exist."
+ end
redirect_to setup_path
end