+ if item.class == Collection or item.class == Group or item.class == Workflow or item.class == ContainerRequest
+ # Use delete API on collections and projects/groups
+ item.destroy
+ @removed_uuids << item.uuid
+ elsif item.owner_uuid == @object.uuid
+ # Object is owned by this project. Remove it from the project by
+ # changing owner to the current user.
+ begin
+ item.update owner_uuid: current_user.uuid
+ @removed_uuids << item.uuid
+ rescue ArvadosApiClient::ApiErrorResponseException => e
+ if e.message.include? '_owner_uuid_'
+ 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 updates
+ @removed_uuids << item.uuid
+ else
+ raise
+ end
+ end
+ end