Cancel a data request.

@since Moodle 3.5
@param int $requestid The request ID.
@return array
@throws invalid_persistent_exception
@throws coding_exception
@throws invalid_parameter_exception
@throws restricted_context_exception
334750
public static function cancel_data_request($requestid) {
        global $USER;

        $warnings = [];
        $params = external_api::validate_parameters(self::cancel_data_request_parameters(), [
            'requestid' => $requestid
        ]);
        $requestid = $params['requestid'];

        // Validate context and access to manage the registry.
        $context = context_user::instance($USER->id);
        self::validate_context($context);

        // Ensure the request exists.
        $select = 'id = :id AND (userid = :userid OR requestedby = :requestedby)';
        $params = ['id' => $requestid, 'userid' => $USER->id, 'requestedby' => $USER->id];
        $requests = data_request::get_records_select($select, $params);
        $requestexists = count($requests) === 1;

        $result = false;
        if ($requestexists) {
            $request = reset($requests);
            $datasubject = $request->get('userid');

            if ($datasubject !== $USER->id) {
                // The user is not the subject. Check that they can cancel this request.
                if (!api::can_create_data_request_for_user($datasubject)) {
                    $forusercontext = \context_user::instance($datasubject);
                    throw new required_capability_exception($forusercontext,
                            'tool/dataprivacy:makedatarequestsforchildren', 'nopermissions', '');
                }
            }

            // TODO: Do we want a request to be non-cancellable past a certain point? E.g. When it's already approved/processing.
            $result = api::update_request_status($requestid, api::DATAREQUEST_STATUS_CANCELLED);
        } else {
            $warnings[] = [
                'item' => $requestid,
                'warningcode' => 'errorrequestnotfound',
                'message' => get_string('errorrequestnotfound', 'tool_dataprivacy')
            ];
        }

        return [
            'result' => $result,
            'warnings' => $warnings
        ];
    }
1356442
@com.fasterxml.jackson.annotation.JsonProperty("RequestId")
    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }
636430
public static function cancel($id, $params = null, $options = null)
    {
        $url = static::classUrl().'/'.$id;
        if (empty($params)) {
            $params = ['status' => 'canceled'];
        } else {
            $params = array_merge($params, ['status' => 'canceled']);
        }
        return static::_directRequest('put', $url, $params, $options);
    }
699134
public function abort($transactionId = null)
    {
        return $this->client->sendFrame($this->getProtocol()->getAbortFrame($transactionId));
    }
1210283
public function allowsRequestMethod($requestMethod) {

		return empty($this->requestMethods) || in_array(strtoupper($requestMethod), $this->requestMethods);

	}
766314
public function setRequestMode($requestMode)
    {
        if (null !== $requestMode && (self::REQUEST_MODE_ASYNCHRONOUS !== $requestMode && self::REQUEST_MODE_SYNCHRONOUS !== $requestMode)) {
            throw new \InvalidArgumentException("invalid mode [{$requestMode}], expecting one of self::REQUEST_MODE_*");
        }
        $this->requestMode = $requestMode;
    }
545677
public static function user_competency_cancel_review_request($userid, $competencyid) {
        static::require_enabled();
        $context = context_user::instance($userid);
        $uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
        if (!$uc || !$uc->can_read()) {
            throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
        } else if ($uc->get('status') != user_competency::STATUS_WAITING_FOR_REVIEW) {
            throw new coding_exception('The competency can not be cancel review request at this stage.');
        } else if (!$uc->can_request_review()) {
            throw new required_capability_exception($context, 'moodle/competency:usercompetencyrequestreview', 'nopermissions', '');
        }

        $uc->set('status', user_competency::STATUS_IDLE);
        $result = $uc->update();
        if ($result) {
            \core\event\competency_user_competency_review_request_cancelled::create_from_user_competency($uc)->trigger();
        }
        return $result;
    }
1123747
public function execute($uri, $requestMethod)
    {
        foreach ($this->routes as $route) {
            if (true === $route->matches($uri, $requestMethod)) {
                return $route;
            }
        }
        return null;
    }
724817
private function dispatchRequest(int $requestId): int
    {
        $request = new Request(
            $this->requests[$requestId]['params'],
            $this->requests[$requestId]['stdin']
        );

        try {
            $response = $this->kernel->handleRequest($request);
        } finally {
            $request->cleanUploadedFiles();
        }

        if ($response instanceof ResponseInterface) {
            $this->sendResponse($requestId, $response);
        } elseif ($response instanceof HttpFoundationResponse) {
            $this->sendHttpFoundationResponse($requestId, $response);
        } else {
            throw new \LogicException('Kernel must return a PSR-7 or HttpFoundation response message');
        }

        $this->endRequest($requestId);

        // This method exists on PSR-7 and Symfony responses
        return $response->getStatusCode();
    }
