def self._contents_requires_parameters
_index_requires_parameters.
merge({
+ uuid: {
+ type: 'string', required: false, default: nil
+ },
+ # include_linked returns name links, which are obsolete, so
+ # remove it when clients have been migrated.
include_linked: {
type: 'boolean', required: false, default: false
},
end
def render_404_if_no_object
- if params[:action] == 'contents' and !params[:uuid]
- # OK!
- @object = nil
+ if params[:action] == 'contents'
+ if !params[:uuid]
+ # OK!
+ @object = nil
+ true
+ elsif @object
+ # Project group
+ true
+ elsif (@object = User.where(uuid: params[:uuid]).first)
+ # "Home" pseudo-project
+ true
+ else
+ super
+ end
else
super
end
def contents
# Set @objects:
- load_searchable_objects(owner_uuid: @object.andand.uuid, include_linked: params[:include_linked])
-
- @links = Link.where('link_class=? and tail_uuid=?'\
- ' and head_uuid in (?)',
- 'name',
- @object.uuid,
- @objects.collect(&:uuid))
+ # include_linked returns name links, which are obsolete, so
+ # remove it when clients have been migrated.
+ load_searchable_objects(owner_uuid: @object.andand.uuid,
+ include_linked: params[:include_linked])
+ sql = 'link_class=? and head_uuid in (?)'
+ sql_params = ['name', @objects.collect(&:uuid)]
+ if @object
+ sql += ' and tail_uuid=?'
+ sql_params << @object.uuid
+ end
+ @links = Link.where sql, *sql_params
@object_list = {
:kind => "arvados#objectList",
:etag => "",
# aggregate set.
limit_all = @limit
offset_all = @offset
+ # save the orders from the current request as determined by load_param,
+ # but otherwise discard them because we're going to be getting objects
+ # from many models
+ request_orders = @orders.clone
@orders = []
[Group,
Collection,
Human, Specimen, Trait].each do |klass|
@objects = klass.readable_by(*@read_users)
- conds = []
- cond_params = []
+ if klass == Group
+ @objects = @objects.where(group_class: 'project')
+ end
if opts[:owner_uuid]
+ conds = []
+ cond_params = []
conds << "#{klass.table_name}.owner_uuid = ?"
cond_params << opts[:owner_uuid]
+ if conds.any?
+ cond_sql = '(' + conds.join(') OR (') + ')'
+ @objects = @objects.where(cond_sql, *cond_params)
+ end
end
- if opts[:include_linked]
- conds << " 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})"
- end
- if conds.any?
- @objects = @objects.where(cond_sql, *cond_params)
+
+ # If the currently requested orders specifically match the table_name for the current klass, apply the order
+ request_order = request_orders && request_orders.find{ |r| r =~ /^#{klass.table_name}\./i }
+ if request_order
+ @objects = @objects.order(request_order)
+ else
+ # default to created_at desc, ignoring any currently requested ordering because it doesn't apply to this klass
+ @objects = @objects.order("#{klass.table_name}.created_at desc")
end
- @objects = @objects.order("#{klass.table_name}.uuid")
+
@limit = limit_all - all_objects.count
- apply_where_limit_order_params
+ apply_where_limit_order_params klass
klass_items_available = @objects.
except(:limit).except(:offset).
count(:id, distinct: true)