1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class Arvados::V1::GroupsController < ApplicationController
8 include TrashableController
10 def self._index_requires_parameters
14 type: 'boolean', required: false, description: "Include items whose is_trashed attribute is true."
19 def self._contents_requires_parameters
20 params = _index_requires_parameters.
23 type: 'string', required: false, default: nil
26 type: 'boolean', required: false, description: 'Include contents from child groups recursively.'
29 params.delete(:select)
33 def render_404_if_no_object
34 if params[:action] == 'contents'
42 elsif (@object = User.where(uuid: params[:uuid]).first)
43 # "Home" pseudo-project
54 load_searchable_objects
56 :kind => "arvados#objectList",
61 :items_available => @items_available,
62 :items => @objects.as_api_response(nil)
68 def load_searchable_objects
72 # Trick apply_where_limit_order_params into applying suitable
73 # per-table values. *_all are the real ones we'll apply to the
77 # save the orders from the current request as determined by load_param,
78 # but otherwise discard them because we're going to be getting objects
80 request_orders = @orders.clone
83 request_filters = @filters
86 Job, PipelineInstance, PipelineTemplate, ContainerRequest, Workflow,
88 Human, Specimen, Trait]
90 table_names = Hash[klasses.collect { |k| [k, k.table_name] }]
92 disabled_methods = Rails.configuration.disable_api_methods
93 avail_klasses = table_names.select{|k, t| !disabled_methods.include?(t+'.index')}
94 klasses = avail_klasses.keys
96 request_filters.each do |col, op, val|
97 if col.index('.') && !table_names.values.include?(col.split('.', 2)[0])
98 raise ArgumentError.new("Invalid attribute '#{col}' in filter")
103 request_filters.each do |col,op,val|
105 (val.is_a?(Array) ? val : [val]).each do |type|
106 type = type.split('#')[-1]
107 type[0] = type[0].capitalize
108 wanted_klasses << type
115 if params['recursive']
116 filter_by_owner[:owner_uuid] = [@object.uuid] + @object.descendant_project_uuids
118 filter_by_owner[:owner_uuid] = @object.uuid
122 seen_last_class = false
123 klasses.each do |klass|
124 @offset = 0 if seen_last_class # reset offset for the new next type being processed
126 # if current klass is same as params['last_object_class'], mark that fact
127 seen_last_class = true if((params['count'].andand.==('none')) and
128 (params['last_object_class'].nil? or
129 params['last_object_class'].empty? or
130 params['last_object_class'] == klass.to_s))
132 # if klasses are specified, skip all other klass types
133 next if wanted_klasses.any? and !wanted_klasses.include?(klass.to_s)
135 # don't reprocess klass types that were already seen
136 next if params['count'] == 'none' and !seen_last_class
138 # don't process rest of object types if we already have needed number of objects
139 break if params['count'] == 'none' and all_objects.size >= limit_all
141 # If the currently requested orders specifically match the
142 # table_name for the current klass, apply that order.
143 # Otherwise, order by recency.
145 request_orders.andand.find { |r| r =~ /^#{klass.table_name}\./i } ||
146 klass.default_orders.join(", ")
149 where_conds = filter_by_owner
150 if klass == Collection
151 @select = klass.selectable_attributes - ["manifest_text"]
153 where_conds = where_conds.merge(group_class: "project")
156 @filters = request_filters.map do |col, op, val|
159 elsif (col = col.split('.', 2))[0] == klass.table_name
166 @objects = klass.readable_by(*@read_users, {:include_trash => params[:include_trash]}).
167 order(request_order).where(where_conds)
169 klass_limit = limit_all - all_objects.count
171 apply_where_limit_order_params klass
172 klass_object_list = object_list(model_class: klass)
173 klass_items_available = klass_object_list[:items_available] || 0
174 @items_available += klass_items_available
175 @offset = [@offset - klass_items_available, 0].max
176 all_objects += klass_object_list[:items]
178 if klass_object_list[:limit] < klass_limit
179 # object_list() had to reduce @limit to comply with
180 # max_index_database_read. From now on, we'll do all queries
181 # with limit=0 and just accumulate items_available.
182 limit_all = all_objects.count
186 @objects = all_objects