diff options
author | Christopher Baines <mail@cbaines.net> | 2019-05-27 20:56:32 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2019-05-30 08:33:03 +0100 |
commit | 1acde9a21a50f4227930afb5b6b9eda1cace54b8 (patch) | |
tree | 65684552ab89c4b65abb9088092da1b1d7b7e15d | |
parent | 040d50d46d699c18133fbe5bd8c88623890244a6 (diff) | |
download | govuk-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.rb | 8 | ||||
-rw-r--r-- | app/controllers/backends/terraform_libvirt_controller.rb | 8 |
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 |