Пример #1
0
 /**
  * {@inheritdoc}
  * @see ApiEntityAdapter::validateEntity()
  */
 public function validateEntity($entity)
 {
     /* @var $entity Environment */
     if (empty($entity->name)) {
         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property name");
     }
     if (Environment::findOne([['accountId' => $entity->accountId], ['name' => $entity->name], ['id' => ['$ne' => $entity->id]]])) {
         throw new ApiErrorException(409, ErrorMessage::ERR_UNICITY_VIOLATION, "Environment with name '{$entity->name}' already exists in this account");
     }
     if (empty($entity->getProperty(EnvironmentProperty::SETTING_CC_ID))) {
         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property costCenter");
     }
 }
Пример #2
0
 /**
  * Gets specified Environment
  *
  * @param      string $envId  Numeric identifier of the Environment
  *
  * @return  Account\Environment Returns the Environment Entity on success
  *
  * @throws ApiErrorException
  *
  */
 public function getEnv($envId)
 {
     /* @var $env Account\Environment */
     $env = Account\Environment::findOne(array_merge($this->getDefaultCriteria(), [['id' => $envId]]));
     if (!$env) {
         throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Requested Environment either does not exist or is not owned by your account.");
     }
     if (!$this->getUser()->hasAccessToEnvironment($envId)) {
         //Checks entity level write access permissions
         throw new ApiErrorException(403, ErrorMessage::ERR_PERMISSION_VIOLATION, "Insufficient permissions");
     }
     return $env;
 }