3836: if there is a unique constraint violation when a collection is removed from...
authorradhika <radhika@curoverse.com>
Wed, 24 Sep 2014 14:15:22 +0000 (10:15 -0400)
committerradhika <radhika@curoverse.com>
Wed, 24 Sep 2014 14:15:22 +0000 (10:15 -0400)
which happens if there is already a collection with that same name in the Home project,
rename the collection to ensure the removal process can complete.

apps/workbench/app/controllers/projects_controller.rb

index 323f2a189a79fc514279337fa9a0ac666a5d94b8..2cbdcc90c846ac4c978467a3ff9dfde3313c1257 100644 (file)
@@ -127,8 +127,21 @@ class ProjectsController < ApplicationController
       if item.owner_uuid == @object.uuid
         # Object is owned by this project. Remove it from the project by
         # changing owner to the current user.
-        item.update_attributes owner_uuid: current_user.uuid
-        @removed_uuids << item.uuid
+        begin
+          item.update_attributes owner_uuid: current_user.uuid
+          @removed_uuids << item.uuid
+        rescue ArvadosApiClient::ApiErrorResponseException => e
+          if e.message.include? 'collection_owner_uuid_name_unique'
+            rename_to = item.name + ' removed from ' +
+                        (@object.name ? @object.name : @object.uuid) +
+                        ' at ' + Time.now.to_s
+            updates = {}
+            updates[:name] = rename_to
+            updates[:owner_uuid] = current_user.uuid
+            item.update_attributes updates
+            @removed_uuids << item.uuid
+          end
+        end
       end
     end
   end