server = $server; $this->server->on('method:POST', [$this, 'httpPost']); } /** * We intercept this to handle POST requests on calendar homes. * * @param RequestInterface $request * @param ResponseInterface $response * * @return bool|void */ public function httpPost(RequestInterface $request, ResponseInterface $response) { $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); if (!$node instanceof CalendarHome) { return; } $requestBody = $request->getBodyAsString(); $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); if ($documentType !== '{' . self::NS_Nextcloud . '}enable-birthday-calendar') { return; } $owner = substr($node->getOwner(), 17); if ($owner !== $this->user->getUID()) { $this->server->httpResponse->setStatus(Http::STATUS_FORBIDDEN); return false; } $this->config->setUserValue($this->user->getUID(), 'dav', 'generateBirthdayCalendar', 'yes'); $this->birthdayService->syncUser($this->user->getUID()); $this->server->httpResponse->setStatus(Http::STATUS_NO_CONTENT); return false; } }