Skip to content

Commit 59730bd

Browse files
committed
feat: Change email of admin of a group
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 3706153 commit 59730bd

File tree

3 files changed

+228
-0
lines changed

3 files changed

+228
-0
lines changed

lib/Controller/AdminGroupController.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,37 @@ public function setEnabled(
117117
return new DataResponse();
118118
}
119119

120+
/**
121+
* Change the email of admin of a group
122+
*
123+
* @param string $userId User ID of account that is admin of a group
124+
* @param string $email New email
125+
* @return DataResponse<Http::STATUS_OK|Http::STATUS_NOT_FOUND, list<empty>, array{}>
126+
*
127+
* 200: OK
128+
* 401: Unauthorized
129+
* 404: Group or email not found
130+
*/
131+
#[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/change-admin-email', requirements: ['apiVersion' => '(v1)'])]
132+
#[AuthorizedAdminSetting(settings:Users::class)]
133+
#[NoCSRFRequired]
134+
#[RestrictIp]
135+
public function changeAdminEmail(
136+
string $userId,
137+
string $email,
138+
): DataResponse {
139+
$group = $this->groupManager->get($userId);
140+
if (!$group instanceof IGroup) {
141+
return new DataResponse([], Http::STATUS_NOT_FOUND);
142+
}
143+
$user = $this->userManager->get($userId);
144+
if (!$user instanceof IUser) {
145+
return new DataResponse([], Http::STATUS_NOT_FOUND);
146+
}
147+
$user->setSystemEMailAddress($email);
148+
return new DataResponse();
149+
}
150+
120151
/**
121152
* Make a user a subadmin of a group
122153
*

openapi.json

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,130 @@
287287
}
288288
}
289289
}
290+
},
291+
"/ocs/v2.php/apps/admin_group_manager/api/{apiVersion}/change-admin-email": {
292+
"post": {
293+
"operationId": "admin_group-change-admin-email",
294+
"summary": "Change the email of admin of a group",
295+
"description": "This endpoint requires admin access",
296+
"tags": [
297+
"admin_group"
298+
],
299+
"security": [
300+
{
301+
"bearer_auth": []
302+
},
303+
{
304+
"basic_auth": []
305+
}
306+
],
307+
"requestBody": {
308+
"required": true,
309+
"content": {
310+
"application/json": {
311+
"schema": {
312+
"type": "object",
313+
"required": [
314+
"userId",
315+
"email"
316+
],
317+
"properties": {
318+
"userId": {
319+
"type": "string",
320+
"description": "User ID of account that is admin of a group"
321+
},
322+
"email": {
323+
"type": "string",
324+
"description": "New email"
325+
}
326+
}
327+
}
328+
}
329+
}
330+
},
331+
"parameters": [
332+
{
333+
"name": "apiVersion",
334+
"in": "path",
335+
"required": true,
336+
"schema": {
337+
"type": "string",
338+
"enum": [
339+
"v1"
340+
],
341+
"default": "v1"
342+
}
343+
},
344+
{
345+
"name": "OCS-APIRequest",
346+
"in": "header",
347+
"description": "Required to be true for the API request to pass",
348+
"required": true,
349+
"schema": {
350+
"type": "boolean",
351+
"default": true
352+
}
353+
}
354+
],
355+
"responses": {
356+
"200": {
357+
"description": "OK",
358+
"content": {
359+
"application/json": {
360+
"schema": {
361+
"type": "object",
362+
"required": [
363+
"ocs"
364+
],
365+
"properties": {
366+
"ocs": {
367+
"type": "object",
368+
"required": [
369+
"meta",
370+
"data"
371+
],
372+
"properties": {
373+
"meta": {
374+
"$ref": "#/components/schemas/OCSMeta"
375+
},
376+
"data": {}
377+
}
378+
}
379+
}
380+
}
381+
}
382+
}
383+
},
384+
"404": {
385+
"description": "Group or email not found",
386+
"content": {
387+
"application/json": {
388+
"schema": {
389+
"type": "object",
390+
"required": [
391+
"ocs"
392+
],
393+
"properties": {
394+
"ocs": {
395+
"type": "object",
396+
"required": [
397+
"meta",
398+
"data"
399+
],
400+
"properties": {
401+
"meta": {
402+
"$ref": "#/components/schemas/OCSMeta"
403+
},
404+
"data": {}
405+
}
406+
}
407+
}
408+
}
409+
}
410+
}
411+
}
412+
}
413+
}
290414
}
291415
},
292416
"tags": []

src/types/openapi/openapi.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ export type paths = {
4646
patch?: never;
4747
trace?: never;
4848
};
49+
"/ocs/v2.php/apps/admin_group_manager/api/{apiVersion}/change-admin-email": {
50+
parameters: {
51+
query?: never;
52+
header?: never;
53+
path?: never;
54+
cookie?: never;
55+
};
56+
get?: never;
57+
put?: never;
58+
/**
59+
* Change the email of admin of a group
60+
* @description This endpoint requires admin access
61+
*/
62+
post: operations["admin_group-change-admin-email"];
63+
delete?: never;
64+
options?: never;
65+
head?: never;
66+
patch?: never;
67+
trace?: never;
68+
};
4969
};
5070
export type webhooks = Record<string, never>;
5171
export type components = {
@@ -179,4 +199,57 @@ export interface operations {
179199
};
180200
};
181201
};
202+
"admin_group-change-admin-email": {
203+
parameters: {
204+
query?: never;
205+
header: {
206+
/** @description Required to be true for the API request to pass */
207+
"OCS-APIRequest": boolean;
208+
};
209+
path: {
210+
apiVersion: "v1";
211+
};
212+
cookie?: never;
213+
};
214+
requestBody: {
215+
content: {
216+
"application/json": {
217+
/** @description User ID of account that is admin of a group */
218+
userId: string;
219+
/** @description New email */
220+
email: string;
221+
};
222+
};
223+
};
224+
responses: {
225+
/** @description OK */
226+
200: {
227+
headers: {
228+
[name: string]: unknown;
229+
};
230+
content: {
231+
"application/json": {
232+
ocs: {
233+
meta: components["schemas"]["OCSMeta"];
234+
data: unknown;
235+
};
236+
};
237+
};
238+
};
239+
/** @description Group or email not found */
240+
404: {
241+
headers: {
242+
[name: string]: unknown;
243+
};
244+
content: {
245+
"application/json": {
246+
ocs: {
247+
meta: components["schemas"]["OCSMeta"];
248+
data: unknown;
249+
};
250+
};
251+
};
252+
};
253+
};
254+
};
182255
}

0 commit comments

Comments
 (0)