X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/d02c4efcfdbe8f21fba895749988b14b7db41310..e1d71c83e17ba6d06e2442ed775f7efd4ea32d84:/apps/workbench/app/controllers/folders_controller.rb diff --git a/apps/workbench/app/controllers/folders_controller.rb b/apps/workbench/app/controllers/folders_controller.rb index 43b6f407b8..86ee42b10d 100644 --- a/apps/workbench/app/controllers/folders_controller.rb +++ b/apps/workbench/app/controllers/folders_controller.rb @@ -7,6 +7,36 @@ class FoldersController < ApplicationController %w(My_folders Shared_with_me) end + def remove_item + @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 @my_folders = [] @shared_with_me = [] @@ -42,11 +72,28 @@ class FoldersController < ApplicationController @share_links = Link.filter([['head_uuid', '=', @object.uuid], ['link_class', '=', 'permission']]) @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]]) + + @objects_and_names = [] + @objects.each do |object| + if !(name_links = @objects.links_for(object, 'name')).empty? + name_links.each do |name_link| + @objects_and_names << [object, name_link] + end + else + @objects_and_names << [object, + Link.new(tail_uuid: @object.uuid, + head_uuid: object.uuid, + link_class: "name", + name: "")] + end + end + super end def create @new_resource_attrs = (params['folder'] || {}).merge(group_class: 'folder') + @new_resource_attrs[:name] ||= 'New folder' super end end