1 class FoldersController < ApplicationController
11 %w(Contents Permissions)
17 item = ArvadosBase.find params[:item_uuid]
18 if (item.class == Link and
19 item.link_class == 'name' and
20 item.tail_uuid = @object.uuid)
21 # Given uuid is a name link, linking an object to this
22 # folder. First follow the link to find the item we're removing,
23 # then delete the link.
25 item = ArvadosBase.find item.head_uuid
27 # Given uuid is an object. Delete all names.
28 links += Link.where(tail_uuid: @object.uuid,
33 @removed_uuids << link.uuid
36 if item.owner_uuid == @object.uuid
37 # Object is owned by this folder. Remove it from the folder by
38 # changing owner to the current user.
39 item.update_attributes owner_uuid: current_user
40 @removed_uuids << item.uuid
45 @objects = Group.where(group_class: 'folder').order('name')
46 parent_of = {current_user.uuid => 'me'}
48 parent_of[ob.uuid] = ob.owner_uuid
50 children_of = {false => [], 'me' => [current_user]}
52 if ob.owner_uuid != current_user.uuid and
53 not parent_of.has_key? ob.owner_uuid
54 parent_of[ob.uuid] = false
56 children_of[parent_of[ob.uuid]] ||= []
57 children_of[parent_of[ob.uuid]] << ob
59 buildtree = lambda do |children_of, root_uuid=false|
61 children_of[root_uuid].andand.each do |ob|
62 tree[ob] = buildtree.call(children_of, ob.uuid)
66 sorted_paths = lambda do |tree, depth=0|
68 tree.keys.sort_by { |ob|
69 ob.is_a?(String) ? ob : ob.friendly_link_name
71 paths << {object: ob, depth: depth}
72 paths += sorted_paths.call tree[ob], depth+1
77 sorted_paths.call buildtree.call(children_of, 'me')
79 sorted_paths.call({'Shared with me' =>
80 buildtree.call(children_of, false)})
84 @objects = @object.contents include_linked: true
85 @share_links = Link.filter([['head_uuid', '=', @object.uuid],
86 ['link_class', '=', 'permission']])
87 @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]])
89 @objects_and_names = []
90 @objects.each do |object|
91 if !(name_links = @objects.links_for(object, 'name')).empty?
92 name_links.each do |name_link|
93 @objects_and_names << [object, name_link]
96 @objects_and_names << [object,
97 Link.new(tail_uuid: @object.uuid,
98 head_uuid: object.uuid,
108 @new_resource_attrs = (params['folder'] || {}).merge(group_class: 'folder')
109 @new_resource_attrs[:name] ||= 'New folder'
114 @updates = params['folder']