0

feat(integerations): add route to get user details (#4030)

* feat(integerations): add route to get user details

* Commit updated API documentation

* test(integrations): implement unit test for get user details

---------

Co-authored-by: Owncast <owncast@owncast.online>
Co-authored-by: Gabe Kangas <gabek@real-ity.com>
This commit is contained in:
Varun Gujarathi 2024-11-26 14:30:33 -05:00 committed by GitHub
parent 2c2bf2b5bb
commit d135d2907a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 622 additions and 357 deletions

File diff suppressed because one or more lines are too long

View File

@ -3217,6 +3217,34 @@ paths:
responses:
'204':
$ref: '#/components/responses/204'
/integrations/moderation/chat/user/{userId}:
get:
summary: Get a user's details
operationId: ExternalGetUserDetails
tags: ['External', 'Chat']
security:
- BearerAuth: []
parameters:
- in: path
name: userId
schema:
type: string
description: The ID of the user to find
required: true
responses:
'200':
description: User information
content:
application/json:
schema:
$ref: '#/components/schemas/ModerationUserDetails'
'401':
$ref: '#/components/responses/401BasicAuth'
'404':
$ref: '#/components/responses/404'
default:
$ref: '#/components/responses/Default'
/moderation/chat/user/{userId}:
get:
summary: Get a user's details

View File

@ -3,6 +3,7 @@ request = request('http://127.0.0.1:8080');
const getAdminResponse = require('./lib/admin').getAdminResponse;
const sendAdminPayload = require('./lib/admin').sendAdminPayload;
const registerChat = require('./lib/chat').registerChat;
var accessToken = '';
var webhookID;
@ -126,6 +127,16 @@ test('test fetch chat history OPTIONS request', async () => {
.expect(204);
});
test('get user details', async () => {
const registration = await registerChat();
const userId = registration.id;
await request
.get(`/api/integrations/moderation/chat/user/${userId}`)
.set('Authorization', 'Bearer ' + accessToken)
.expect(200);
});
test('delete access token', async () => {
const res = await sendAdminPayload('accesstokens/delete', {
token: accessToken,

View File

@ -1,6 +1,6 @@
// Package generated provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.3.0 DO NOT EDIT.
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.4.1 DO NOT EDIT.
package generated
import (
@ -503,14 +503,6 @@ type StreamOutputVariant struct {
VideoPassthrough *bool `json:"videoPassthrough,omitempty"`
}
// SystemActionEvent defines model for SystemActionEvent.
type SystemActionEvent struct {
Body *string `json:"body,omitempty"`
Id *string `json:"id,omitempty"`
Timestamp *string `json:"timestamp,omitempty"`
Type *string `json:"type,omitempty"`
}
// SystemMessage defines model for SystemMessage.
type SystemMessage struct {
Body *string `json:"body,omitempty"`
@ -1088,16 +1080,16 @@ type RegisterAnonymousChatUserJSONRequestBody RegisterAnonymousChatUserJSONBody
type UpdateUserEnabledJSONRequestBody UpdateUserEnabledJSONBody
// SendChatActionJSONRequestBody defines body for SendChatAction for application/json ContentType.
type SendChatActionJSONRequestBody = SystemActionEvent
type SendChatActionJSONRequestBody = MessageEvent
// ExternalUpdateMessageVisibilityJSONRequestBody defines body for ExternalUpdateMessageVisibility for application/json ContentType.
type ExternalUpdateMessageVisibilityJSONRequestBody = MessageVisibilityUpdate
// SendIntegrationChatMessageJSONRequestBody defines body for SendIntegrationChatMessage for application/json ContentType.
type SendIntegrationChatMessageJSONRequestBody = UserMessage
type SendIntegrationChatMessageJSONRequestBody = MessageEvent
// SendSystemMessageJSONRequestBody defines body for SendSystemMessage for application/json ContentType.
type SendSystemMessageJSONRequestBody = SystemMessage
type SendSystemMessageJSONRequestBody = MessageEvent
// SendSystemMessageToConnectedClientJSONRequestBody defines body for SendSystemMessageToConnectedClient for application/json ContentType.
type SendSystemMessageToConnectedClientJSONRequestBody = SystemMessage

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,7 @@ import (
"github.com/owncast/owncast/models"
"github.com/owncast/owncast/webserver/handlers/admin"
"github.com/owncast/owncast/webserver/handlers/moderation"
"github.com/owncast/owncast/webserver/router/middleware"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
@ -67,6 +68,10 @@ func (*ServerInterfaceImpl) ExternalSetStreamTitleOptions(w http.ResponseWriter,
middleware.RequireExternalAPIAccessToken(models.ScopeHasAdminAccess, admin.ExternalSetStreamTitle)(w, r)
}
func (*ServerInterfaceImpl) ExternalGetUserDetails(w http.ResponseWriter, r *http.Request, userId string) {
middleware.RequireExternalAPIAccessToken(models.ScopeHasAdminAccess, moderation.ExternalGetUserDetails)(w, r)
}
func (*ServerInterfaceImpl) ExternalGetChatMessages(w http.ResponseWriter, r *http.Request) {
middleware.RequireExternalAPIAccessToken(models.ScopeHasAdminAccess, ExternalGetChatMessages)(w, r)
}

View File

@ -74,3 +74,7 @@ func GetUserDetails(w http.ResponseWriter, r *http.Request) {
utils.InternalErrorHandler(w, err)
}
}
func ExternalGetUserDetails(integration models.ExternalAPIUser, w http.ResponseWriter, r *http.Request) {
GetUserDetails(w, r)
}