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.

Merge pull request 'Do not require login_name & source_id for /admin/user/{username}' (#3278) from algernon/forgejo:leave-your-name-at-the-door into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3278
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>

+56 -33
+2 -4
modules/structs/admin_user.go
··· 30 30 31 31 // EditUserOption edit user options 32 32 type EditUserOption struct { 33 - // required: true 34 - SourceID int64 `json:"source_id"` 35 - // required: true 36 - LoginName string `json:"login_name" binding:"Required"` 33 + SourceID *int64 `json:"source_id"` 34 + LoginName *string `json:"login_name"` 37 35 // swagger:strfmt email 38 36 Email *string `json:"email" binding:"MaxSize(254)"` 39 37 FullName *string `json:"full_name" binding:"MaxSize(100)"`
+10 -2
routers/api/v1/admin/user.go
··· 192 192 193 193 form := web.GetForm(ctx).(*api.EditUserOption) 194 194 195 + // If either LoginSource or LoginName is given, the other must be present too. 196 + if form.SourceID != nil || form.LoginName != nil { 197 + if form.SourceID == nil || form.LoginName == nil { 198 + ctx.Error(http.StatusUnprocessableEntity, "LoginSourceAndLoginName", fmt.Errorf("source_id and login_name must be specified together")) 199 + return 200 + } 201 + } 202 + 195 203 authOpts := &user_service.UpdateAuthOptions{ 196 - LoginSource: optional.FromNonDefault(form.SourceID), 197 - LoginName: optional.Some(form.LoginName), 204 + LoginSource: optional.FromPtr(form.SourceID), 205 + LoginName: optional.FromPtr(form.LoginName), 198 206 Password: optional.FromNonDefault(form.Password), 199 207 MustChangePassword: optional.FromPtr(form.MustChangePassword), 200 208 ProhibitLogin: optional.FromPtr(form.ProhibitLogin),
-4
templates/swagger/v1_json.tmpl
··· 20989 20989 "EditUserOption": { 20990 20990 "description": "EditUserOption edit user options", 20991 20991 "type": "object", 20992 - "required": [ 20993 - "source_id", 20994 - "login_name" 20995 - ], 20996 20992 "properties": { 20997 20993 "active": { 20998 20994 "type": "boolean",
+42 -17
tests/integration/api_admin_test.go
··· 196 196 urlStr := fmt.Sprintf("/api/v1/admin/users/%s", "user2") 197 197 198 198 req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{ 199 - // required 200 - "login_name": "user2", 201 - "source_id": "0", 202 - // to change 203 199 "full_name": "Full Name User 2", 204 200 }).AddTokenAuth(token) 205 201 MakeRequest(t, req, http.StatusOK) 206 202 207 203 empty := "" 208 204 req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{ 209 - LoginName: "user2", 210 - SourceID: 0, 211 - Email: &empty, 205 + Email: &empty, 212 206 }).AddTokenAuth(token) 213 207 resp := MakeRequest(t, req, http.StatusBadRequest) 214 208 ··· 220 214 assert.False(t, user2.IsRestricted) 221 215 bTrue := true 222 216 req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{ 223 - // required 224 - LoginName: "user2", 225 - SourceID: 0, 226 - // to change 227 217 Restricted: &bTrue, 228 218 }).AddTokenAuth(token) 229 219 MakeRequest(t, req, http.StatusOK) 230 220 user2 = unittest.AssertExistsAndLoadBean(t, &user_model.User{LoginName: "user2"}) 231 221 assert.True(t, user2.IsRestricted) 222 + } 223 + 224 + func TestAPIEditUserWithLoginName(t *testing.T) { 225 + defer tests.PrepareTestEnv(t)() 226 + 227 + adminUsername := "user1" 228 + token := getUserToken(t, adminUsername, auth_model.AccessTokenScopeWriteAdmin) 229 + urlStr := fmt.Sprintf("/api/v1/admin/users/%s", "user2") 230 + 231 + loginName := "user2" 232 + loginSource := int64(0) 233 + 234 + t.Run("login_name only", func(t *testing.T) { 235 + defer tests.PrintCurrentTest(t)() 236 + 237 + req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{ 238 + LoginName: &loginName, 239 + }).AddTokenAuth(token) 240 + MakeRequest(t, req, http.StatusUnprocessableEntity) 241 + }) 242 + 243 + t.Run("source_id only", func(t *testing.T) { 244 + defer tests.PrintCurrentTest(t)() 245 + 246 + req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{ 247 + SourceID: &loginSource, 248 + }).AddTokenAuth(token) 249 + MakeRequest(t, req, http.StatusUnprocessableEntity) 250 + }) 251 + 252 + t.Run("login_name & source_id", func(t *testing.T) { 253 + defer tests.PrintCurrentTest(t)() 254 + 255 + req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{ 256 + LoginName: &loginName, 257 + SourceID: &loginSource, 258 + }).AddTokenAuth(token) 259 + MakeRequest(t, req, http.StatusOK) 260 + }) 232 261 } 233 262 234 263 func TestAPICreateRepoForUser(t *testing.T) { ··· 375 404 376 405 newEmail := "user2@example1.com" 377 406 req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{ 378 - LoginName: "user2", 379 - SourceID: 0, 380 - Email: &newEmail, 407 + Email: &newEmail, 381 408 }).AddTokenAuth(token) 382 409 resp := MakeRequest(t, req, http.StatusOK) 383 410 assert.Equal(t, "the domain of user email user2@example1.com conflicts with EMAIL_DOMAIN_ALLOWLIST or EMAIL_DOMAIN_BLOCKLIST", resp.Header().Get("X-Gitea-Warning")) 384 411 385 412 originalEmail := "user2@example.com" 386 413 req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{ 387 - LoginName: "user2", 388 - SourceID: 0, 389 - Email: &originalEmail, 414 + Email: &originalEmail, 390 415 }).AddTokenAuth(token) 391 416 MakeRequest(t, req, http.StatusOK) 392 417 }
+2 -6
tests/integration/user_test.go
··· 495 495 // Set the pronouns for user2 496 496 pronouns := "she/her" 497 497 req := NewRequestWithJSON(t, "PATCH", "/api/v1/admin/users/user2", &api.EditUserOption{ 498 - LoginName: "user2", 499 - SourceID: 0, 500 - Pronouns: &pronouns, 498 + Pronouns: &pronouns, 501 499 }).AddTokenAuth(adminToken) 502 500 resp := MakeRequest(t, req, http.StatusOK) 503 501 ··· 596 594 // Set the pronouns to Unspecified (an empty string) via the API 597 595 pronouns := "" 598 596 req := NewRequestWithJSON(t, "PATCH", "/api/v1/admin/users/user2", &api.EditUserOption{ 599 - LoginName: "user2", 600 - SourceID: 0, 601 - Pronouns: &pronouns, 597 + Pronouns: &pronouns, 602 598 }).AddTokenAuth(adminToken) 603 599 MakeRequest(t, req, http.StatusOK) 604 600