Skip to content

Commit fe2c942

Browse files
fixup! feat: OCS Calendar Export + Import
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
1 parent 0d0df4d commit fe2c942

5 files changed

Lines changed: 78 additions & 39 deletions

File tree

apps/dav/lib/Controller/CalendarExportController.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,19 @@ public function __construct(
4343
*
4444
* @param string $id calendar id
4545
* @param string|null $type data format
46-
* @param array{rangeStart:string,rangeCount:int<1,max>} $options configuration options
46+
* @param array{rangeStart:string,rangeCount:positive-int} $options configuration options
4747
* @param string|null $user system user id
4848
*
49-
* @return StreamGeneratorResponse<Http::STATUS_OK, array{Content-Type:string}> | DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_UNAUTHORIZED, array{error?: non-empty-string}, array{}>
49+
* @return StreamGeneratorResponse<Http::STATUS_OK, array{Content-Type:'text/calendar; charset=UTF-8'|'application/calendar+json; charset=UTF-8'|'application/calendar+xml; charset=UTF-8'}> | DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_UNAUTHORIZED, array{error?: non-empty-string}, array{}>
5050
*
5151
* 200: data in requested format
5252
* 400: invalid parameters
5353
* 401: user not authorized
5454
*/
55-
#[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)]
5655
#[ApiRoute(verb: 'POST', url: '/export', root: '/calendar')]
57-
#[UserRateLimit(limit: 60, period: 60)]
56+
#[UserRateLimit(limit: 1, period: 60)]
5857
#[NoAdminRequired]
59-
public function index(string $id, ?string $type = null, ?array $options = null, ?string $user = null) {
60-
$userId = $user;
58+
public function export(string $id, ?string $type = null, ?array $options = null, ?string $user = null) {
6159
$calendarId = $id;
6260
$format = $type ?? 'ical';
6361
$rangeStart = isset($options['rangeStart']) ? (string)$options['rangeStart'] : null;
@@ -66,12 +64,12 @@ public function index(string $id, ?string $type = null, ?array $options = null,
6664
if (!$this->userSession->isLoggedIn()) {
6765
return new DataResponse([], Http::STATUS_UNAUTHORIZED);
6866
}
69-
if ($userId !== null) {
70-
if ($this->userSession->getUser()->getUID() !== $userId
67+
if ($user !== null) {
68+
if ($this->userSession->getUser()->getUID() !== $user
7169
&& $this->groupManager->isAdmin($this->userSession->getUser()->getUID()) === false) {
7270
return new DataResponse([], Http::STATUS_UNAUTHORIZED);
7371
}
74-
if (!$this->userManager->userExists($userId)) {
72+
if (!$this->userManager->userExists($user)) {
7573
return new DataResponse(['error' => 'user not found'], Http::STATUS_BAD_REQUEST);
7674
}
7775
} else {

apps/dav/lib/Controller/CalendarImportController.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
namespace OCA\DAV\Controller;
99

1010
use InvalidArgumentException;
11+
12+
/**
13+
* @psalm-type CalendarImportResult = array{items: list<string>, total: non-negative-int}
14+
*/
1115
use OCA\DAV\AppInfo\Application;
1216
use OCA\DAV\CalDAV\CalendarImpl;
1317
use OCA\DAV\CalDAV\Import\ImportService;
1418
use OCP\AppFramework\Http;
1519
use OCP\AppFramework\Http\Attribute\ApiRoute;
1620
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
17-
use OCP\AppFramework\Http\Attribute\OpenAPI;
1821
use OCP\AppFramework\Http\Attribute\UserRateLimit;
1922
use OCP\AppFramework\Http\DataResponse;
2023
use OCP\AppFramework\OCSController;
@@ -44,22 +47,20 @@ public function __construct(
4447
* Import calendar data
4548
*
4649
* @param string $id calendar id
47-
* @param array{format?:string, validation?:int<0,2>, errors?:int<0,1>, supersede?:bool, showCreated?:bool, showUpdated?:bool, showSkipped?:bool, showErrors?:bool} $options configuration options
50+
* @param array{format?:string, validation?:0|1|2, errors?:0|1, supersede?:bool, showCreated?:bool, showUpdated?:bool, showSkipped?:bool, showErrors?:bool} $options configuration options
4851
* @param string $data calendar data
4952
* @param string|null $user system user id
5053
*
51-
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST|Http::STATUS_UNAUTHORIZED|Http::STATUS_INTERNAL_SERVER_ERROR, array{error?: string, time?: float, created?: array{items: list<string>, total: int<0,max>}, updated?: array{items: list<string>, total: int<0,max>}, skipped?: array{items: list<string>, total: int<0, max>}, errors?: array{items: list<string>, total: int<0, max>}}, array{}>
54+
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST|Http::STATUS_UNAUTHORIZED|Http::STATUS_INTERNAL_SERVER_ERROR, array{error?: string, time?: float, created?: array{items: list<string>, total: non-negative-int}, updated?: array{items: list<string>, total: non-negative-int}, skipped?: array{items: list<string>, total: non-negative-int}, errors?: array{items: list<string>, total: non-negative-int}}, array{}>
5255
*
5356
* 200: calendar data
5457
* 400: invalid request
5558
* 401: user not authorized
5659
*/
57-
#[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)]
5860
#[ApiRoute(verb: 'POST', url: '/import', root: '/calendar')]
5961
#[UserRateLimit(limit: 1, period: 60)]
6062
#[NoAdminRequired]
61-
public function index(string $id, array $options, string $data, ?string $user = null): DataResponse {
62-
$userId = $user;
63+
public function import(string $id, array $options, string $data, ?string $user = null): DataResponse {
6364
$calendarId = $id;
6465
$format = isset($options['format']) ? $options['format'] : null;
6566
$validation = isset($options['validation']) ? (int)$options['validation'] : null;
@@ -73,12 +74,12 @@ public function index(string $id, array $options, string $data, ?string $user =
7374
if (!$this->userSession->isLoggedIn()) {
7475
return new DataResponse([], Http::STATUS_UNAUTHORIZED);
7576
}
76-
if ($userId !== null) {
77-
if ($this->userSession->getUser()->getUID() !== $userId
77+
if ($user !== null) {
78+
if ($this->userSession->getUser()->getUID() !== $user
7879
&& $this->groupManager->isAdmin($this->userSession->getUser()->getUID()) === false) {
7980
return new DataResponse([], Http::STATUS_UNAUTHORIZED);
8081
}
81-
if (!$this->userManager->userExists($userId)) {
82+
if (!$this->userManager->userExists($user)) {
8283
return new DataResponse(['error' => 'user not found'], Http::STATUS_BAD_REQUEST);
8384
}
8485
} else {

apps/dav/openapi.json

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@
11661166
},
11671167
"/ocs/v2.php/calendar/export": {
11681168
"post": {
1169-
"operationId": "calendar_export-index",
1169+
"operationId": "calendar_export-export",
11701170
"summary": "Export calendar data",
11711171
"tags": [
11721172
"calendar_export"
@@ -1243,7 +1243,24 @@
12431243
],
12441244
"responses": {
12451245
"200": {
1246-
"description": "data in requested format"
1246+
"description": "data in requested format",
1247+
"content": {
1248+
"text/calendar; charset=UTF-8": {
1249+
"schema": {
1250+
"anyOf": []
1251+
}
1252+
},
1253+
"application/calendar+json; charset=UTF-8": {
1254+
"schema": {
1255+
"anyOf": []
1256+
}
1257+
},
1258+
"application/calendar+xml; charset=UTF-8": {
1259+
"schema": {
1260+
"anyOf": []
1261+
}
1262+
}
1263+
}
12471264
},
12481265
"400": {
12491266
"description": "invalid parameters",
@@ -1347,7 +1364,7 @@
13471364
},
13481365
"/ocs/v2.php/calendar/import": {
13491366
"post": {
1350-
"operationId": "calendar_import-index",
1367+
"operationId": "calendar_import-import",
13511368
"summary": "Import calendar data",
13521369
"tags": [
13531370
"calendar_import"
@@ -1386,14 +1403,19 @@
13861403
"validation": {
13871404
"type": "integer",
13881405
"format": "int64",
1389-
"minimum": 0,
1390-
"maximum": 2
1406+
"enum": [
1407+
0,
1408+
1,
1409+
2
1410+
]
13911411
},
13921412
"errors": {
13931413
"type": "integer",
13941414
"format": "int64",
1395-
"minimum": 0,
1396-
"maximum": 1
1415+
"enum": [
1416+
0,
1417+
1
1418+
]
13971419
},
13981420
"supersede": {
13991421
"type": "boolean"

lib/public/AppFramework/Http/StreamGeneratorResponse.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
declare(strict_types=1);
44

55
/**
6-
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7-
* SPDX-License-Identifier: AGPL-3.0-only
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
88
*/
99
namespace OCP\AppFramework\Http;
1010

1111
use Generator;
1212
use OCP\AppFramework\Http;
1313

1414
/**
15-
* @since 32.0.0
15+
* @since 33.0.0
1616
*
1717
* @template S of Http::STATUS_*
1818
* @template H of array<string, mixed>
@@ -22,8 +22,6 @@ class StreamGeneratorResponse extends Response implements ICallbackResponse {
2222
protected $generator;
2323

2424
/**
25-
* @since 32.0.0
26-
*
2725
* @param Generator $generator the function to call to generate the response
2826
* @param string $contentType http response content type e.g. 'application/json; charset=UTF-8'
2927
* @param S $status http response status
@@ -45,8 +43,6 @@ public function __construct(Generator $generator, string $contentType, int $stat
4543
/**
4644
* Streams content directly to client
4745
*
48-
* @since 32.0.0
49-
*
5046
* @param IOutput $output a small wrapper that handles output
5147
*/
5248
public function callback(IOutput $output) {

openapi.json

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20194,7 +20194,7 @@
2019420194
},
2019520195
"/ocs/v2.php/calendar/export": {
2019620196
"post": {
20197-
"operationId": "dav-calendar_export-index",
20197+
"operationId": "dav-calendar_export-export",
2019820198
"summary": "Export calendar data",
2019920199
"tags": [
2020020200
"dav/calendar_export"
@@ -20271,7 +20271,24 @@
2027120271
],
2027220272
"responses": {
2027320273
"200": {
20274-
"description": "data in requested format"
20274+
"description": "data in requested format",
20275+
"content": {
20276+
"text/calendar; charset=UTF-8": {
20277+
"schema": {
20278+
"anyOf": []
20279+
}
20280+
},
20281+
"application/calendar+json; charset=UTF-8": {
20282+
"schema": {
20283+
"anyOf": []
20284+
}
20285+
},
20286+
"application/calendar+xml; charset=UTF-8": {
20287+
"schema": {
20288+
"anyOf": []
20289+
}
20290+
}
20291+
}
2027520292
},
2027620293
"400": {
2027720294
"description": "invalid parameters",
@@ -20375,7 +20392,7 @@
2037520392
},
2037620393
"/ocs/v2.php/calendar/import": {
2037720394
"post": {
20378-
"operationId": "dav-calendar_import-index",
20395+
"operationId": "dav-calendar_import-import",
2037920396
"summary": "Import calendar data",
2038020397
"tags": [
2038120398
"dav/calendar_import"
@@ -20414,14 +20431,19 @@
2041420431
"validation": {
2041520432
"type": "integer",
2041620433
"format": "int64",
20417-
"minimum": 0,
20418-
"maximum": 2
20434+
"enum": [
20435+
0,
20436+
1,
20437+
2
20438+
]
2041920439
},
2042020440
"errors": {
2042120441
"type": "integer",
2042220442
"format": "int64",
20423-
"minimum": 0,
20424-
"maximum": 1
20443+
"enum": [
20444+
0,
20445+
1
20446+
]
2042520447
},
2042620448
"supersede": {
2042720449
"type": "boolean"

0 commit comments

Comments
 (0)