9587: add support for include_trash in groups_controller -> contents method
[arvados.git] / services / api / app / controllers / arvados / v1 / groups_controller.rb
index ded28c7109673b4244d46b3ae0ce76ffcfa27e79..fc6489901a967a2dc667fc106e8f2178110420a8 100644 (file)
@@ -136,15 +136,28 @@ class Arvados::V1::GroupsController < ApplicationController
         end
       end.compact
 
-      @objects = klass.readable_by(*@read_users).
-        order(request_order).where(where_conds)
-      @limit = limit_all - all_objects.count
+      if klass == Collection and params[:include_trash]
+        @objects = klass.unscoped.readable_by(*@read_users).
+          order(request_order).where(where_conds)
+      else
+        @objects = klass.readable_by(*@read_users).
+          order(request_order).where(where_conds)
+      end
+      klass_limit = limit_all - all_objects.count
+      @limit = klass_limit
       apply_where_limit_order_params klass
-      klass_object_list = object_list
+      klass_object_list = object_list(model_class: klass)
       klass_items_available = klass_object_list[:items_available] || 0
       @items_available += klass_items_available
       @offset = [@offset - klass_items_available, 0].max
       all_objects += klass_object_list[:items]
+
+      if klass_object_list[:limit] < klass_limit
+        # object_list() had to reduce @limit to comply with
+        # max_index_database_read. From now on, we'll do all queries
+        # with limit=0 and just accumulate items_available.
+        limit_all = all_objects.count
+      end
     end
 
     @objects = all_objects