[ARVADOS] updated: 6b928cd8adc2ed93f4b7f3d1be8e933e3b1a572b
Git user
git at public.curoverse.com
Thu Aug 24 17:10:57 EDT 2017
Summary of changes:
services/api/app/models/group.rb | 6 ++++
.../db/migrate/20170824202826_trashable_groups.rb | 7 ++++
services/api/db/structure.sql | 7 +++-
services/api/lib/create_permission_view.sql | 2 +-
services/api/test/unit/group_test.rb | 40 ++++++++++++++++++++++
5 files changed, 60 insertions(+), 2 deletions(-)
create mode 100644 services/api/db/migrate/20170824202826_trashable_groups.rb
via 6b928cd8adc2ed93f4b7f3d1be8e933e3b1a572b (commit)
from a263160f6243ba5485d8cc2dd10c15822f1252d6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 6b928cd8adc2ed93f4b7f3d1be8e933e3b1a572b
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date: Thu Aug 24 17:09:49 2017 -0400
12032: Tests for group delete behavior.
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>
diff --git a/services/api/app/models/group.rb b/services/api/app/models/group.rb
index 0dd2a73..861800d 100644
--- a/services/api/app/models/group.rb
+++ b/services/api/app/models/group.rb
@@ -3,12 +3,15 @@
# SPDX-License-Identifier: AGPL-3.0
require 'can_be_an_owner'
+require 'trashable'
class Group < ArvadosModel
include HasUuid
include KindAndEtag
include CommonApiTemplate
include CanBeAnOwner
+ include Trashable
+
after_create :invalidate_permissions_cache
after_update :maybe_invalidate_permissions_cache
before_create :assign_name
@@ -18,6 +21,9 @@ class Group < ArvadosModel
t.add :group_class
t.add :description
t.add :writable_by
+ t.add :delete_at
+ t.add :trash_at
+ t.add :is_trashed
end
def maybe_invalidate_permissions_cache
diff --git a/services/api/db/migrate/20170824202826_trashable_groups.rb b/services/api/db/migrate/20170824202826_trashable_groups.rb
new file mode 100644
index 0000000..b7e3373
--- /dev/null
+++ b/services/api/db/migrate/20170824202826_trashable_groups.rb
@@ -0,0 +1,7 @@
+class TrashableGroups < ActiveRecord::Migration
+ def change
+ add_column :groups, :trash_at, :datetime
+ add_column :groups, :delete_at, :datetime
+ add_column :groups, :is_trashed, :boolean, null: false, default: false
+ end
+end
diff --git a/services/api/db/structure.sql b/services/api/db/structure.sql
index 7e6bb1d..90aa0a3 100644
--- a/services/api/db/structure.sql
+++ b/services/api/db/structure.sql
@@ -391,7 +391,10 @@ CREATE TABLE groups (
name character varying(255) NOT NULL,
description character varying(524288),
updated_at timestamp without time zone NOT NULL,
- group_class character varying(255)
+ group_class character varying(255),
+ trash_at timestamp without time zone,
+ delete_at timestamp without time zone,
+ is_trashed boolean DEFAULT false NOT NULL
);
@@ -2791,3 +2794,5 @@ INSERT INTO schema_migrations (version) VALUES ('20170419175801');
INSERT INTO schema_migrations (version) VALUES ('20170628185847');
+INSERT INTO schema_migrations (version) VALUES ('20170824202826');
+
diff --git a/services/api/lib/create_permission_view.sql b/services/api/lib/create_permission_view.sql
index 82839e8..e6195d7 100644
--- a/services/api/lib/create_permission_view.sql
+++ b/services/api/lib/create_permission_view.sql
@@ -37,7 +37,7 @@ perm_edges (tail_uuid, head_uuid, val, follow, trashed) AS (
LEFT JOIN groups ON pv.val<3 AND groups.uuid = links.head_uuid
WHERE links.link_class = 'permission'
UNION ALL
- SELECT owner_uuid, uuid, 3, true, 0::smallint FROM groups
+ SELECT owner_uuid, uuid, 3, true, CASE is_trashed WHEN true THEN 1 ELSE 0 END FROM groups
),
perm (val, follow, user_uuid, target_uuid, trashed, startnode) AS (
SELECT 3::smallint AS val,
diff --git a/services/api/test/unit/group_test.rb b/services/api/test/unit/group_test.rb
index a1123b1..11f546b 100644
--- a/services/api/test/unit/group_test.rb
+++ b/services/api/test/unit/group_test.rb
@@ -60,4 +60,44 @@ class GroupTest < ActiveSupport::TestCase
assert g_foo.errors.messages[:owner_uuid].join(" ").match(/ownership cycle/)
end
+ test "delete group hides contents" do
+ set_user_from_auth :active_trustedclient
+
+ g_foo = Group.create!(name: "foo")
+ col = Collection.create!(owner_uuid: g_foo.uuid)
+
+ 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?
+ g_foo.update! is_trashed: false
+ assert Collection.readable_by(users(:active)).where(uuid: col.uuid).any?
+ end
+
+
+ test "delete group propagates to subgroups" 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)
+
+ 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?
+
+ 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 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?
+
+ 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?
+ assert Collection.readable_by(users(:active)).where(uuid: col.uuid).any?
+ end
+
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list