17119: bugfix: the group/contents endpoint should do the right thing
authorWard Vandewege <ward@curii.com>
Thu, 25 Mar 2021 19:47:35 +0000 (15:47 -0400)
committerWard Vandewege <ward@curii.com>
Thu, 25 Mar 2021 19:47:35 +0000 (15:47 -0400)
       when 'count: none' and an offset are provided.

Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

services/api/app/controllers/arvados/v1/groups_controller.rb
services/api/test/integration/groups_test.rb

index 5388e8ffbb6552608ac461ccd51fdd8259769e6d..a8957de75eba3555ab5d527d870d7bafa6668be2 100644 (file)
@@ -246,8 +246,6 @@ class Arvados::V1::GroupsController < ApplicationController
 
     seen_last_class = false
     klasses.each do |klass|
-      @offset = 0 if seen_last_class  # reset offset for the new next type being processed
-
       # if current klass is same as params['last_object_class'], mark that fact
       seen_last_class = true if((params['count'].andand.==('none')) and
                                 (params['last_object_class'].nil? or
@@ -296,12 +294,24 @@ class Arvados::V1::GroupsController < ApplicationController
       if params['exclude_home_project']
         @objects = exclude_home @objects, klass
       end
+      if params['count'] == 'none'
+        # The call to object_list below will not populate :items_available in
+        # its response, because count is disabled.  Save @objects length (does
+        # not require another db query) so that @offset (if set) is handled
+        # correctly.
+        countless_items_available = @objects.length
+      end
 
       klass_limit = limit_all - all_objects.count
       @limit = klass_limit
       apply_where_limit_order_params klass
       klass_object_list = object_list(model_class: klass)
-      klass_items_available = klass_object_list[:items_available] || 0
+      if params['count'] != 'none'
+        klass_items_available = klass_object_list[:items_available] || 0
+      else
+        # klass_object_list[:items_available] is not populated
+        klass_items_available = countless_items_available || 0
+      end
       @items_available += klass_items_available
       @offset = [@offset - klass_items_available, 0].max
       all_objects += klass_object_list[:items]
index 7021761278d72143c277b06622504eae3c593334..aa67166f7e613a7b71f1ce8b798cf3b23b060e4a 100644 (file)
@@ -177,6 +177,26 @@ class GroupsTest < ActionDispatch::IntegrationTest
     end
     assert_equal true, found_projects.include?(groups(:starred_and_shared_active_user_project).uuid)
   end
+
+  test 'count none works with offset' do
+    first_results = nil
+    (0..10).each do |offset|
+      get "/arvados/v1/groups/contents", params: {
+        id: groups(:aproject).uuid,
+        offset: offset,
+        format: :json,
+        order: :uuid,
+        count: :none,
+      }, headers: auth(:active)
+      assert_response :success
+      assert_nil json_response['items_available']
+      if first_results.nil?
+        first_results = json_response['items']
+      else
+        assert_equal first_results[offset]['uuid'], json_response['items'][0]['uuid']
+      end
+    end
+  end
 end
 
 class NonTransactionalGroupsTest < ActionDispatch::IntegrationTest