88namespace OCA \DAV \Controller ;
99
1010use InvalidArgumentException ;
11+
12+ /**
13+ * @psalm-type CalendarImportResult = array{items: list<string>, total: non-negative-int}
14+ */
1115use OCA \DAV \AppInfo \Application ;
1216use OCA \DAV \CalDAV \CalendarImpl ;
1317use OCA \DAV \CalDAV \Import \ImportService ;
1418use OCP \AppFramework \Http ;
1519use OCP \AppFramework \Http \Attribute \ApiRoute ;
1620use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
17- use OCP \AppFramework \Http \Attribute \OpenAPI ;
1821use OCP \AppFramework \Http \Attribute \UserRateLimit ;
1922use OCP \AppFramework \Http \DataResponse ;
2023use 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 {
0 commit comments