1 class ProjectsController < ApplicationController
6 def find_object_by_uuid
7 if current_user and params[:uuid] == current_user.uuid
8 @object = current_user.dup
9 @object.uuid = current_user.uuid
17 def attribute_editable? attr, *args
19 when 'description', 'name'
37 %w(Data_collections Jobs_and_pipelines Pipeline_templates Subprojects Other_objects Sharing Advanced)
39 %w(Data_collections Jobs_and_pipelines Pipeline_templates Subprojects Other_objects Advanced)
44 params[:item_uuids] = [params[:item_uuid]]
46 render template: 'projects/remove_items'
52 params[:item_uuids].collect { |uuid| ArvadosBase.find uuid }.each do |item|
53 if (item.class == Link and
54 item.link_class == 'name' and
55 item.tail_uuid == @object.uuid)
56 # Given uuid is a name link, linking an object to this
57 # project. First follow the link to find the item we're removing,
58 # then delete the link.
60 item = ArvadosBase.find item.head_uuid
62 # Given uuid is an object. Delete all names.
63 links += Link.where(tail_uuid: @object.uuid,
68 @removed_uuids << link.uuid
71 if item.owner_uuid == @object.uuid
72 # Object is owned by this project. Remove it from the project by
73 # changing owner to the current user.
74 item.update_attributes owner_uuid: current_user.uuid
75 @removed_uuids << item.uuid
81 target_uuid = params['target']
82 uuids_to_add = session[:selected_move_items]
85 collect { |x| ArvadosBase::resource_class_for_uuid(x) }.
87 each do |resource_class|
88 resource_class.filter([['uuid','in',uuids_to_add]]).each do |dst|
89 if resource_class == Collection
90 dst = Link.new(owner_uuid: target_uuid,
91 tail_uuid: target_uuid,
96 dst.owner_uuid = target_uuid
97 dst.tail_uuid = target_uuid if dst.class == Link
102 session[:selected_move_items] = nil
107 while (objects = Link.filter([['owner_uuid','=',@object.uuid],
108 ['tail_uuid','=',@object.uuid]])).any?
109 objects.each do |object|
113 while (objects = @object.contents(include_linked: false)).any?
114 objects.each do |object|
115 object.update_attributes! owner_uuid: current_user.uuid
118 if ArvadosBase::resource_class_for_uuid(@object.owner_uuid) == Group
119 params[:return_to] ||= group_path(@object.owner_uuid)
121 params[:return_to] ||= projects_path
126 def find_objects_for_index
127 @objects = all_projects
133 return render_not_found("object not found")
135 @objects = @object.contents(limit: 50,
136 include_linked: true,
137 filters: params[:filters],
138 offset: params[:offset] || 0)
139 @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]])
140 @users = User.limit(10000).
141 select(["uuid", "is_active", "first_name", "last_name"]).
142 filter([['is_active', '=', 'true']])
143 @groups = Group.limit(10000).
144 select(["uuid", "name", "description"])
146 @user_is_manager = false
148 if @object.uuid != current_user.uuid
150 @share_links = Link.permissions_for(@object)
151 @user_is_manager = true
152 rescue ArvadosApiClient::AccessForbiddenException,
153 ArvadosApiClient::NotFoundException
157 @objects_and_names = get_objects_and_names @objects
163 content: render_to_string(partial: 'show_contents_rows.html',
166 objects_and_names: @objects_and_names,
169 next_page_href: (next_page_offset and
170 url_for(offset: next_page_offset, filters: params[:filters], partial: true))
180 @new_resource_attrs = (params['project'] || {}).merge(group_class: 'project')
181 @new_resource_attrs[:name] ||= 'New project'
186 @updates = params['project']
190 helper_method :get_objects_and_names
191 def get_objects_and_names(objects)
192 objects_and_names = []
193 objects.each do |object|
194 if !(name_links = objects.links_for(object, 'name')).empty?
195 name_links.each do |name_link|
196 objects_and_names << [object, name_link]
198 elsif object.respond_to? :name
199 objects_and_names << [object, object]
201 objects_and_names << [object,
202 Link.new(owner_uuid: @object.uuid,
203 tail_uuid: @object.uuid,
204 head_uuid: object.uuid,
213 if not params[:uuids].andand.any?
214 @errors = ["No user/group UUIDs specified to share with."]
215 return render_error(status: 422)
217 results = {"success" => [], "errors" => []}
218 params[:uuids].each do |shared_uuid|
220 Link.create(tail_uuid: shared_uuid, link_class: "permission",
221 name: "can_read", head_uuid: @object.uuid)
222 rescue ArvadosApiClient::ApiError => error
223 error_list = error.api_response.andand[:errors]
224 if error_list.andand.any?
225 results["errors"] += error_list.map { |e| "#{shared_uuid}: #{e}" }
227 error_code = error.api_status || "Bad status"
228 results["errors"] << "#{shared_uuid}: #{error_code} response"
231 results["success"] << shared_uuid
234 if results["errors"].empty?
235 results.delete("errors")
241 f.json { render(json: results, status: status) }