8784: Fix test for latest firefox.
[arvados.git] / services / api / app / models / group.rb
1 require 'can_be_an_owner'
2
3 class Group < ArvadosModel
4   include HasUuid
5   include KindAndEtag
6   include CommonApiTemplate
7   include CanBeAnOwner
8   after_create :invalidate_permissions_cache
9   after_update :maybe_invalidate_permissions_cache
10   before_create :assign_name
11
12   api_accessible :user, extend: :common do |t|
13     t.add :name
14     t.add :group_class
15     t.add :description
16     t.add :writable_by
17   end
18
19   def maybe_invalidate_permissions_cache
20     if uuid_changed? or owner_uuid_changed?
21       # This can change users' permissions on other groups as well as
22       # this one.
23       invalidate_permissions_cache
24     end
25   end
26
27   def invalidate_permissions_cache
28     # Ensure a new group can be accessed by the appropriate users
29     # immediately after being created.
30     User.invalidate_permissions_cache db_current_time.to_i
31   end
32
33   def assign_name
34     if self.new_record? and (self.name.nil? or self.name.empty?)
35       self.name = self.uuid
36     end
37     true
38   end
39
40 end