restart dispatch_jobs service on deploy
[arvados.git] / app / models / user.rb
1 class User < OrvosModel
2   include AssignUuid
3   include KindAndEtag
4   include CommonApiTemplate
5   serialize :prefs, Hash
6   has_many :api_client_authorizations
7   before_update :prevent_privilege_escalation
8
9   api_accessible :superuser, :extend => :common do |t|
10     t.add :email
11     t.add :full_name
12     t.add :first_name
13     t.add :last_name
14     t.add :identity_url
15     t.add :is_admin
16     t.add :prefs
17   end
18
19   def full_name
20     "#{first_name} #{last_name}"
21   end
22
23   protected
24
25   def permission_to_create
26     Thread.current[:user] == self or
27       (Thread.current[:user] and Thread.current[:user].is_admin)
28   end
29
30   def prevent_privilege_escalation
31     if self.is_admin_changed? and !current_user.is_admin
32       if current_user.uuid == self.uuid
33         if self.is_admin != self.is_admin_was
34           logger.warn "User #{self.uuid} tried to change is_admin from #{self.is_admin_was} to #{self.is_admin}"
35           self.is_admin = self.is_admin_was
36         end
37       end
38     end
39     true
40   end
41 end