diff options
author | techknowlogick <techknowlogick@gitea.io> | 2023-03-14 03:54:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 03:54:40 -0400 |
commit | d56bb7420184c0c2f451f4bcaa96c9b3b00c393d (patch) | |
tree | dcf3c0f696d2142e330d3d07b005db0bae8bbe97 /routers/api/v1 | |
parent | 03591f0f95823a0b1dcca969d2a3ed505c7e6d73 (diff) | |
download | gitea-d56bb7420184c0c2f451f4bcaa96c9b3b00c393d.tar.gz gitea-d56bb7420184c0c2f451f4bcaa96c9b3b00c393d.zip |
add admin API email endpoints (#22792)
add email endpoint to admin API to ensure API parity with admin
dashboard.
Diffstat (limited to 'routers/api/v1')
-rw-r--r-- | routers/api/v1/admin/email.go | 87 | ||||
-rw-r--r-- | routers/api/v1/api.go | 4 |
2 files changed, 91 insertions, 0 deletions
diff --git a/routers/api/v1/admin/email.go b/routers/api/v1/admin/email.go new file mode 100644 index 0000000000..8d0491e070 --- /dev/null +++ b/routers/api/v1/admin/email.go @@ -0,0 +1,87 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package admin + +import ( + "net/http" + + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/context" + api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" + "code.gitea.io/gitea/services/convert" +) + +// GetAllEmails +func GetAllEmails(ctx *context.APIContext) { + // swagger:operation GET /admin/emails admin adminGetAllEmails + // --- + // summary: List all emails + // produces: + // - application/json + // parameters: + // - name: page + // in: query + // description: page number of results to return (1-based) + // type: integer + // - name: limit + // in: query + // description: page size of results + // type: integer + // responses: + // "200": + // "$ref": "#/responses/EmailList" + // "403": + // "$ref": "#/responses/forbidden" + + listOptions := utils.GetListOptions(ctx) + + emails, maxResults, err := user_model.SearchEmails(&user_model.SearchEmailOptions{ + Keyword: ctx.Params(":email"), + ListOptions: listOptions, + }) + if err != nil { + ctx.Error(http.StatusInternalServerError, "GetAllEmails", err) + return + } + + results := make([]*api.Email, len(emails)) + for i := range emails { + results[i] = convert.ToEmailSearch(emails[i]) + } + + ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) + ctx.SetTotalCountHeader(maxResults) + ctx.JSON(http.StatusOK, &results) +} + +// SearchEmail +func SearchEmail(ctx *context.APIContext) { + // swagger:operation GET /admin/emails/search admin adminSearchEmails + // --- + // summary: Search all emails + // produces: + // - application/json + // parameters: + // - name: q + // in: query + // description: keyword + // type: string + // - name: page + // in: query + // description: page number of results to return (1-based) + // type: integer + // - name: limit + // in: query + // description: page size of results + // type: integer + // responses: + // "200": + // "$ref": "#/responses/EmailList" + // "403": + // "$ref": "#/responses/forbidden" + + ctx.SetParams(":email", ctx.FormTrim("q")) + GetAllEmails(ctx) +} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 7001dc72ac..5c32164fa7 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1260,6 +1260,10 @@ func Routes(ctx gocontext.Context) *web.Route { m.Post("/rename", bind(api.RenameUserOption{}), admin.RenameUser) }, context_service.UserAssignmentAPI()) }) + m.Group("/emails", func() { + m.Get("", admin.GetAllEmails) + m.Get("/search", admin.SearchEmail) + }) m.Group("/unadopted", func() { m.Get("", admin.ListUnadoptedRepositories) m.Post("/{username}/{reponame}", admin.AdoptRepository) |