diff --git a/lib/Controller/AdminGroupController.php b/lib/Controller/AdminGroupController.php index e8edce0..700319e 100644 --- a/lib/Controller/AdminGroupController.php +++ b/lib/Controller/AdminGroupController.php @@ -117,6 +117,37 @@ public function setEnabled( return new DataResponse(); } + /** + * Change the email of admin of a group + * + * @param string $userId User ID of account that is admin of a group + * @param string $email New email + * @return DataResponse, array{}> + * + * 200: OK + * 401: Unauthorized + * 404: Group or email not found + */ + #[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/change-admin-email', requirements: ['apiVersion' => '(v1)'])] + #[AuthorizedAdminSetting(settings:Users::class)] + #[NoCSRFRequired] + #[RestrictIp] + public function changeAdminEmail( + string $userId, + string $email, + ): DataResponse { + $group = $this->groupManager->get($userId); + if (!$group instanceof IGroup) { + return new DataResponse([], Http::STATUS_NOT_FOUND); + } + $user = $this->userManager->get($userId); + if (!$user instanceof IUser) { + return new DataResponse([], Http::STATUS_NOT_FOUND); + } + $user->setSystemEMailAddress($email); + return new DataResponse(); + } + /** * Make a user a subadmin of a group * diff --git a/openapi.json b/openapi.json index 7dbb12b..d5e52ed 100644 --- a/openapi.json +++ b/openapi.json @@ -287,6 +287,130 @@ } } } + }, + "/ocs/v2.php/apps/admin_group_manager/api/{apiVersion}/change-admin-email": { + "post": { + "operationId": "admin_group-change-admin-email", + "summary": "Change the email of admin of a group", + "description": "This endpoint requires admin access", + "tags": [ + "admin_group" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "userId", + "email" + ], + "properties": { + "userId": { + "type": "string", + "description": "User ID of account that is admin of a group" + }, + "email": { + "type": "string", + "description": "New email" + } + } + } + } + } + }, + "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 or email 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 45f99f0..ae6391c 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -46,6 +46,26 @@ export type paths = { patch?: never; trace?: never; }; + "/ocs/v2.php/apps/admin_group_manager/api/{apiVersion}/change-admin-email": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + /** + * Change the email of admin of a group + * @description This endpoint requires admin access + */ + post: operations["admin_group-change-admin-email"]; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; }; export type webhooks = Record; export type components = { @@ -179,4 +199,57 @@ export interface operations { }; }; }; + "admin_group-change-admin-email": { + 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 User ID of account that is admin of a group */ + userId: string; + /** @description New email */ + email: string; + }; + }; + }; + responses: { + /** @description OK */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: unknown; + }; + }; + }; + }; + /** @description Group or email not found */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: unknown; + }; + }; + }; + }; + }; + }; }