1693 get workspace users api (#1694)

* Enhance API - add GET for users with access to workspace

Adds GET request endpoint for retrieving a list of users with permissions to access the specified workspace

* Update Swagger for users with access to workspace

Adds swagger docs for the endpoint used to retrieve users with access to workspace. "v1/admin/workspaces/:workspaceId/users"
This commit is contained in:
lewismacnow 2024-06-17 21:52:01 +01:00 committed by GitHub
parent 65093d99d8
commit 38441f4b21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 107 additions and 2 deletions

View File

@ -426,7 +426,60 @@ function apiAdminEndpoints(app) {
}
}
);
app.get(
"/v1/admin/workspaces/:workspaceId/users",
[validApiKey],
async (request, response) => {
/*
#swagger.tags = ['Admin']
#swagger.path = '/v1/admin/workspaces/{workspaceId}/users'
#swagger.parameters['workspaceId'] = {
in: 'path',
description: 'id of the workspace.',
required: true,
type: 'string'
}
#swagger.description = 'Retrieve a list of users with permissions to access the specified workspace.'
#swagger.responses[200] = {
content: {
"application/json": {
schema: {
type: 'object',
example: {
users: [
{"userId": 1, "role": "admin"},
{"userId": 2, "role": "member"}
]
}
}
}
}
}
#swagger.responses[403] = {
schema: {
"$ref": "#/definitions/InvalidAPIKey"
}
}
#swagger.responses[401] = {
description: "Instance is not in Multi-User mode. Method denied",
}
*/
try {
if (!multiUserMode(response)) {
response.sendStatus(401).end();
return;
}
const workspaceId = request.params.workspaceId;
const users = await Workspace.workspaceUsers(workspaceId);
response.status(200).json({ users });
} catch (e) {
console.error(e);
response.sendStatus(500).end();
}
});
app.post(
"/v1/admin/workspaces/:workspaceId/update-users",
[validApiKey],
@ -494,7 +547,6 @@ function apiAdminEndpoints(app) {
}
}
);
app.post(
"/v1/admin/workspace-chats",
[validApiKey],

View File

@ -502,6 +502,59 @@
}
}
},
"/v1/admin/workspaces/:workspaceId/users": {
"get": {
"tags": ["Admin"],
"description": "Retrieve a list of users for the given workspace.",
"parameters": [
{
"name": "workspaceId",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "The ID of the workspace whose users are to be retrieved."
}
],
"responses": {
"200": {
"description": "OK, successful operation. Returns a list of user IDs for the given workspace.",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {"type": "string"}
}
}
}
},
"401": {
"description": "Unauthorized, not authorized to access resources in multi-user mode.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/InvalidAPIKey"
}
}
}
},
"500": {
"description": "Internal Server Error",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {"type": "string"}
}
}
}
}
}
}
}
},
"/v1/admin/workspaces/{workspaceId}/update-users": {
"post": {
"tags": [
@ -2336,4 +2389,4 @@
"BearerAuth": []
}
]
}
}