Merge branch 'master' into origin-8442-cwl-crunch2
[arvados.git] / services / api / app / models / container_request.rb
index 6353132e908baa3d683ec0a9d320ff3a60d55804..496a6b141db2d4f95536430b31edad1f90fba82f 100644 (file)
@@ -18,6 +18,7 @@ class ContainerRequest < ArvadosModel
   validate :validate_state_change
   validate :validate_change
   after_save :update_priority
+  before_create :set_requesting_container_uuid
 
   api_accessible :user, extend: :common do |t|
     t.add :command
@@ -128,8 +129,8 @@ class ContainerRequest < ArvadosModel
         errors.add :priority, "cannot be nil"
       end
 
-      # Can update priority, container count.
-      permitted.push :priority, :container_count_max, :container_uuid
+      # Can update priority, container count, name and description
+      permitted.push :priority, :container_count_max, :container_uuid, :name, :description
 
       if self.state_changed?
         # Allow create-and-commit in a single operation.
@@ -140,12 +141,12 @@ class ContainerRequest < ArvadosModel
       end
 
     when Final
-      if not current_user.andand.is_admin
+      if not current_user.andand.is_admin and not (self.name_changed? || self.description_changed?)
         errors.add :state, "of container request can only be set to Final by system."
       end
 
-      if self.state_changed?
-          permitted.push :state
+      if self.state_changed? || self.name_changed? || self.description_changed?
+          permitted.push :state, :name, :description
       else
         errors.add :state, "does not allow updates"
       end
@@ -170,4 +171,12 @@ class ContainerRequest < ArvadosModel
     end
   end
 
+  def set_requesting_container_uuid
+    return true if self.requesting_container_uuid   # already set
+
+    token_uuid = current_api_client_authorization.andand.uuid
+    container = Container.where('auth_uuid=?', token_uuid).order('created_at desc').first
+    self.requesting_container_uuid = container.uuid if container
+    true
+  end
 end