ApprovalsDispatcher::cancel PHP Method

cancel() public method

public cancel ( SS_HTTPRequest $request ) : SS_HTTPResponse
$request SS_HTTPRequest
return SS_HTTPResponse
    public function cancel(\SS_HTTPRequest $request)
    {
        if ($request->httpMethod() !== 'POST') {
            return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405);
        }
        $this->checkSecurityToken();
        $deployment = \DNDeployment::get()->byId($request->postVar('id'));
        $errorResponse = $this->validateDeployment($deployment);
        if ($errorResponse instanceof \SS_HTTPResponse) {
            return $errorResponse;
        }
        // if the person cancelling is not the one who created the deployment, update the deployer
        if (\Member::currentUserID() !== $deployment->DeployerID) {
            $deployment->DeployerID = \Member::currentUserID();
        }
        try {
            $deployment->getMachine()->apply(\DNDeployment::TR_NEW);
        } catch (\Exception $e) {
            return $this->getAPIResponse(['message' => $e->getMessage()], 400);
        }
        return $this->getAPIResponse(['message' => 'Deployment request has been cancelled', 'deployment' => $this->formatter->getDeploymentData($deployment)], 200);
    }