diff --git a/lib/Controller/AdminGroupController.php b/lib/Controller/AdminGroupController.php index 032e373..05f1a2b 100644 --- a/lib/Controller/AdminGroupController.php +++ b/lib/Controller/AdminGroupController.php @@ -75,6 +75,37 @@ public function createAdminGroup( return new DataResponse(); } + /** + * Set enabled status + * + * Change the status of all users of a group to be enabled or not. + * + * @param string $groupid ID of the group + * @param int<0, 1> $enabled 1 or 0 + * @return DataResponse, array{}> + * + * 200: OK + * 401: Unauthorized + * 404: Group not found + */ + #[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/users-of-group/set-enabled', requirements: ['apiVersion' => '(v1)'])] + #[AuthorizedAdminSetting(settings:Users::class)] + #[RestrictIp] + public function setEnabled( + string $groupid, + int $enabled, + ): DataResponse { + $group = $this->groupManager->get($groupid); + if (!$group instanceof IGroup) { + return new DataResponse([], Http::STATUS_NOT_FOUND); + } + $users = $group->getUsers(); + foreach ($users as $user) { + $user->setEnabled((bool)$enabled); + } + return new DataResponse(); + } + /** * Make a user a subadmin of a group * diff --git a/openapi.json b/openapi.json index 1f98b5b..90fdf49 100644 --- a/openapi.json +++ b/openapi.json @@ -155,6 +155,133 @@ } } } + }, + "/ocs/v2.php/apps/admin_group_manager/api/{apiVersion}/users-of-group/set-enabled": { + "post": { + "operationId": "admin_group-set-enabled", + "summary": "Set enabled status", + "description": "Change the status of all users of a group to be enabled or not.\nThis endpoint requires admin access", + "tags": [ + "admin_group" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "groupid", + "enabled" + ], + "properties": { + "groupid": { + "type": "string", + "description": "ID of the group" + }, + "enabled": { + "type": "integer", + "format": "int64", + "description": "1 or 0", + "minimum": 0, + "maximum": 1 + } + } + } + } + } + }, + "parameters": [ + { + "name": "apiVersion", + "in": "path", + "required": true, + "schema": { + "type": "string", + "enum": [ + "v1" + ], + "default": "v1" + } + }, + { + "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": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": {} + } + } + } + } + } + } + }, + "404": { + "description": "Group not found", + "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/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index 103696a..5d4f39a 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -25,6 +25,27 @@ export type paths = { patch?: never; trace?: never; }; + "/ocs/v2.php/apps/admin_group_manager/api/{apiVersion}/users-of-group/set-enabled": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + /** + * Set enabled status + * @description Change the status of all users of a group to be enabled or not. + * This endpoint requires admin access + */ + post: operations["admin_group-set-enabled"]; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; }; export type webhooks = Record; export type components = { @@ -97,4 +118,60 @@ export interface operations { }; }; }; + "admin_group-set-enabled": { + parameters: { + query?: never; + header: { + /** @description Required to be true for the API request to pass */ + "OCS-APIRequest": boolean; + }; + path: { + apiVersion: "v1"; + }; + cookie?: never; + }; + requestBody: { + content: { + "application/json": { + /** @description ID of the group */ + groupid: string; + /** + * Format: int64 + * @description 1 or 0 + */ + enabled: number; + }; + }; + }; + responses: { + /** @description OK */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: unknown; + }; + }; + }; + }; + /** @description Group not found */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: unknown; + }; + }; + }; + }; + }; + }; } diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 3603e55..032e3d1 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -6,8 +6,10 @@ + +