12032: Fix hiding trashed groups directly owned by user.
authorPeter Amstutz <peter.amstutz@curoverse.com>
Fri, 25 Aug 2017 01:58:38 +0000 (21:58 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Thu, 14 Sep 2017 23:39:06 +0000 (19:39 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

services/api/app/models/arvados_model.rb
services/api/test/unit/group_test.rb

index 5a9d43f82d2b3762cc0c849261f4970b734d0999..ccd8f8276056528862cbaea8cc81d549ebd350a5 100644 (file)
@@ -293,7 +293,14 @@ class ArvadosModel < ActiveRecord::Base
                   (#{sql_table}.owner_uuid = pv.target_uuid AND pv.target_owner_uuid is NOT NULL)))"]
         # Match any object whose owner is listed explicitly in
         # user_uuids.
-        sql_conds += ["#{sql_table}.owner_uuid IN (:user_uuids)"]
+        trash_clause = if !include_trashed
+                         "1 NOT IN (SELECT trashed
+                             FROM permission_view pv
+                             WHERE #{sql_table}.uuid = pv.target_uuid) AND"
+                       else
+                         ""
+                       end
+        sql_conds += ["(#{trash_clause} #{sql_table}.owner_uuid IN (:user_uuids))"]
       else
         sql_conds += ["EXISTS(SELECT target_uuid
                   FROM permission_view pv
index 11f546bc6e1fc26ab2bb282907ece55b4c4c88ea..e2c88293c3d82933d95d14d5005e4e1ff1f2f2ad 100644 (file)
@@ -90,10 +90,12 @@ class GroupTest < ActiveSupport::TestCase
     assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).empty?
     assert Collection.readable_by(users(:active)).where(uuid: col.uuid).empty?
 
-    assert Group.readable_by(users(:active), {:include_trashed => true}).where(uuid: g_foo.uuid).any?
-    assert Group.readable_by(users(:active), {:include_trashed => true}).where(uuid: g_bar.uuid).any?
-    assert Collection.readable_by(users(:active), {:include_trashed => true}).where(uuid: col.uuid).any?
+    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 Collection.readable_by(users(:active)).where(uuid: col.uuid).empty?
 
+    set_user_from_auth :active_trustedclient
     g_foo.update! is_trashed: false
     assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any?
     assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).any?