X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cb775c17c561a60b975a97a97fc9c0153f6954d6..e27e7a7e8b03f48e7d512ff714cc79fb60d92ff9:/services/api/app/models/user.rb diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb index 68e23804c1..ab8799d6bf 100644 --- a/services/api/app/models/user.rb +++ b/services/api/app/models/user.rb @@ -6,11 +6,12 @@ class User < ArvadosModel has_many :api_client_authorizations before_update :prevent_privilege_escalation before_update :prevent_inactive_admin + before_create :check_auto_admin after_create AdminNotifier has_many :authorized_keys, :foreign_key => :authorized_user_uuid, :primary_key => :uuid - api_accessible :superuser, :extend => :common do |t| + api_accessible :user, extend: :common do |t| t.add :email t.add :full_name t.add :first_name @@ -40,10 +41,10 @@ class User < ArvadosModel next if target_uuid == self.uuid next if (group_permissions[target_uuid] and group_permissions[target_uuid][action]) - if target.respond_to? :owner - next if target.owner == self.uuid - next if (group_permissions[target.owner] and - group_permissions[target.owner][action]) + if target.respond_to? :owner_uuid + next if target.owner_uuid == self.uuid + next if (group_permissions[target.owner_uuid] and + group_permissions[target.owner_uuid][action]) end return false end @@ -68,6 +69,15 @@ class User < ArvadosModel self.is_active == Rails.configuration.new_users_are_active) end + def check_auto_admin + if User.where("uuid not like '%-000000000000000'").where(:is_admin => true).count == 0 and not Rails.configuration.auto_admin_user.nil? + if current_user.email == Rails.configuration.auto_admin_user + self.is_admin = true + self.is_active = true + end + end + end + def prevent_privilege_escalation if current_user.andand.is_admin return true