aboutsummaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-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