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
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.
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
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