2884: Selecting folders works for run pipeline dialog. Increased page size
[arvados.git] / services / api / app / controllers / arvados / v1 / groups_controller.rb
1 class Arvados::V1::GroupsController < ApplicationController
2
3   def self._contents_requires_parameters
4     _index_requires_parameters.
5       merge({
6               include_linked: {
7                 type: 'boolean', required: false, default: false
8               },
9             })
10   end
11
12   def contents
13     all_objects = []
14     all_available = 0
15
16     # Trick apply_where_limit_order_params into applying suitable
17     # per-table values. *_all are the real ones we'll apply to the
18     # aggregate set.
19     limit_all = @limit
20     offset_all = @offset
21     @orders = []
22
23     [Group,
24      Job, PipelineInstance, PipelineTemplate,
25      Collection,
26      Human, Specimen, Trait].each do |klass|
27       @objects = klass.readable_by(*@read_users)
28       cond_sql = "#{klass.table_name}.owner_uuid = ?"
29       cond_params = [@object.uuid]
30       if params[:include_linked]
31         cond_sql += " OR #{klass.table_name}.uuid IN (SELECT head_uuid FROM links WHERE link_class=#{klass.sanitize 'name'} AND links.tail_uuid=#{klass.sanitize @object.uuid})"
32       end
33       @objects = @objects.where(cond_sql, *cond_params).order("#{klass.table_name}.uuid")
34       @limit = limit_all - all_objects.count
35       apply_where_limit_order_params
36       items_available = @objects.
37         except(:limit).except(:offset).
38         count(:id, distinct: true)
39       all_available += items_available
40       @offset = [@offset - items_available, 0].max
41
42       all_objects += @objects.to_a
43     end
44     @objects = all_objects || []
45     @links = Link.where('link_class=? and tail_uuid=?'\
46                         ' and head_uuid in (?)',
47                         'name',
48                         @object.uuid,
49                         @objects.collect(&:uuid))
50     @object_list = {
51       :kind  => "arvados#objectList",
52       :etag => "",
53       :self_link => "",
54       :links => @links.as_api_response(nil),
55       :offset => offset_all,
56       :limit => limit_all,
57       :items_available => all_available,
58       :items => @objects.as_api_response(nil)
59     }
60     render json: @object_list
61   end
62
63 end