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 dst.name += " (#{Time.now.localtime})" if dst.respond_to? :name=
82 session[:selected_move_items] = nil
87 while (objects = Link.filter([['owner_uuid','=',@object.uuid],
88 ['tail_uuid','=',@object.uuid]])).any?
89 objects.each do |object|
93 while (objects = @object.contents(include_linked: false)).any?
94 objects.each do |object|
95 object.update_attributes! owner_uuid: current_user.uuid
98 if ArvadosBase::resource_class_for_uuid(@object.owner_uuid) == Group
99 params[:return_to] ||= group_path(@object.owner_uuid)
101 params[:return_to] ||= projects_path
106 def find_objects_for_index
107 @objects = all_projects
113 return render_not_found("object not found")
115 @objects = @object.contents(limit: 50,
116 include_linked: true,
117 filters: params[:filters],
118 offset: params[:offset] || 0)
119 @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]])
120 @users = User.limit(10000).
121 select(["uuid", "is_active", "first_name", "last_name"]).
122 filter([['is_active', '=', 'true']])
123 @groups = Group.limit(10000).
124 select(["uuid", "name", "description"])
127 @share_links = Link.permissions_for(@object)
128 @user_is_manager = true
129 rescue ArvadosApiClient::AccessForbiddenException,
130 ArvadosApiClient::NotFoundException
132 @user_is_manager = false
135 @objects_and_names = get_objects_and_names @objects
141 content: render_to_string(partial: 'show_contents_rows.html',
144 objects_and_names: @objects_and_names,
147 next_page_href: (next_page_offset and
148 url_for(offset: next_page_offset, filters: params[:filters], partial: true))
158 @new_resource_attrs = (params['project'] || {}).merge(group_class: 'project')
159 @new_resource_attrs[:name] ||= 'New project'
164 @updates = params['project']
168 helper_method :get_objects_and_names
169 def get_objects_and_names(objects)
170 objects_and_names = []
171 objects.each do |object|
172 if !(name_links = objects.links_for(object, 'name')).empty?
173 name_links.each do |name_link|
174 objects_and_names << [object, name_link]
176 elsif object.respond_to? :name
177 objects_and_names << [object, object]
179 objects_and_names << [object,
180 Link.new(owner_uuid: @object.uuid,
181 tail_uuid: @object.uuid,
182 head_uuid: object.uuid,
191 if not params[:uuids].andand.any?
192 @errors = ["No user/group UUIDs specified to share with."]
193 return render_error(status: 422)
195 results = {"success" => [], "errors" => []}
196 params[:uuids].each do |shared_uuid|
198 Link.create(tail_uuid: shared_uuid, link_class: "permission",
199 name: "can_read", head_uuid: @object.uuid)
200 rescue ArvadosApiClient::ApiError => error
201 error_list = error.api_response.andand[:errors]
202 if error_list.andand.any?
203 results["errors"] += error_list.map { |e| "#{shared_uuid}: #{e}" }
205 error_code = error.api_status || "Bad status"
206 results["errors"] << "#{shared_uuid}: #{error_code} response"
209 results["success"] << shared_uuid
212 if results["errors"].empty?
213 results.delete("errors")
219 f.json { render(json: results, status: status) }