19144: Resets storage_classes_confirmed* fields on WB1 copy action.
[arvados.git] / apps / workbench / app / controllers / container_requests_controller.rb
index c42e93375bb5aeaf5b64a3f02a515609074c5301..be463b022cc6ed013ab652fba16140daf4e2d08d 100644 (file)
@@ -127,14 +127,12 @@ class ContainerRequestsController < ApplicationController
         @updates[:reuse_steps] = false
       end
       @updates[:command] ||= @object.command
+      @updates[:command] -= ["--disable-reuse", "--enable-reuse"]
       if @updates[:reuse_steps]
-        @updates[:command] = @updates[:command] - ["--disable-reuse"]
-        @updates[:command].insert(1, '--enable-reuse')
+        @updates[:command].insert(1, "--enable-reuse")
       else
-        @updates[:command] -= @updates[:command] - ["--enable-reuse"]
-        @updates[:command].insert(1, '--disable-reuse')
+        @updates[:command].insert(1, "--disable-reuse")
       end
-
       @updates.delete(:reuse_steps)
     end
 
@@ -152,7 +150,7 @@ class ContainerRequestsController < ApplicationController
     @object = ContainerRequest.new
 
     # set owner_uuid to that of source, provided it is a project and writable by current user
-    if params[:work_unit][:owner_uuid]
+    if params[:work_unit].andand[:owner_uuid]
       @object.owner_uuid = src.owner_uuid = params[:work_unit][:owner_uuid]
     else
       current_project = Group.find(src.owner_uuid) rescue nil
@@ -161,32 +159,37 @@ class ContainerRequestsController < ApplicationController
       end
     end
 
-    if src.command[0] == 'arvados-cwl-runner'
+    command = src.command
+    if command[0] == 'arvados-cwl-runner'
       command.each_with_index do |arg, i|
         if arg.start_with? "--project-uuid="
           command[i] = "--project-uuid=#{@object.owner_uuid}"
         end
-        if arg == "--disable-reuse"
-          command[i] = "--enable-reuse"
-        end
       end
+      command -= ["--disable-reuse", "--enable-reuse"]
+      command.insert(1, '--enable-reuse')
     end
 
-    # By default the copied CR won't be reusing containers, unless use_existing=true
-    # param is passed.
-    command = src.command
-    if params[:use_existing]
-      @object.use_existing = true
+    if params[:use_existing] == "false"
+      params[:use_existing] = false
+    elsif params[:use_existing] == "true"
+      params[:use_existing] = true
+    end
+
+    if params[:use_existing] || params[:use_existing].nil?
+      # If nil, reuse workflow steps but not the workflow runner.
+      @object.use_existing = !!params[:use_existing]
+
       # Pass the correct argument to arvados-cwl-runner command.
-      if src.command[0] == 'arvados-cwl-runner'
-        command = src.command - ['--disable-reuse']
+      if command[0] == 'arvados-cwl-runner'
+        command -= ["--disable-reuse", "--enable-reuse"]
         command.insert(1, '--enable-reuse')
       end
     else
       @object.use_existing = false
       # Pass the correct argument to arvados-cwl-runner command.
-      if src.command[0] == 'arvados-cwl-runner'
-        command = src.command - ['--enable-reuse']
+      if command[0] == 'arvados-cwl-runner'
+        command -= ["--disable-reuse", "--enable-reuse"]
         command.insert(1, '--disable-reuse')
       end
     end