Merge branch 'master' of git.curoverse.com:arvados into 2638-add-cache-age-disk-usage...
[arvados.git] / apps / workbench / app / controllers / folders_controller.rb
index 0a7f0f9e1e7cf063c4ee46a4f673ee9d8eb3db44..86ee42b10db54ecd389254d2470c210bc30c64e1 100644 (file)
@@ -8,7 +8,33 @@ class FoldersController < ApplicationController
   end
 
   def remove_item
-    raise "Not implemented yet!"
+    @removed_uuids = []
+    links = []
+    item = ArvadosBase.find params[:item_uuid]
+    if (item.class == Link and
+        item.link_class == 'name' and
+        item.tail_uuid = @object.uuid)
+      # Given uuid is a name link, linking an object to this
+      # folder. First follow the link to find the item we're removing,
+      # then delete the link.
+      links << item
+      item = ArvadosBase.find item.head_uuid
+    else
+      # Given uuid is an object. Delete all names.
+      links += Link.where(tail_uuid: @object.uuid,
+                          head_uuid: item.uuid,
+                          link_class: 'name')
+    end
+    links.each do |link|
+      @removed_uuids << link.uuid
+      link.destroy
+    end
+    if item.owner_uuid == @object.uuid
+      # Object is owned by this folder. Remove it from the folder by
+      # changing owner to the current user.
+      item.update_attributes owner_uuid: current_user
+      @removed_uuids << item.uuid
+    end
   end
 
   def index
@@ -39,7 +65,6 @@ class FoldersController < ApplicationController
         @shared_with_me << folder
       end
     end
-    @object
   end
 
   def show
@@ -68,6 +93,7 @@ class FoldersController < ApplicationController
 
   def create
     @new_resource_attrs = (params['folder'] || {}).merge(group_class: 'folder')
+    @new_resource_attrs[:name] ||= 'New folder'
     super
   end
 end