Merge branch '16265-security-updates' into dependabot/bundler/services/api/rake-13.0.1
[arvados.git] / services / api / app / models / group.rb
index 0e857ad15c22101d0d93e4b497479f3e14a6055d..1f2b0d8b776a1f63ca94d0e3e7654e7f9cd5887b 100644 (file)
@@ -1,10 +1,22 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# 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
+
+  # Posgresql JSONB columns should NOT be declared as serialized, Rails 5
+  # already know how to properly treat them.
+  attribute :properties, :jsonbHash, default: {}
+
+  validate :ensure_filesystem_compatible_name
   after_create :invalidate_permissions_cache
   after_update :maybe_invalidate_permissions_cache
   before_create :assign_name
@@ -14,10 +26,20 @@ 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
+    t.add :properties
+  end
+
+  def ensure_filesystem_compatible_name
+    # project groups need filesystem-compatible names, but others
+    # don't.
+    super if group_class == 'project'
   end
 
   def maybe_invalidate_permissions_cache
-    if uuid_changed? or owner_uuid_changed?
+    if uuid_changed? or owner_uuid_changed? or is_trashed_changed?
       # This can change users' permissions on other groups as well as
       # this one.
       invalidate_permissions_cache
@@ -27,7 +49,7 @@ class Group < ArvadosModel
   def invalidate_permissions_cache
     # Ensure a new group can be accessed by the appropriate users
     # immediately after being created.
-    User.invalidate_permissions_cache
+    User.invalidate_permissions_cache self.async_permissions_update
   end
 
   def assign_name
@@ -36,5 +58,4 @@ class Group < ArvadosModel
     end
     true
   end
-
 end