1 class ProjectsController < ApplicationController
12 %w(Data_collections Jobs_and_pipelines Pipeline_templates Subprojects Other_objects Sharing Advanced)
14 %w(Data_collections Jobs_and_pipelines Pipeline_templates Subprojects Other_objects Advanced)
19 params[:item_uuids] = [params[:item_uuid]]
21 render template: 'projects/remove_items'
27 params[:item_uuids].collect { |uuid| ArvadosBase.find uuid }.each do |item|
28 if (item.class == Link and
29 item.link_class == 'name' and
30 item.tail_uuid == @object.uuid)
31 # Given uuid is a name link, linking an object to this
32 # project. First follow the link to find the item we're removing,
33 # then delete the link.
35 item = ArvadosBase.find item.head_uuid
37 # Given uuid is an object. Delete all names.
38 links += Link.where(tail_uuid: @object.uuid,
43 @removed_uuids << link.uuid
46 if item.owner_uuid == @object.uuid
47 # Object is owned by this project. Remove it from the project by
48 # changing owner to the current user.
49 item.update_attributes owner_uuid: current_user.uuid
50 @removed_uuids << item.uuid
56 target_uuid = params['target']
57 uuids_to_add = session[:selected_move_items]
60 collect { |x| ArvadosBase::resource_class_for_uuid(x) }.
62 each do |resource_class|
63 resource_class.filter([['uuid','in',uuids_to_add]]).each do |dst|
64 if resource_class == Collection
65 dst = Link.new(owner_uuid: target_uuid,
66 tail_uuid: target_uuid,
71 dst.owner_uuid = target_uuid
72 dst.tail_uuid = target_uuid if dst.class == Link
77 session[:selected_move_items] = nil
82 while (objects = Link.filter([['owner_uuid','=',@object.uuid],
83 ['tail_uuid','=',@object.uuid]])).any?
84 objects.each do |object|
88 while (objects = @object.contents(include_linked: false)).any?
89 objects.each do |object|
90 object.update_attributes! owner_uuid: current_user.uuid
93 if ArvadosBase::resource_class_for_uuid(@object.owner_uuid) == Group
94 params[:return_to] ||= group_path(@object.owner_uuid)
96 params[:return_to] ||= projects_path
101 def find_objects_for_index
102 @objects = all_projects
108 return render_not_found("object not found")
110 @objects = @object.contents(limit: 50,
111 include_linked: true,
112 filters: params[:filters],
113 offset: params[:offset] || 0)
114 @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]])
115 @users = User.limit(10000).
116 select(["uuid", "is_active", "first_name", "last_name"]).
117 filter([['is_active', '=', 'true']])
118 @groups = Group.limit(10000).
119 select(["uuid", "name", "description"])
122 @share_links = Link.permissions_for(@object)
123 @user_is_manager = true
124 rescue ArvadosApiClient::AccessForbiddenException,
125 ArvadosApiClient::NotFoundException
127 @user_is_manager = false
130 @objects_and_names = get_objects_and_names @objects
136 content: render_to_string(partial: 'show_contents_rows.html',
139 objects_and_names: @objects_and_names,
142 next_page_href: (next_page_offset and
143 url_for(offset: next_page_offset, filters: params[:filters], partial: true))
153 @new_resource_attrs = (params['project'] || {}).merge(group_class: 'project')
154 @new_resource_attrs[:name] ||= 'New project'
159 @updates = params['project']
163 helper_method :get_objects_and_names
164 def get_objects_and_names(objects)
165 objects_and_names = []
166 objects.each do |object|
167 if !(name_links = objects.links_for(object, 'name')).empty?
168 name_links.each do |name_link|
169 objects_and_names << [object, name_link]
171 elsif object.respond_to? :name
172 objects_and_names << [object, object]
174 objects_and_names << [object,
175 Link.new(owner_uuid: @object.uuid,
176 tail_uuid: @object.uuid,
177 head_uuid: object.uuid,
186 if not params[:uuids].andand.any?
187 @errors = ["No user/group UUIDs specified to share with."]
188 return render_error(status: 422)
190 results = {"success" => [], "errors" => []}
191 params[:uuids].each do |shared_uuid|
193 Link.create(tail_uuid: shared_uuid, link_class: "permission",
194 name: "can_read", head_uuid: @object.uuid)
195 rescue ArvadosApiClient::ApiError => error
196 error_list = error.api_response.andand[:errors]
197 if error_list.andand.any?
198 results["errors"] += error_list.map { |e| "#{shared_uuid}: #{e}" }
200 error_code = error.api_status || "Bad status"
201 results["errors"] << "#{shared_uuid}: #{error_code} response"
204 results["success"] << shared_uuid
207 if results["errors"].empty?
208 results.delete("errors")
214 f.json { render(json: results, status: status) }