Add job.cancel API.
[arvados.git] / services / api / app / models / user.rb
index 68e23804c1f4479eeb1d82e5f536cd654428a694..ab8799d6bf83d7bac5db733408d21a7722ee3c47 100644 (file)
@@ -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