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 while (objects = Link.filter([['owner_uuid','=',@object.uuid],
57 ['tail_uuid','=',@object.uuid]])).any?
58 objects.each do |object|
62 while (objects = @object.contents(include_linked: false)).any?
63 objects.each do |object|
64 object.update_attributes! owner_uuid: current_user.uuid
67 if ArvadosBase::resource_class_for_uuid(@object.owner_uuid) == Group
68 params[:return_to] ||= group_path(@object.owner_uuid)
70 params[:return_to] ||= projects_path
75 def find_objects_for_index
76 @objects = all_projects
82 return render_not_found("object not found")
84 @objects = @object.contents(limit: 50,
86 filters: params[:filters],
87 offset: params[:offset] || 0)
88 @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]])
89 @users = User.limit(10000).
90 select(["uuid", "is_active", "first_name", "last_name"]).
91 filter([['is_active', '=', 'true']])
92 @groups = Group.limit(10000).
93 select(["uuid", "name", "description"])
96 @share_links = Link.permissions_for(@object)
97 @user_is_manager = true
98 rescue ArvadosApiClient::AccessForbiddenException,
99 ArvadosApiClient::NotFoundException
101 @user_is_manager = false
104 @objects_and_names = get_objects_and_names @objects
110 content: render_to_string(partial: 'show_contents_rows.html',
113 objects_and_names: @objects_and_names,
116 next_page_href: (next_page_offset and
117 url_for(offset: next_page_offset, filters: params[:filters], partial: true))
127 @new_resource_attrs = (params['project'] || {}).merge(group_class: 'project')
128 @new_resource_attrs[:name] ||= 'New project'
133 @updates = params['project']
137 helper_method :get_objects_and_names
138 def get_objects_and_names(objects)
139 objects_and_names = []
140 objects.each do |object|
141 if !(name_links = objects.links_for(object, 'name')).empty?
142 name_links.each do |name_link|
143 objects_and_names << [object, name_link]
145 elsif object.respond_to? :name
146 objects_and_names << [object, object]
148 objects_and_names << [object,
149 Link.new(owner_uuid: @object.uuid,
150 tail_uuid: @object.uuid,
151 head_uuid: object.uuid,
160 if not params[:uuids].andand.any?
161 @errors = ["No user/group UUIDs specified to share with."]
162 return render_error(status: 422)
164 results = {"success" => [], "errors" => []}
165 params[:uuids].each do |shared_uuid|
167 Link.create(tail_uuid: shared_uuid, link_class: "permission",
168 name: "can_read", head_uuid: @object.uuid)
169 rescue ArvadosApiClient::ApiError => error
170 error_list = error.api_response.andand[:errors]
171 if error_list.andand.any?
172 results["errors"] += error_list.map { |e| "#{shared_uuid}: #{e}" }
174 error_code = error.api_status || "Bad status"
175 results["errors"] << "#{shared_uuid}: #{error_code} response"
178 results["success"] << shared_uuid
181 if results["errors"].empty?
182 results.delete("errors")
188 f.json { render(json: results, status: status) }