loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add admin API email endpoints (#22792)

add email endpoint to admin API to ensure API parity with admin
dashboard.

authored by

techknowlogick and committed by
GitHub
d56bb742 03591f0f

+188
+3
modules/structs/user_email.go
··· 1 1 // Copyright 2015 The Gogs Authors. All rights reserved. 2 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 3 // SPDX-License-Identifier: MIT 3 4 4 5 package structs ··· 9 10 Email string `json:"email"` 10 11 Verified bool `json:"verified"` 11 12 Primary bool `json:"primary"` 13 + UserID int64 `json:"user_id"` 14 + UserName string `json:"username"` 12 15 } 13 16 14 17 // CreateEmailOption options when creating email addresses
+87
routers/api/v1/admin/email.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package admin 5 + 6 + import ( 7 + "net/http" 8 + 9 + user_model "code.gitea.io/gitea/models/user" 10 + "code.gitea.io/gitea/modules/context" 11 + api "code.gitea.io/gitea/modules/structs" 12 + "code.gitea.io/gitea/routers/api/v1/utils" 13 + "code.gitea.io/gitea/services/convert" 14 + ) 15 + 16 + // GetAllEmails 17 + func GetAllEmails(ctx *context.APIContext) { 18 + // swagger:operation GET /admin/emails admin adminGetAllEmails 19 + // --- 20 + // summary: List all emails 21 + // produces: 22 + // - application/json 23 + // parameters: 24 + // - name: page 25 + // in: query 26 + // description: page number of results to return (1-based) 27 + // type: integer 28 + // - name: limit 29 + // in: query 30 + // description: page size of results 31 + // type: integer 32 + // responses: 33 + // "200": 34 + // "$ref": "#/responses/EmailList" 35 + // "403": 36 + // "$ref": "#/responses/forbidden" 37 + 38 + listOptions := utils.GetListOptions(ctx) 39 + 40 + emails, maxResults, err := user_model.SearchEmails(&user_model.SearchEmailOptions{ 41 + Keyword: ctx.Params(":email"), 42 + ListOptions: listOptions, 43 + }) 44 + if err != nil { 45 + ctx.Error(http.StatusInternalServerError, "GetAllEmails", err) 46 + return 47 + } 48 + 49 + results := make([]*api.Email, len(emails)) 50 + for i := range emails { 51 + results[i] = convert.ToEmailSearch(emails[i]) 52 + } 53 + 54 + ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) 55 + ctx.SetTotalCountHeader(maxResults) 56 + ctx.JSON(http.StatusOK, &results) 57 + } 58 + 59 + // SearchEmail 60 + func SearchEmail(ctx *context.APIContext) { 61 + // swagger:operation GET /admin/emails/search admin adminSearchEmails 62 + // --- 63 + // summary: Search all emails 64 + // produces: 65 + // - application/json 66 + // parameters: 67 + // - name: q 68 + // in: query 69 + // description: keyword 70 + // type: string 71 + // - name: page 72 + // in: query 73 + // description: page number of results to return (1-based) 74 + // type: integer 75 + // - name: limit 76 + // in: query 77 + // description: page size of results 78 + // type: integer 79 + // responses: 80 + // "200": 81 + // "$ref": "#/responses/EmailList" 82 + // "403": 83 + // "$ref": "#/responses/forbidden" 84 + 85 + ctx.SetParams(":email", ctx.FormTrim("q")) 86 + GetAllEmails(ctx) 87 + }
+4
routers/api/v1/api.go
··· 1260 1260 m.Post("/rename", bind(api.RenameUserOption{}), admin.RenameUser) 1261 1261 }, context_service.UserAssignmentAPI()) 1262 1262 }) 1263 + m.Group("/emails", func() { 1264 + m.Get("", admin.GetAllEmails) 1265 + m.Get("/search", admin.SearchEmail) 1266 + }) 1263 1267 m.Group("/unadopted", func() { 1264 1268 m.Get("", admin.ListUnadoptedRepositories) 1265 1269 m.Post("/{username}/{reponame}", admin.AdoptRepository)
+11
services/convert/convert.go
··· 38 38 } 39 39 } 40 40 41 + // ToEmail convert models.EmailAddress to api.Email 42 + func ToEmailSearch(email *user_model.SearchEmailResult) *api.Email { 43 + return &api.Email{ 44 + Email: email.Email, 45 + Verified: email.IsActivated, 46 + Primary: email.IsPrimary, 47 + UserID: email.UID, 48 + UserName: email.Name, 49 + } 50 + } 51 + 41 52 // ToBranch convert a git.Commit and git.Branch to an api.Branch 42 53 func ToBranch(ctx context.Context, repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *git_model.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) { 43 54 if bp == nil {
+83
templates/swagger/v1_json.tmpl
··· 138 138 } 139 139 } 140 140 }, 141 + "/admin/emails": { 142 + "get": { 143 + "produces": [ 144 + "application/json" 145 + ], 146 + "tags": [ 147 + "admin" 148 + ], 149 + "summary": "List all emails", 150 + "operationId": "adminGetAllEmails", 151 + "parameters": [ 152 + { 153 + "type": "integer", 154 + "description": "page number of results to return (1-based)", 155 + "name": "page", 156 + "in": "query" 157 + }, 158 + { 159 + "type": "integer", 160 + "description": "page size of results", 161 + "name": "limit", 162 + "in": "query" 163 + } 164 + ], 165 + "responses": { 166 + "200": { 167 + "$ref": "#/responses/EmailList" 168 + }, 169 + "403": { 170 + "$ref": "#/responses/forbidden" 171 + } 172 + } 173 + } 174 + }, 175 + "/admin/emails/search": { 176 + "get": { 177 + "produces": [ 178 + "application/json" 179 + ], 180 + "tags": [ 181 + "admin" 182 + ], 183 + "summary": "Search all emails", 184 + "operationId": "adminSearchEmails", 185 + "parameters": [ 186 + { 187 + "type": "string", 188 + "description": "keyword", 189 + "name": "q", 190 + "in": "query" 191 + }, 192 + { 193 + "type": "integer", 194 + "description": "page number of results to return (1-based)", 195 + "name": "page", 196 + "in": "query" 197 + }, 198 + { 199 + "type": "integer", 200 + "description": "page size of results", 201 + "name": "limit", 202 + "in": "query" 203 + } 204 + ], 205 + "responses": { 206 + "200": { 207 + "$ref": "#/responses/EmailList" 208 + }, 209 + "403": { 210 + "$ref": "#/responses/forbidden" 211 + } 212 + } 213 + } 214 + }, 141 215 "/admin/hooks": { 142 216 "get": { 143 217 "produces": [ ··· 16998 17072 "primary": { 16999 17073 "type": "boolean", 17000 17074 "x-go-name": "Primary" 17075 + }, 17076 + "user_id": { 17077 + "type": "integer", 17078 + "format": "int64", 17079 + "x-go-name": "UserID" 17080 + }, 17081 + "username": { 17082 + "type": "string", 17083 + "x-go-name": "UserName" 17001 17084 }, 17002 17085 "verified": { 17003 17086 "type": "boolean",