[ARVADOS] created: 1.2.0-243-g0d9d68f8a

Git user git at public.curoverse.com
Thu Oct 18 18:47:53 EDT 2018


        at  0d9d68f8a6c0a6593814f5610b611847de5004ac (commit)


commit 0d9d68f8a6c0a6593814f5610b611847de5004ac
Author: Lucas Di Pentima <ldipentima at veritasgenetics.com>
Date:   Thu Oct 18 19:46:18 2018 -0300

    13561: Exclude past versions regardless of user & include_trash setting.
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima at veritasgenetics.com>

diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb
index 801da17db..1e90ef602 100644
--- a/services/api/app/models/arvados_model.rb
+++ b/services/api/app/models/arvados_model.rb
@@ -281,7 +281,7 @@ class ArvadosModel < ActiveRecord::Base
           # Only include records where the owner is not trashed
           sql_conds = "NOT EXISTS(SELECT 1 FROM #{PERMISSION_VIEW} "+
                       "WHERE trashed = 1 AND "+
-                      "(#{sql_table}.owner_uuid = target_uuid)) #{exclude_trashed_records} #{exclude_old_versions}"
+                      "(#{sql_table}.owner_uuid = target_uuid)) #{exclude_trashed_records}"
         end
       end
     else
@@ -318,10 +318,18 @@ class ArvadosModel < ActiveRecord::Base
                        "(#{sql_table}.head_uuid IN (:user_uuids) OR #{sql_table}.tail_uuid IN (:user_uuids)))"
       end
 
-      sql_conds = "(#{direct_check} #{owner_check} #{links_cond}) #{exclude_trashed_records} #{exclude_old_versions}"
+      sql_conds = "(#{direct_check} #{owner_check} #{links_cond}) #{exclude_trashed_records}"
 
     end
 
+    if exclude_old_versions != ""
+      if sql_conds.nil?
+        sql_conds = exclude_old_versions[4..-1] # Remove "AND "
+      else
+        sql_conds += " #{exclude_old_versions}"
+      end
+    end
+
     self.where(sql_conds,
                user_uuids: user_uuids,
                permission_link_classes: ['permission', 'resources'])
diff --git a/services/api/test/fixtures/collections.yml b/services/api/test/fixtures/collections.yml
index 29b486c45..8763f3944 100644
--- a/services/api/test/fixtures/collections.yml
+++ b/services/api/test/fixtures/collections.yml
@@ -291,6 +291,24 @@ expired_collection:
   delete_at: 2038-01-01T00:00:00Z
   manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:expired\n"
   name: expired_collection
+  version: 2
+
+expired_collection_past_version:
+  uuid: zzzzz-4zz18-mto52zx1s7oldie
+  current_version_uuid: zzzzz-4zz18-mto52zx1s7sn3ih
+  portable_data_hash: 0b21a217243bfce5617fb9224b95bcb9+49
+  owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  created_at: 2014-02-03T17:12:54Z
+  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_user_uuid: zzzzz-tpzed-d9tiejq69daie8f
+  modified_at: 2014-02-03T17:17:54Z
+  updated_at: 2014-02-03T17:17:54Z
+  is_trashed: true
+  trash_at: 2001-01-01T00:00:00Z
+  delete_at: 2038-01-01T00:00:00Z
+  manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:expired\n"
+  name: expired_collection original
+  version: 1
 
 trashed_on_next_sweep:
   uuid: zzzzz-4zz18-4guozfh77ewd2f0
diff --git a/services/api/test/functional/arvados/v1/collections_controller_test.rb b/services/api/test/functional/arvados/v1/collections_controller_test.rb
index f5bed6384..26b8290e6 100644
--- a/services/api/test/functional/arvados/v1/collections_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/collections_controller_test.rb
@@ -1025,6 +1025,54 @@ EOS
     assert_response 200
   end
 
+  [:admin, :active].each do |user|
+    test "get trashed collection via filters and #{user} user" do
+      uuid = 'zzzzz-4zz18-mto52zx1s7sn3ih' # expired_collection
+      authorize_with user
+      get :index, {
+        filters: [["current_version_uuid", "=", uuid]],
+        include_trash: true,
+      }
+      assert_response 200
+      # Only the current version is returned
+      assert_equal 1, json_response["items"].size
+    end
+  end
+
+  [:admin, :active].each do |user|
+    test "get trashed collection via filters and #{user} user, including its past versions" do
+      uuid = 'zzzzz-4zz18-mto52zx1s7sn3ih' # expired_collection
+      authorize_with :admin
+      get :index, {
+        filters: [["current_version_uuid", "=", uuid]],
+        include_trash: true,
+        include_old_versions: true,
+      }
+      assert_response 200
+      # Both current & past version are returned
+      assert_equal 2, json_response["items"].size
+    end
+  end
+
+  test "trash collection also trash its past versions" do
+    uuid = collections(:collection_owned_by_active).uuid
+    authorize_with :active
+    versions = Collection.where(current_version_uuid: uuid)
+    assert_equal 2, versions.size
+    versions.each do |col|
+      refute col.is_trashed
+    end
+    post :trash, {
+      id: uuid,
+    }
+    assert_response 200
+    versions = Collection.where(current_version_uuid: uuid)
+    assert_equal 2, versions.size
+    versions.each do |col|
+      assert col.is_trashed
+    end
+  end
+
   test 'get trashed collection without include_trash' do
     uuid = 'zzzzz-4zz18-mto52zx1s7sn3ih' # expired_collection
     authorize_with :active

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list