1 class ProjectsController < ApplicationController
11 %w(Contents Permissions Advanced)
15 params[:item_uuids] = [params[:item_uuid]]
17 render template: 'projects/remove_items'
23 params[:item_uuids].collect { |uuid| ArvadosBase.find uuid }.each do |item|
24 if (item.class == Link and
25 item.link_class == 'name' and
26 item.tail_uuid == @object.uuid)
27 # Given uuid is a name link, linking an object to this
28 # project. First follow the link to find the item we're removing,
29 # then delete the link.
31 item = ArvadosBase.find item.head_uuid
33 # Given uuid is an object. Delete all names.
34 links += Link.where(tail_uuid: @object.uuid,
39 @removed_uuids << link.uuid
42 if item.owner_uuid == @object.uuid
43 # Object is owned by this project. Remove it from the project by
44 # changing owner to the current user.
45 item.update_attributes owner_uuid: current_user.uuid
46 @removed_uuids << item.uuid
51 def find_objects_for_index
53 filter([['group_class','in',['project','folder']]]).
56 parent_of = {current_user.uuid => 'me'}
58 parent_of[ob.uuid] = ob.owner_uuid
60 children_of = {false => [], 'me' => [current_user]}
62 if ob.owner_uuid != current_user.uuid and
63 not parent_of.has_key? ob.owner_uuid
64 parent_of[ob.uuid] = false
66 children_of[parent_of[ob.uuid]] ||= []
67 children_of[parent_of[ob.uuid]] << ob
69 buildtree = lambda do |children_of, root_uuid=false|
71 children_of[root_uuid].andand.each do |ob|
72 tree[ob] = buildtree.call(children_of, ob.uuid)
76 sorted_paths = lambda do |tree, depth=0|
78 tree.keys.sort_by { |ob|
79 ob.is_a?(String) ? ob : ob.friendly_link_name
81 paths << {object: ob, depth: depth}
82 paths += sorted_paths.call tree[ob], depth+1
87 sorted_paths.call buildtree.call(children_of, 'me')
88 @shared_project_tree =
89 sorted_paths.call({'Shared with me' =>
90 buildtree.call(children_of, false)})
95 return render_not_found("object not found")
97 @objects = @object.contents(limit: 50,
99 offset: params[:offset] || 0)
100 @share_links = Link.filter([['head_uuid', '=', @object.uuid],
101 ['link_class', '=', 'permission']])
102 @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]])
104 @objects_and_names = []
105 @objects.each do |object|
106 if !(name_links = @objects.links_for(object, 'name')).empty?
107 name_links.each do |name_link|
108 @objects_and_names << [object, name_link]
110 elsif object.respond_to? :name
111 @objects_and_names << [object, object]
113 @objects_and_names << [object,
114 Link.new(owner_uuid: @object.uuid,
115 tail_uuid: @object.uuid,
116 head_uuid: object.uuid,
125 content: render_to_string(partial: 'show_contents_rows.html',
128 objects_and_names: @objects_and_names,
131 next_page_href: (next_page_offset and
132 url_for(offset: next_page_offset, partial: true))
142 @new_resource_attrs = (params['project'] || {}).merge(group_class: 'project')
143 @new_resource_attrs[:name] ||= 'New project'
148 @updates = params['project']