Arvbox sets PATH, GEM_HOME and GEM_PATH in common.sh. refs #10410
[arvados.git] / services / api / app / models / group.rb
index 94a392d5eb172ebc2a59de333bdfeb00c53283d7..6105b5f35d78636b0c9471b4f1315ec2236d77d6 100644 (file)
@@ -1,10 +1,40 @@
+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
+  before_create :assign_name
 
-  api_accessible :superuser, :extend => :common do |t|
+  api_accessible :user, extend: :common do |t|
     t.add :name
+    t.add :group_class
     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 db_current_time.to_i
+  end
+
+  def assign_name
+    if self.new_record? and (self.name.nil? or self.name.empty?)
+      self.name = self.uuid
+    end
+    true
   end
+
 end