1 class ProjectsController < ApplicationController
2 before_filter :set_share_links, if: -> { defined? @object }
3 skip_around_filter :require_thread_api_token, if: proc { |ctrl|
4 Rails.configuration.anonymous_user_token and
5 %w(show tab_counts).include? ctrl.action_name
12 def find_object_by_uuid
13 if current_user and params[:uuid] == current_user.uuid
14 @object = current_user.dup
15 @object.uuid = current_user.uuid
23 def attribute_editable? attr, *args
25 when 'description', 'name'
41 # Returning an array of hashes instead of an array of strings will allow
42 # us to tell the interface to get counts for each pane (using :filters).
43 # It also seems to me that something like these could be used to configure the contents of the panes.
46 if @object.uuid != current_user.andand.uuid
47 pane_list << 'Description'
51 :name => 'Data_collections',
52 :filters => [%w(uuid is_a arvados#collection)]
56 :name => 'Jobs_and_pipelines',
57 :filters => [%w(uuid is_a) + [%w(arvados#job arvados#pipelineInstance)]]
61 :name => 'Pipeline_templates',
62 :filters => [%w(uuid is_a arvados#pipelineTemplate)]
66 :name => 'Subprojects',
67 :filters => [%w(uuid is_a arvados#group)]
71 :name => 'Other_objects',
72 :filters => [%w(uuid is_a) + [%w(arvados#human arvados#specimen arvados#trait)]]
74 pane_list << { :name => 'Sharing',
75 :count => @share_links.count } if @user_is_manager
76 pane_list << { :name => 'Advanced' }
79 # Called via AJAX and returns Javascript that populates tab counts into tab titles.
80 # References #show_pane_list action which should return an array of hashes each with :name
81 # and then optionally a :filters to run or a straight up :count
83 # This action could easily be moved to the ApplicationController to genericize the tab_counts behaviour,
84 # but one or more new routes would have to be created, the js.erb would also have to be moved
87 show_pane_list.each do |pane|
90 @tab_counts[pane[:name]] = pane[:count]
92 @tab_counts[pane[:name]] = @object.contents(filters: pane[:filters]).items_available
99 params[:item_uuids] = [params[:item_uuid]]
101 render template: 'projects/remove_items'
107 params[:item_uuids].collect { |uuid| ArvadosBase.find uuid }.each do |item|
108 if (item.class == Link and
109 item.link_class == 'name' and
110 item.tail_uuid == @object.uuid)
111 # Given uuid is a name link, linking an object to this
112 # project. First follow the link to find the item we're removing,
113 # then delete the link.
115 item = ArvadosBase.find item.head_uuid
117 # Given uuid is an object. Delete all names.
118 links += Link.where(tail_uuid: @object.uuid,
119 head_uuid: item.uuid,
123 @removed_uuids << link.uuid
127 # If this object has the 'expires_at' attribute, then simply mark it
129 if item.attributes.include?("expires_at")
130 item.update_attributes expires_at: Time.now
131 @removed_uuids << item.uuid
132 elsif item.owner_uuid == @object.uuid
133 # Object is owned by this project. Remove it from the project by
134 # changing owner to the current user.
136 item.update_attributes owner_uuid: current_user.uuid
137 @removed_uuids << item.uuid
138 rescue ArvadosApiClient::ApiErrorResponseException => e
139 if e.message.include? 'collection_owner_uuid_name_unique'
140 rename_to = item.name + ' removed from ' +
141 (@object.name ? @object.name : @object.uuid) +
142 ' at ' + Time.now.to_s
144 updates[:name] = rename_to
145 updates[:owner_uuid] = current_user.uuid
146 item.update_attributes updates
147 @removed_uuids << item.uuid
157 while (objects = Link.filter([['owner_uuid','=',@object.uuid],
158 ['tail_uuid','=',@object.uuid]])).any?
159 objects.each do |object|
163 while (objects = @object.contents).any?
164 objects.each do |object|
165 object.update_attributes! owner_uuid: current_user.uuid
168 if ArvadosBase::resource_class_for_uuid(@object.owner_uuid) == Group
169 params[:return_to] ||= group_path(@object.owner_uuid)
171 params[:return_to] ||= projects_path
176 def find_objects_for_index
177 @objects = all_projects
181 def load_contents_objects kinds=[]
182 kind_filters = @filters.select do |attr,op,val|
183 op == 'is_a' and val.is_a? Array and val.count > 1
185 if /^created_at\b/ =~ @order[0] and kind_filters.count == 1
186 # If filtering on multiple types and sorting by date: Get the
187 # first page of each type, sort the entire set, truncate to one
188 # page, and use the last item on this page as a filter for
189 # retrieving the next page. Ideally the API would do this for
190 # us, but it doesn't (yet).
192 # To avoid losing items that have the same created_at as the
193 # last item on this page, we retrieve an overlapping page with a
194 # "created_at <= last_created_at" filter, then remove duplicates
195 # with a "uuid not in [...]" filter (see below).
196 nextpage_operator = /\bdesc$/i =~ @order[0] ? '<=' : '>='
200 kind_filters.each do |attr,op,val|
201 (val.is_a?(Array) ? val : [val]).each do |type|
202 objects = @object.contents(order: @order,
204 filters: (@filters - kind_filters + [['uuid', 'is_a', type]]),
206 objects.each do |object|
207 @name_link_for[object.andand.uuid] = objects.links_for(object, 'name').first
212 @objects = @objects.to_a.sort_by(&:created_at)
213 @objects.reverse! if nextpage_operator == '<='
214 @objects = @objects[0..@limit-1]
215 @next_page_filters = @filters.reject do |attr,op,val|
216 (attr == 'created_at' and op == nextpage_operator) or
217 (attr == 'uuid' and op == 'not in')
221 last_created_at = @objects.last.created_at
224 @objects.each do |obj|
225 last_uuids << obj.uuid if obj.created_at.eql?(last_created_at)
228 @next_page_filters += [['created_at',
231 @next_page_filters += [['uuid', 'not in', last_uuids]]
232 @next_page_href = url_for(partial: :contents_rows,
234 filters: @next_page_filters.to_json)
236 @next_page_href = nil
239 @objects = @object.contents(order: @order,
243 @next_page_href = next_page_href(partial: :contents_rows,
244 filters: @filters.to_json,
245 order: @order.to_json)
248 preload_links_for_objects(@objects.to_a)
253 return render_not_found("object not found")
257 load_contents_objects
261 content: render_to_string(partial: 'show_contents_rows.html',
263 next_page_href: @next_page_href
274 @new_resource_attrs = (params['project'] || {}).merge(group_class: 'project')
275 @new_resource_attrs[:name] ||= 'New project'
280 @updates = params['project']
284 helper_method :get_objects_and_names
285 def get_objects_and_names(objects=nil)
286 objects = @objects if objects.nil?
287 objects_and_names = []
288 objects.each do |object|
289 if objects.respond_to? :links_for and
290 !(name_links = objects.links_for(object, 'name')).empty?
291 name_links.each do |name_link|
292 objects_and_names << [object, name_link]
294 elsif @name_link_for.andand[object.uuid]
295 objects_and_names << [object, @name_link_for[object.uuid]]
296 elsif object.respond_to? :name
297 objects_and_names << [object, object]
299 objects_and_names << [object,
300 Link.new(owner_uuid: @object.uuid,
301 tail_uuid: @object.uuid,
302 head_uuid: object.uuid,