diff --git a/appinfo/routes.php b/appinfo/routes.php index 4ac70227a..71033f29a 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -31,8 +31,6 @@ ['name' => 'Endpoint#confirmIdsForUser', 'url' => '/api/{apiVersion}/notifications/exists', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v1|v2)']], ['name' => 'Endpoint#deleteNotification', 'url' => '/api/{apiVersion}/notifications/{id}', 'verb' => 'DELETE', 'requirements' => ['apiVersion' => '(v1|v2)', 'id' => '\d+']], ['name' => 'Endpoint#deleteAllNotifications', 'url' => '/api/{apiVersion}/notifications', 'verb' => 'DELETE', 'requirements' => ['apiVersion' => '(v1|v2)']], - ['name' => 'Push#registerDevice', 'url' => '/api/{apiVersion}/push', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']], - ['name' => 'Push#removeDevice', 'url' => '/api/{apiVersion}/push', 'verb' => 'DELETE', 'requirements' => ['apiVersion' => '(v2)']], ['name' => 'API#generateNotification', 'url' => '/api/{apiVersion}/admin_notifications/{userId}', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v1|v2)']], diff --git a/lib/Controller/PushController.php b/lib/Controller/PushController.php index 1129548ed..1c8dde3af 100644 --- a/lib/Controller/PushController.php +++ b/lib/Controller/PushController.php @@ -30,6 +30,8 @@ use OC\Security\IdentityProof\Manager; use OCA\Notifications\ResponseDefinitions; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\ApiRoute; +use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\OpenAPI; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; @@ -79,8 +81,6 @@ public function __construct(string $appName, } /** - * @NoAdminRequired - * * Register device for push notifications * * @param string $pushTokenHash Hash of the push token @@ -93,6 +93,8 @@ public function __construct(string $appName, * 400: Registering device is not possible * 401: Missing permissions to register device */ + #[NoAdminRequired] + #[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/push', requirements: ['apiVersion' => '(v2)'])] public function registerDevice(string $pushTokenHash, string $devicePublicKey, string $proxyServer): DataResponse { $user = $this->userSession->getUser(); if (!$user instanceof IUser) { @@ -163,8 +165,6 @@ public function registerDevice(string $pushTokenHash, string $devicePublicKey, s } /** - * @NoAdminRequired - * * Remove a device from push notifications * * @return DataResponse, array{}>|DataResponse @@ -174,6 +174,8 @@ public function registerDevice(string $pushTokenHash, string $devicePublicKey, s * 400: Removing device is not possible * 401: Missing permissions to remove device */ + #[NoAdminRequired] + #[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/push', requirements: ['apiVersion' => '(v2)'])] public function removeDevice(): DataResponse { $user = $this->userSession->getUser(); if (!$user instanceof IUser) { diff --git a/openapi-full.json b/openapi-full.json index f3dd138df..a301d0b19 100644 --- a/openapi-full.json +++ b/openapi-full.json @@ -902,12 +902,13 @@ } } }, - "/ocs/v2.php/apps/notifications/api/{apiVersion}/push": { + "/ocs/v2.php/apps/notifications/api/{apiVersion}/admin_notifications/{userId}": { "post": { - "operationId": "push-register-device", - "summary": "Register device for push notifications", + "operationId": "api-generate-notification", + "summary": "Generate a notification for a user", + "description": "This endpoint requires admin access", "tags": [ - "push" + "api" ], "security": [ { @@ -919,30 +920,21 @@ ], "parameters": [ { - "name": "pushTokenHash", - "in": "query", - "description": "Hash of the push token", - "required": true, - "schema": { - "type": "string" - } - }, - { - "name": "devicePublicKey", + "name": "shortMessage", "in": "query", - "description": "Public key of the device", + "description": "Subject of the notification", "required": true, "schema": { "type": "string" } }, { - "name": "proxyServer", + "name": "longMessage", "in": "query", - "description": "Proxy server to be used", - "required": true, + "description": "Message of the notification", "schema": { - "type": "string" + "type": "string", + "default": "" } }, { @@ -952,11 +944,21 @@ "schema": { "type": "string", "enum": [ + "v1", "v2" ], "default": "v2" } }, + { + "name": "userId", + "in": "path", + "description": "ID of the user", + "required": true, + "schema": { + "type": "string" + } + }, { "name": "OCS-APIRequest", "in": "header", @@ -970,7 +972,7 @@ ], "responses": { "200": { - "description": "Device was already registered", + "description": "Notification generated successfully", "content": { "application/json": { "schema": { @@ -989,9 +991,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "$ref": "#/components/schemas/PushDevice" - } + "data": {} } } } @@ -999,8 +999,8 @@ } } }, - "201": { - "description": "Device registered successfully", + "400": { + "description": "Generating notification is not possible", "content": { "application/json": { "schema": { @@ -1020,7 +1020,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "$ref": "#/components/schemas/PushDevice" + "nullable": true } } } @@ -1029,8 +1029,8 @@ } } }, - "400": { - "description": "Registering device is not possible", + "404": { + "description": "User not found", "content": { "application/json": { "schema": { @@ -1050,15 +1050,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "type": "object", - "required": [ - "message" - ], - "properties": { - "message": { - "type": "string" - } - } + "nullable": true } } } @@ -1067,8 +1059,8 @@ } } }, - "401": { - "description": "Missing permissions to register device", + "500": { + "description": "", "content": { "application/json": { "schema": { @@ -1087,7 +1079,9 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "nullable": true + } } } } @@ -1096,12 +1090,15 @@ } } } - }, - "delete": { - "operationId": "push-remove-device", - "summary": "Remove a device from push notifications", + } + }, + "/ocs/v2.php/apps/notifications/api/{apiVersion}/settings/admin": { + "post": { + "operationId": "settings-admin", + "summary": "Update default notification settings for new users", + "description": "This endpoint requires admin access", "tags": [ - "push" + "settings" ], "security": [ { @@ -1112,6 +1109,34 @@ } ], "parameters": [ + { + "name": "batchSetting", + "in": "query", + "description": "How often E-mails about missed notifications should be sent (hourly: 1; every three hours: 2; daily: 3; weekly: 4)", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + }, + { + "name": "soundNotification", + "in": "query", + "description": "Enable sound for notifications ('yes' or 'no')", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "soundTalk", + "in": "query", + "description": "Enable sound for Talk notifications ('yes' or 'no')", + "required": true, + "schema": { + "type": "string" + } + }, { "name": "apiVersion", "in": "path", @@ -1137,7 +1162,7 @@ ], "responses": { "200": { - "description": "No device registered", + "description": "Admin settings updated", "content": { "application/json": { "schema": { @@ -1163,9 +1188,79 @@ } } } + } + } + } + }, + "/ocs/v2.php/apps/notifications/api/{apiVersion}/push": { + "post": { + "operationId": "push-register-device", + "summary": "Register device for push notifications", + "tags": [ + "push" + ], + "security": [ + { + "bearer_auth": [] }, - "202": { - "description": "Device removed successfully", + { + "basic_auth": [] + } + ], + "parameters": [ + { + "name": "pushTokenHash", + "in": "query", + "description": "Hash of the push token", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "devicePublicKey", + "in": "query", + "description": "Public key of the device", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "proxyServer", + "in": "query", + "description": "Proxy server to be used", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "apiVersion", + "in": "path", + "required": true, + "schema": { + "type": "string", + "enum": [ + "v2" + ], + "default": "v2" + } + }, + { + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, + "schema": { + "type": "boolean", + "default": true + } + } + ], + "responses": { + "200": { + "description": "Device was already registered", "content": { "application/json": { "schema": { @@ -1184,7 +1279,9 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "$ref": "#/components/schemas/PushDevice" + } } } } @@ -1192,8 +1289,8 @@ } } }, - "401": { - "description": "Missing permissions to remove device", + "201": { + "description": "Device registered successfully", "content": { "application/json": { "schema": { @@ -1212,7 +1309,9 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "$ref": "#/components/schemas/PushDevice" + } } } } @@ -1221,7 +1320,7 @@ } }, "400": { - "description": "Removing device is not possible", + "description": "Registering device is not possible", "content": { "application/json": { "schema": { @@ -1257,17 +1356,42 @@ } } } + }, + "401": { + "description": "Missing permissions to register device", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": {} + } + } + } + } + } + } } } - } - }, - "/ocs/v2.php/apps/notifications/api/{apiVersion}/admin_notifications/{userId}": { - "post": { - "operationId": "api-generate-notification", - "summary": "Generate a notification for a user", - "description": "This endpoint requires admin access", + }, + "delete": { + "operationId": "push-remove-device", + "summary": "Remove a device from push notifications", "tags": [ - "api" + "push" ], "security": [ { @@ -1278,24 +1402,6 @@ } ], "parameters": [ - { - "name": "shortMessage", - "in": "query", - "description": "Subject of the notification", - "required": true, - "schema": { - "type": "string" - } - }, - { - "name": "longMessage", - "in": "query", - "description": "Message of the notification", - "schema": { - "type": "string", - "default": "" - } - }, { "name": "apiVersion", "in": "path", @@ -1303,21 +1409,11 @@ "schema": { "type": "string", "enum": [ - "v1", "v2" ], "default": "v2" } }, - { - "name": "userId", - "in": "path", - "description": "ID of the user", - "required": true, - "schema": { - "type": "string" - } - }, { "name": "OCS-APIRequest", "in": "header", @@ -1331,7 +1427,7 @@ ], "responses": { "200": { - "description": "Notification generated successfully", + "description": "No device registered", "content": { "application/json": { "schema": { @@ -1358,8 +1454,8 @@ } } }, - "400": { - "description": "Generating notification is not possible", + "202": { + "description": "Device removed successfully", "content": { "application/json": { "schema": { @@ -1378,9 +1474,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "nullable": true - } + "data": {} } } } @@ -1388,8 +1482,8 @@ } } }, - "404": { - "description": "User not found", + "401": { + "description": "Missing permissions to remove device", "content": { "application/json": { "schema": { @@ -1408,9 +1502,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "nullable": true - } + "data": {} } } } @@ -1418,8 +1510,8 @@ } } }, - "500": { - "description": "", + "400": { + "description": "Removing device is not possible", "content": { "application/json": { "schema": { @@ -1439,7 +1531,15 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "nullable": true + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string" + } + } } } } @@ -1450,106 +1550,6 @@ } } } - }, - "/ocs/v2.php/apps/notifications/api/{apiVersion}/settings/admin": { - "post": { - "operationId": "settings-admin", - "summary": "Update default notification settings for new users", - "description": "This endpoint requires admin access", - "tags": [ - "settings" - ], - "security": [ - { - "bearer_auth": [] - }, - { - "basic_auth": [] - } - ], - "parameters": [ - { - "name": "batchSetting", - "in": "query", - "description": "How often E-mails about missed notifications should be sent (hourly: 1; every three hours: 2; daily: 3; weekly: 4)", - "required": true, - "schema": { - "type": "integer", - "format": "int64" - } - }, - { - "name": "soundNotification", - "in": "query", - "description": "Enable sound for notifications ('yes' or 'no')", - "required": true, - "schema": { - "type": "string" - } - }, - { - "name": "soundTalk", - "in": "query", - "description": "Enable sound for Talk notifications ('yes' or 'no')", - "required": true, - "schema": { - "type": "string" - } - }, - { - "name": "apiVersion", - "in": "path", - "required": true, - "schema": { - "type": "string", - "enum": [ - "v2" - ], - "default": "v2" - } - }, - { - "name": "OCS-APIRequest", - "in": "header", - "description": "Required to be true for the API request to pass", - "required": true, - "schema": { - "type": "boolean", - "default": true - } - } - ], - "responses": { - "200": { - "description": "Admin settings updated", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": {} - } - } - } - } - } - } - } - } - } } }, "tags": [] diff --git a/tests/Unit/AppInfo/RoutesTest.php b/tests/Unit/AppInfo/RoutesTest.php index 494df8b80..96d2ded74 100644 --- a/tests/Unit/AppInfo/RoutesTest.php +++ b/tests/Unit/AppInfo/RoutesTest.php @@ -37,6 +37,6 @@ public function testRoutes() { $this->assertCount(1, $routes); $this->assertArrayHasKey('ocs', $routes); $this->assertIsArray($routes['ocs']); - $this->assertCount(10, $routes['ocs']); + $this->assertCount(8, $routes['ocs']); } } diff --git a/vendor-bin/openapi-extractor/composer.lock b/vendor-bin/openapi-extractor/composer.lock index 18f1ccef8..e6c94e495 100644 --- a/vendor-bin/openapi-extractor/composer.lock +++ b/vendor-bin/openapi-extractor/composer.lock @@ -82,12 +82,12 @@ "source": { "type": "git", "url": "https://github.com/nextcloud/openapi-extractor.git", - "reference": "6283132e51a756d657bd991bac6363bc2d2065e6" + "reference": "e15283dc655436460c531ce286b7f0bae3e0bf31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud/openapi-extractor/zipball/6283132e51a756d657bd991bac6363bc2d2065e6", - "reference": "6283132e51a756d657bd991bac6363bc2d2065e6", + "url": "https://api.github.com/repos/nextcloud/openapi-extractor/zipball/e15283dc655436460c531ce286b7f0bae3e0bf31", + "reference": "e15283dc655436460c531ce286b7f0bae3e0bf31", "shasum": "" }, "require": { @@ -129,7 +129,7 @@ "source": "https://github.com/nextcloud/openapi-extractor/tree/main", "issues": "https://github.com/nextcloud/openapi-extractor/issues" }, - "time": "2024-01-29T13:55:56+00:00" + "time": "2024-02-21T11:05:43+00:00" }, { "name": "nikic/php-parser",