Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Change email of admin of a group #15

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 44 additions & 31 deletions composer.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use OCP\AppFramework\OCSController;

abstract class AEnvironmentAwareController extends OCSController {
abstract class AEnvironmentAwareOCSController extends OCSController {
protected int $apiVersion = 1;

public function setAPIVersion(int $apiVersion): void {
Expand Down
33 changes: 32 additions & 1 deletion lib/Controller/AdminGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;

class AdminGroupController extends AEnvironmentAwareController {
class AdminGroupController extends AEnvironmentAwareOCSController {
public function __construct(
$appName,
IRequest $request,
Expand Down 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)]
#[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
6 changes: 3 additions & 3 deletions lib/Middleware/InjectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OCA\AdminGroupManager\Middleware;

use OCA\AdminGroupManager\Controller\AEnvironmentAwareController;
use OCA\AdminGroupManager\Controller\AEnvironmentAwareOCSController;
use OCA\AdminGroupManager\Controller\Attribute\RestrictIp;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
Expand All @@ -34,9 +34,9 @@ public function __construct(
* @throws \Exception
*/
public function beforeController(Controller $controller, string $methodName) {
if ($controller instanceof AEnvironmentAwareController) {
if ($controller instanceof AEnvironmentAwareOCSController) {
$apiVersion = $this->request->getParam('apiVersion');
/** @var AEnvironmentAwareController $controller */
/** @var AEnvironmentAwareOCSController $controller */
$controller->setAPIVersion((int)substr($apiVersion, 1));
}

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;
};
};
};
};
};
};
}
2 changes: 2 additions & 0 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
<InvalidArgument>
<code><![CDATA[Users::class]]></code>
<code><![CDATA[Users::class]]></code>
<code><![CDATA[Users::class]]></code>
</InvalidArgument>
<UndefinedClass>
<code><![CDATA[Users]]></code>
<code><![CDATA[Users]]></code>
<code><![CDATA[Users]]></code>
<code><![CDATA[\OC_Helper]]></code>
Expand Down
12 changes: 6 additions & 6 deletions vendor-bin/coding-standard/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading