18122: Fix "get collection by pdh" when manifest_text is unselected.
authorTom Clegg <tom@curii.com>
Thu, 16 Sep 2021 17:15:29 +0000 (13:15 -0400)
committerTom Clegg <tom@curii.com>
Thu, 16 Sep 2021 17:15:29 +0000 (13:15 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

services/api/app/controllers/arvados/v1/collections_controller.rb
services/api/test/functional/arvados/v1/collections_controller_test.rb

index 1b0850a5802eab5e7b451cf40ac1beecf392a61b..c9b36e19ed95dedca95d9fd473af748088641d33 100644 (file)
@@ -80,18 +80,22 @@ class Arvados::V1::CollectionsController < ApplicationController
       # it will select the Collection object with the longest
       # available lifetime.
 
+      select_attrs = (@select || ["manifest_text"]) | ["portable_data_hash", "trash_at"]
       if c = Collection.
                readable_by(*@read_users, opts).
                where({ portable_data_hash: loc.to_s }).
                order("trash_at desc").
-               select(((@select || ["manifest_text"]) | ["portable_data_hash", "trash_at"]).join(", ")).
+               select(select_attrs.join(", ")).
                limit(1).
                first
         @object = {
           uuid: c.portable_data_hash,
           portable_data_hash: c.portable_data_hash,
-          manifest_text: c.manifest_text,
+          trash_at: c.trash_at,
         }
+        if select_attrs.index("manifest_text")
+          @object[:manifest_text] = c.manifest_text
+        end
       end
     else
       super
index 3b217f06de984b3a0a185d58c18fc9d98c8a42ff..af11715982a1adf26226a986c54bc9b6f69676c9 100644 (file)
@@ -1491,4 +1491,26 @@ EOS
     assert_nil json_response["properties"]
     assert_equal collections(:collection_owned_by_active).name, json_response["name"]
   end
+
+  [nil,
+   [],
+   ["is_trashed", "trash_at"],
+   ["is_trashed", "trash_at", "portable_data_hash"],
+   ["portable_data_hash"],
+   ["portable_data_hash", "manifest_text"],
+  ].each do |select|
+    test "select=#{select.inspect} param is respected in 'get by pdh' response" do
+      authorize_with :active
+      get :show, params: {
+            id: collections(:collection_owned_by_active).portable_data_hash,
+            select: select,
+          }
+      assert_response :success
+      if !select || select.index("manifest_text")
+        assert_not_nil json_response["manifest_text"]
+      else
+        assert_nil json_response["manifest_text"]
+      end
+    end
+  end
 end