X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/4fec5ed8870b227ec2982573c1aa26066027d66e..0b1508df7ee4526340e8834422dd49ced63ee8d9:/services/api/test/unit/group_test.rb diff --git a/services/api/test/unit/group_test.rb b/services/api/test/unit/group_test.rb index e2c88293c3..4672acd097 100644 --- a/services/api/test/unit/group_test.rb +++ b/services/api/test/unit/group_test.rb @@ -69,30 +69,87 @@ class GroupTest < ActiveSupport::TestCase assert Collection.readable_by(users(:active)).where(uuid: col.uuid).any? g_foo.update! is_trashed: true assert Collection.readable_by(users(:active)).where(uuid: col.uuid).empty? + assert Collection.readable_by(users(:active), {:include_trash => true}).where(uuid: col.uuid).any? g_foo.update! is_trashed: false assert Collection.readable_by(users(:active)).where(uuid: col.uuid).any? end + test "delete group" do + set_user_from_auth :active_trustedclient - test "delete group propagates to subgroups" do + g_foo = Group.create!(name: "foo") + g_bar = Group.create!(name: "bar", owner_uuid: g_foo.uuid) + g_baz = Group.create!(name: "baz", owner_uuid: g_bar.uuid) + + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).any? + g_foo.update! is_trashed: true + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).empty? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).empty? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty? + + assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_foo.uuid).any? + assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_bar.uuid).any? + assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_baz.uuid).any? + end + + + test "delete subgroup" do set_user_from_auth :active_trustedclient g_foo = Group.create!(name: "foo") g_bar = Group.create!(name: "bar", owner_uuid: g_foo.uuid) - col = Collection.create!(owner_uuid: g_bar.uuid) + g_baz = Group.create!(name: "baz", owner_uuid: g_bar.uuid) assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any? assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).any? - assert Collection.readable_by(users(:active)).where(uuid: col.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).any? + g_bar.update! is_trashed: true + + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).empty? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty? + + assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_bar.uuid).any? + assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_baz.uuid).any? + end + + test "delete subsubgroup" do + set_user_from_auth :active_trustedclient + + g_foo = Group.create!(name: "foo") + g_bar = Group.create!(name: "bar", owner_uuid: g_foo.uuid) + g_baz = Group.create!(name: "baz", owner_uuid: g_bar.uuid) + + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).any? + g_baz.update! is_trashed: true + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty? + assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_baz.uuid).any? + end + + + test "delete group propagates to subgroups" do + set_user_from_auth :active_trustedclient + + g_foo = groups(:trashed_project) + g_bar = groups(:trashed_subproject) + g_baz = groups(:trashed_subproject3) + col = collections(:collection_in_trashed_subproject) - g_foo.update! is_trashed: true assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).empty? assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).empty? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty? assert Collection.readable_by(users(:active)).where(uuid: col.uuid).empty? set_user_from_auth :admin assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).empty? assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).empty? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty? assert Collection.readable_by(users(:active)).where(uuid: col.uuid).empty? set_user_from_auth :active_trustedclient @@ -100,6 +157,12 @@ class GroupTest < ActiveSupport::TestCase assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any? assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).any? assert Collection.readable_by(users(:active)).where(uuid: col.uuid).any? + + # this one should still be deleted. + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty? + + g_baz.update! is_trashed: false + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).any? end end