Skip to content

Commit

Permalink
Merge pull request #6 from LibreSign/chore/disable-users
Browse files Browse the repository at this point in the history
feat: implement endpoint to change enabled status of all users of a group
  • Loading branch information
vitormattos authored Oct 10, 2024
2 parents 33a93e1 + a45c41a commit 12a0993
Show file tree
Hide file tree
Showing 4 changed files with 237 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 @@ -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<Http::STATUS_OK|Http::STATUS_NOT_FOUND, array<empty>, 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
*
Expand Down
127 changes: 127 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
Expand Down
77 changes: 77 additions & 0 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, never>;
export type components = {
Expand Down Expand Up @@ -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;
};
};
};
};
};
};
}
2 changes: 2 additions & 0 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
</FalsableReturnStatement>
<InvalidArgument>
<code><![CDATA[Users::class]]></code>
<code><![CDATA[Users::class]]></code>
</InvalidArgument>
<UndefinedClass>
<code><![CDATA[Users]]></code>
<code><![CDATA[Users]]></code>
<code><![CDATA[\OC_Helper]]></code>
</UndefinedClass>
Expand Down

0 comments on commit 12a0993

Please sign in to comment.