aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-06-01 20:44:11 +0100
committerChristopher Baines <mail@cbaines.net>2018-06-01 20:44:11 +0100
commit7829d53c854e2ba6eb574d6f994204fb0b4bb869 (patch)
treecef479168a314bd1d12613c361264bb37f9fbee1 /app
parent9953ee2af581fc676a7ea7d308b691186aea6638 (diff)
downloadgovuk-mini-environment-admin-7829d53c854e2ba6eb574d6f994204fb0b4bb869.tar
govuk-mini-environment-admin-7829d53c854e2ba6eb574d6f994204fb0b4bb869.tar.gz
Rework the services method in the MiniEnvironmentController
Bring the transaction inside of the request.put? conditional, as it shouldn't have been outside to begin with. Also, store the data snapshot if one is selected.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/mini_environments_controller.rb40
1 files changed, 25 insertions, 15 deletions
diff --git a/app/controllers/mini_environments_controller.rb b/app/controllers/mini_environments_controller.rb
index 0cee75b..05cf558 100644
--- a/app/controllers/mini_environments_controller.rb
+++ b/app/controllers/mini_environments_controller.rb
@@ -101,28 +101,38 @@ class MiniEnvironmentsController < ApplicationController
def services
@mini_environment = MiniEnvironment.find(params[:id])
- @mini_environment.transaction do
- @mini_environment.govuk_guix_revision.all_available_services
- .each do |service|
+ if request.put?
+ @mini_environment.transaction do
+ @mini_environment.govuk_guix_revision.all_available_services
+ .each do |service|
+
+ name = service['name']
+
+ next if params["#{name}-selected"] != 'on'
- name = service['name']
+ revision = params["#{name}-revision"]
- next if params["#{name}-selected"] != 'on'
+ @mini_environment.services.where(
+ name: name
+ ).delete_all
- revision = params["#{name}-revision"]
+ @mini_environment.services.create(
+ name: name,
+ revision: revision
+ )
+ end
- @mini_environment.services.where(
- name: name
- ).delete_all
+ data_snapshot_id = params.fetch(:data_snapshot, nil)
- @mini_environment.services.create(
- name: name,
- revision: revision
- )
+ if data_snapshot_id
+ # TODO: Validate that this is on the list of approved snapshots
+
+ @mini_environment.update!(
+ data_snapshot_id: data_snapshot_id
+ )
+ end
end
- end
- if request.put?
@mini_environment.backend.build(@mini_environment)
redirect_to @mini_environment
end