Exemple #1
0
 /**
  * Gets TeamEnvs entity
  *
  * @param string $criteria search criteria
  * @param array $params query params
  * @return TeamEnvs
  */
 protected function getEnvironmentTeam($criteria, $params)
 {
     /* @var  $teamEnv TeamEnvs */
     $teamEnv = TeamEnvs::findOne([['teamId' => $criteria], ['envId' => $params['envId']]]);
     static::toDelete(TeamEnvs::class, [$teamEnv->envId, $teamEnv->teamId]);
     return $teamEnv;
 }
Exemple #2
0
 /**
  * Revoke team access to specified environment
  *
  * @param   int $envId  Environment ID
  * @param   int $teamId Team ID
  *
  * @return  ResultEnvelope
  *
  * @throws  ApiErrorException
  * @throws  ModelException
  */
 public function denyTeamAction($envId, $teamId)
 {
     if (!$this->getUser()->canManageAcl()) {
         throw new ApiInsufficientPermissionsException();
     }
     $this->getEnv($envId);
     $team = Account\TeamEnvs::findOne([['envId' => $envId], ['teamId' => $teamId]]);
     if (empty($team)) {
         throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Team '{$teamId}' has no access to environment '{$envId}'");
     }
     $team->delete();
     return $this->result(null);
 }
 /**
  * {@inheritdoc}
  * @see ApiEntityAdapter::validateEntity()
  */
 public function validateEntity($entity)
 {
     if (!$entity instanceof TeamEnvs) {
         throw new InvalidArgumentException(sprintf("First argument must be instance of %s", Team::class));
     }
     if (empty($entity->teamId)) {
         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property team.id");
     }
     $teamId = $entity->teamId;
     if (!is_numeric($teamId)) {
         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid team identifier");
     }
     /* @var $team Team */
     $team = Team::findOne([['id' => $teamId], ['accountId' => $this->controller->getUser()->accountId]]);
     if (empty($team)) {
         throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, sprintf("Requested team %s do not exist in this account", $teamId));
     }
     if (!empty(TeamEnvs::findOne([['envId' => $entity->envId], ['teamId' => $teamId]]))) {
         throw new ApiErrorException(409, ErrorMessage::ERR_UNICITY_VIOLATION, sprintf("Team %s already exists in this environment", $teamId));
     }
     /* @var  $teamAdapter TeamAdapter */
     $teamAdapter = $this->controller->adapter('team');
     $teamAdapter->validateTeamName($team->name);
 }