3220: Merge branch '3220-http-status-codes' closes #3220
[arvados.git] / services / api / app / models / group.rb
index 4d7f63005344019f2020ac75f59858cb635d4cb7..d3802441317f21f5be00ccc194d16c2c7338037f 100644 (file)
@@ -1,7 +1,12 @@
+require 'can_be_an_owner'
+
 class Group < ArvadosModel
-  include AssignUuid
+  include HasUuid
   include KindAndEtag
   include CommonApiTemplate
+  include CanBeAnOwner
+  after_create :invalidate_permissions_cache
+  after_update :maybe_invalidate_permissions_cache
 
   api_accessible :user, extend: :common do |t|
     t.add :name
@@ -9,4 +14,18 @@ class Group < ArvadosModel
     t.add :description
     t.add :writable_by
   end
+
+  def maybe_invalidate_permissions_cache
+    if uuid_changed? or owner_uuid_changed?
+      # This can change users' permissions on other groups as well as
+      # this one.
+      invalidate_permissions_cache
+    end
+  end
+
+  def invalidate_permissions_cache
+    # Ensure a new group can be accessed by the appropriate users
+    # immediately after being created.
+    User.invalidate_permissions_cache
+  end
 end