/** * Check if a DNDeployment exists and do permission checks on it. If there is something wrong it will return * an APIResponse with the error, otherwise null. * * @param \DNDeployment $deployment * * @return null|SS_HTTPResponse */ protected function validateDeployment($deployment) { if (!$deployment || !$deployment->exists()) { return $this->getAPIResponse(['message' => 'This deployment does not exist'], 404); } if ($deployment->EnvironmentID != $this->environment->ID) { return $this->getAPIResponse(['message' => 'This deployment does not belong to the environment'], 403); } if (!$deployment->canView()) { return $this->getAPIResponse(['message' => 'You are not authorised to view this deployment'], 403); } return null; }