1 class ProjectsController < ApplicationController
2 before_filter :set_share_links, if: -> { defined? @object and @object}
3 skip_around_filter :require_thread_api_token, if: proc { |ctrl|
4 Rails.configuration.anonymous_user_token and
5 %w(show tab_counts public).include? ctrl.action_name
12 def find_object_by_uuid
13 if (current_user and params[:uuid] == current_user.uuid) or
14 (resource_class_for_uuid(params[:uuid]) == User)
15 if params[:uuid] != current_user.uuid
16 @object = User.find(params[:uuid])
18 @object = current_user.dup
19 @object.uuid = current_user.uuid
24 if current_user.uuid == self.uuid
27 "Home for #{self.email}"
33 def attribute_editable? attr, *args
35 when 'description', 'name'
51 # Returning an array of hashes instead of an array of strings will allow
52 # us to tell the interface to get counts for each pane (using :filters).
53 # It also seems to me that something like these could be used to configure the contents of the panes.
56 if @object.uuid != current_user.andand.uuid
57 pane_list << 'Description'
61 :name => 'Data_collections',
62 :filters => [%w(uuid is_a arvados#collection)]
66 :name => 'Jobs_and_pipelines',
67 :filters => [%w(uuid is_a) + [%w(arvados#job arvados#pipelineInstance)]]
71 :name => 'Pipeline_templates',
72 :filters => [%w(uuid is_a arvados#pipelineTemplate)]
76 :name => 'Subprojects',
77 :filters => [%w(uuid is_a arvados#group)]
81 :name => 'Other_objects',
82 :filters => [%w(uuid is_a) + [%w(arvados#human arvados#specimen arvados#trait)]]
84 pane_list << { :name => 'Sharing',
85 :count => @share_links.count } if @user_is_manager
86 pane_list << { :name => 'Advanced' }
89 # Called via AJAX and returns Javascript that populates tab counts into tab titles.
90 # References #show_pane_list action which should return an array of hashes each with :name
91 # and then optionally a :filters to run or a straight up :count
93 # This action could easily be moved to the ApplicationController to genericize the tab_counts behaviour,
94 # but one or more new routes would have to be created, the js.erb would also have to be moved
97 show_pane_list.each do |pane|
100 @tab_counts[pane[:name]] = pane[:count]
102 @tab_counts[pane[:name]] = @object.contents(filters: pane[:filters]).items_available
109 params[:item_uuids] = [params[:item_uuid]]
111 render template: 'projects/remove_items'
117 params[:item_uuids].collect { |uuid| ArvadosBase.find uuid }.each do |item|
118 if (item.class == Link and
119 item.link_class == 'name' and
120 item.tail_uuid == @object.uuid)
121 # Given uuid is a name link, linking an object to this
122 # project. First follow the link to find the item we're removing,
123 # then delete the link.
125 item = ArvadosBase.find item.head_uuid
127 # Given uuid is an object. Delete all names.
128 links += Link.where(tail_uuid: @object.uuid,
129 head_uuid: item.uuid,
133 @removed_uuids << link.uuid
137 # If this object has the 'expires_at' attribute, then simply mark it
139 if item.attributes.include?("expires_at")
140 item.update_attributes expires_at: Time.now
141 @removed_uuids << item.uuid
142 elsif item.owner_uuid == @object.uuid
143 # Object is owned by this project. Remove it from the project by
144 # changing owner to the current user.
146 item.update_attributes owner_uuid: current_user.uuid
147 @removed_uuids << item.uuid
148 rescue ArvadosApiClient::ApiErrorResponseException => e
149 if e.message.include? '_owner_uuid_name_unique'
150 rename_to = item.name + ' removed from ' +
151 (@object.name ? @object.name : @object.uuid) +
152 ' at ' + Time.now.to_s
154 updates[:name] = rename_to
155 updates[:owner_uuid] = current_user.uuid
156 item.update_attributes updates
157 @removed_uuids << item.uuid
167 while (objects = Link.filter([['owner_uuid','=',@object.uuid],
168 ['tail_uuid','=',@object.uuid]])).any?
169 objects.each do |object|
173 while (objects = @object.contents).any?
174 objects.each do |object|
175 object.update_attributes! owner_uuid: current_user.uuid
178 if ArvadosBase::resource_class_for_uuid(@object.owner_uuid) == Group
179 params[:return_to] ||= group_path(@object.owner_uuid)
181 params[:return_to] ||= projects_path
186 def find_objects_for_index
187 @objects = all_projects
191 def load_contents_objects kinds=[]
192 kind_filters = @filters.select do |attr,op,val|
193 op == 'is_a' and val.is_a? Array and val.count > 1
195 if /^created_at\b/ =~ @order[0] and kind_filters.count == 1
196 # If filtering on multiple types and sorting by date: Get the
197 # first page of each type, sort the entire set, truncate to one
198 # page, and use the last item on this page as a filter for
199 # retrieving the next page. Ideally the API would do this for
200 # us, but it doesn't (yet).
202 # To avoid losing items that have the same created_at as the
203 # last item on this page, we retrieve an overlapping page with a
204 # "created_at <= last_created_at" filter, then remove duplicates
205 # with a "uuid not in [...]" filter (see below).
206 nextpage_operator = /\bdesc$/i =~ @order[0] ? '<=' : '>='
210 kind_filters.each do |attr,op,val|
211 (val.is_a?(Array) ? val : [val]).each do |type|
212 objects = @object.contents(order: @order,
214 filters: (@filters - kind_filters + [['uuid', 'is_a', type]]),
216 objects.each do |object|
217 @name_link_for[object.andand.uuid] = objects.links_for(object, 'name').first
222 @objects = @objects.to_a.sort_by(&:created_at)
223 @objects.reverse! if nextpage_operator == '<='
224 @objects = @objects[0..@limit-1]
225 @next_page_filters = @filters.reject do |attr,op,val|
226 (attr == 'created_at' and op == nextpage_operator) or
227 (attr == 'uuid' and op == 'not in')
231 last_created_at = @objects.last.created_at
234 @objects.each do |obj|
235 last_uuids << obj.uuid if obj.created_at.eql?(last_created_at)
238 @next_page_filters += [['created_at',
241 @next_page_filters += [['uuid', 'not in', last_uuids]]
242 @next_page_href = url_for(partial: :contents_rows,
244 filters: @next_page_filters.to_json)
246 @next_page_href = nil
249 @objects = @object.contents(order: @order,
253 @next_page_href = next_page_href(partial: :contents_rows,
254 filters: @filters.to_json,
255 order: @order.to_json)
258 preload_links_for_objects(@objects.to_a)
263 return render_not_found("object not found")
267 load_contents_objects
271 content: render_to_string(partial: 'show_contents_rows.html',
273 next_page_href: @next_page_href
284 @new_resource_attrs = (params['project'] || {}).merge(group_class: 'project')
285 @new_resource_attrs[:name] ||= 'New project'
290 @updates = params['project']
294 helper_method :get_objects_and_names
295 def get_objects_and_names(objects=nil)
296 objects = @objects if objects.nil?
297 objects_and_names = []
298 objects.each do |object|
299 if objects.respond_to? :links_for and
300 !(name_links = objects.links_for(object, 'name')).empty?
301 name_links.each do |name_link|
302 objects_and_names << [object, name_link]
304 elsif @name_link_for.andand[object.uuid]
305 objects_and_names << [object, @name_link_for[object.uuid]]
306 elsif object.respond_to? :name
307 objects_and_names << [object, object]
309 objects_and_names << [object,
310 Link.new(owner_uuid: @object.uuid,
311 tail_uuid: @object.uuid,
312 head_uuid: object.uuid,
321 def public # Yes 'public' is the name of the action for public projects
322 return render_not_found if not Rails.configuration.anonymous_user_token or not Rails.configuration.enable_public_projects_page
323 @objects = using_specific_api_token Rails.configuration.anonymous_user_token do
324 Group.where(group_class: 'project').order("updated_at DESC")