add some admin privileges to make bootstrapping possible
[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 prevent_privilege_escalation
26     if self.is_admin_changed? and !current_user.is_admin
27       if current_user.uuid == self.uuid
28         if self.is_admin != self.is_admin_was
29           logger.warn "User #{self.uuid} tried to change is_admin from #{self.is_admin_was} to #{self.is_admin}"
30           self.is_admin = self.is_admin_was
31         end
32       end
33     end
34     true
35   end
36 end