Skip to content

Commit

Permalink
feat: Change email of admin of a group
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Dec 6, 2024
1 parent 3706153 commit 59730bd
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/Controller/AdminGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Http::STATUS_OK|Http::STATUS_NOT_FOUND, list<empty>, 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)]

Check failure on line 132 in lib/Controller/AdminGroupController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedClass

lib/Controller/AdminGroupController.php:132:36: UndefinedClass: Class, interface or enum named OCA\Settings\Settings\Admin\Users does not exist (see https://psalm.dev/019)

Check failure on line 132 in lib/Controller/AdminGroupController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

InvalidArgument

lib/Controller/AdminGroupController.php:132:36: InvalidArgument: Argument 1 of OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting::__construct expects class-string<OCP\Settings\IDelegatedSettings>, but OCA\Settings\Settings\Admin\Users::class provided (see https://psalm.dev/004)
#[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
*
Expand Down
124 changes: 124 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
Expand Down
73 changes: 73 additions & 0 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, never>;
export type components = {
Expand Down Expand Up @@ -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;
};
};
};
};
};
};
}

0 comments on commit 59730bd

Please sign in to comment.