342473
public function processResponse($requestId = null)
    {
        $this->_errors = array();
        $this->_errorReason = null;
        if (isset($_POST) && isset($_POST['SAMLResponse'])) {
            // AuthnResponse -- HTTP_POST Binding
            $response = new OneLogin_Saml2_Response($this->_settings, $_POST['SAMLResponse']);
            $this->_lastResponse = $response->getXMLDocument();

            if ($response->isValid($requestId)) {
                $this->_attributes = $response->getAttributes();
                $this->_attributesWithFriendlyName = $response->getAttributesWithFriendlyName();
                $this->_nameid = $response->getNameId();
                $this->_nameidFormat = $response->getNameIdFormat();
                $this->_nameidNameQualifier = $response->getNameIdNameQualifier();
                $this->_authenticated = true;
                $this->_sessionIndex = $response->getSessionIndex();
                $this->_sessionExpiration = $response->getSessionNotOnOrAfter();
                $this->_lastMessageId = $response->getId();
                $this->_lastAssertionId = $response->getAssertionId();
                $this->_lastAssertionNotOnOrAfter = $response->getAssertionNotOnOrAfter();
            } else {
                $this->_errors[] = 'invalid_response';
                $this->_errorReason = $response->getError();
            }
        } else {
            $this->_errors[] = 'invalid_binding';
            throw new OneLogin_Saml2_Error(
                'SAML Response not found, Only supported HTTP_POST Binding',
                OneLogin_Saml2_Error::SAML_RESPONSE_NOT_FOUND
            );
        }
    }
1189208
public function cancelPayment($orderUuid)
    {
        $request = $this
            ->apiRequestFactory
            ->createCancelPaymentRequest($orderUuid);

        return $this->send($request);
    }
885696
public function cancelDraftAction(Request $request, $id = null)
    {
        /** @var $draftPage PageInterface */
        $draftPage = $this->admin->getObject($id);

        if (!$draftPage) {
            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
        }

        if (false === $this->admin->isGranted('EDIT', $draftPage)) {
            throw new AccessDeniedException();
        }

        if ($request->getMethod() == 'POST') {
            $pageManager = $this->get('networking_init_cms.page_manager');
            $serializer = $this->get('jms_serializer');

            $publishedPage = $pageManager->revertToPublished($draftPage, $serializer);

            if ($request->isXmlHttpRequest()) {
                $form = $this->admin->getForm();
                $form->setData($publishedPage);

                $pageSettingsTemplate = $this->render(
                    $this->admin->getTemplate('edit'),
                    [
                        'action' => 'edit',
                        'form' => $form->createView(),
                        'object' => $publishedPage,
                    ]
                );

                return $this->renderJson(
                    [
                        'result' => 'ok',
                        'objectId' => $this->admin->getNormalizedIdentifier($publishedPage),
                        'title' => $publishedPage->__toString(),
                        'pageStatus' => $this->translate($publishedPage->getStatus()),
                        'pageSettings' => $pageSettingsTemplate->getContent(),
                    ]
                );
            }

            return $this->redirect($this->admin->generateObjectUrl('edit', $publishedPage));
        }

        return $this->renderWithExtraParams(
            '@NetworkingInitCms/PageAdmin/page_cancel_draft.html.twig',
            [
                'action' => 'cancelDraft',
                'page' => $draftPage,
                'admin' => $this->admin,
            ]
        );
    }
1132301
public function deleteById(string $modelId)
    {
        $deleteResult = $this->getRequest()->request(
            'DELETE',
            $this->getRequestUrl(sprintf('models/%s', $modelId))
        );

        return $deleteResult['status'];
    }
103268
public function cancel(string $id, bool $atPeriodEnd)
    {
        // Log Debug
        $this->flow->getLogger()->debug("Cancelling Subscription $id" . ($atPeriodEnd ? ' at period end.' : '.'));

        return $this->make(
            $this->flow->send(
                'post',
                $this->endpoint . '/cancel',
                [
                    'subscriptionId' => $id,
                    'at_period_end' => (int) $atPeriodEnd,
                ]
            )
        );
    }
507283
def cancelRequest(self, requestId, reason=None, _=None):
        
        if reason is None:
            reason = CancelledError()
        tReq = self.requests.pop(requestId)
        tReq.d.errback(reason)
683151
public static function cancel($orderId)
    {
        $url = static::classUrl();
        $url = $url . '/' . $orderId . '/cancel';
        list($ret, $code) = parent::staticRequest('post', $url, []);

        return (object)[
            'code' => $code,
            'status' => $code === 200? 'success' : 'failed'
        ];
    }
807410
public function setRequestData($requestData)
    {
        if (is_array($requestData)) {
            $this->requestData = http_build_query($requestData);
        } else {
            $this->requestData = $requestData;
        }
        return $this;
    }