mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-26 03:13:22 +00:00
Backport #38917 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -11,7 +11,6 @@ type CreateUserOption struct {
|
|||||||
// The authentication source ID to associate with the user
|
// The authentication source ID to associate with the user
|
||||||
SourceID int64 `json:"source_id"`
|
SourceID int64 `json:"source_id"`
|
||||||
// identifier of the user, provided by the external authenticator (if configured)
|
// identifier of the user, provided by the external authenticator (if configured)
|
||||||
// default: empty
|
|
||||||
LoginName string `json:"login_name"`
|
LoginName string `json:"login_name"`
|
||||||
// username of the user
|
// username of the user
|
||||||
// required: true
|
// required: true
|
||||||
@@ -44,9 +43,7 @@ type EditUserOption struct {
|
|||||||
// The authentication source ID to associate with the user
|
// The authentication source ID to associate with the user
|
||||||
SourceID int64 `json:"source_id"`
|
SourceID int64 `json:"source_id"`
|
||||||
// identifier of the user, provided by the external authenticator (if configured)
|
// identifier of the user, provided by the external authenticator (if configured)
|
||||||
// default: empty
|
LoginName *string `json:"login_name"`
|
||||||
// required: true
|
|
||||||
LoginName string `json:"login_name" binding:"Required"`
|
|
||||||
// swagger:strfmt email
|
// swagger:strfmt email
|
||||||
// The email address of the user
|
// The email address of the user
|
||||||
Email *string `json:"email" binding:"MaxSize(254)"`
|
Email *string `json:"email" binding:"MaxSize(254)"`
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ type User struct {
|
|||||||
// login of the user, same as `username`
|
// login of the user, same as `username`
|
||||||
UserName string `json:"login"`
|
UserName string `json:"login"`
|
||||||
// identifier of the user, provided by the external authenticator (if configured)
|
// identifier of the user, provided by the external authenticator (if configured)
|
||||||
// default: empty
|
|
||||||
LoginName string `json:"login_name"`
|
LoginName string `json:"login_name"`
|
||||||
// The ID of the user's Authentication Source
|
// The ID of the user's Authentication Source
|
||||||
SourceID int64 `json:"source_id"`
|
SourceID int64 `json:"source_id"`
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ func EditUser(ctx *context.APIContext) {
|
|||||||
|
|
||||||
authOpts := &user_service.UpdateAuthOptions{
|
authOpts := &user_service.UpdateAuthOptions{
|
||||||
LoginSource: optional.FromNonDefault(form.SourceID),
|
LoginSource: optional.FromNonDefault(form.SourceID),
|
||||||
LoginName: optional.Some(form.LoginName),
|
LoginName: optional.FromPtr(form.LoginName),
|
||||||
Password: optional.FromNonDefault(form.Password),
|
Password: optional.FromNonDefault(form.Password),
|
||||||
MustChangePassword: optional.FromPtr(form.MustChangePassword),
|
MustChangePassword: optional.FromPtr(form.MustChangePassword),
|
||||||
ProhibitLogin: optional.FromPtr(form.ProhibitLogin),
|
ProhibitLogin: optional.FromPtr(form.ProhibitLogin),
|
||||||
|
|||||||
Generated
+1
-5
@@ -25063,7 +25063,6 @@
|
|||||||
"login_name": {
|
"login_name": {
|
||||||
"description": "identifier of the user, provided by the external authenticator (if configured)",
|
"description": "identifier of the user, provided by the external authenticator (if configured)",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "empty",
|
|
||||||
"x-go-name": "LoginName"
|
"x-go-name": "LoginName"
|
||||||
},
|
},
|
||||||
"must_change_password": {
|
"must_change_password": {
|
||||||
@@ -26249,8 +26248,7 @@
|
|||||||
"description": "EditUserOption edit user options",
|
"description": "EditUserOption edit user options",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"source_id",
|
"source_id"
|
||||||
"login_name"
|
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"active": {
|
"active": {
|
||||||
@@ -26301,7 +26299,6 @@
|
|||||||
"login_name": {
|
"login_name": {
|
||||||
"description": "identifier of the user, provided by the external authenticator (if configured)",
|
"description": "identifier of the user, provided by the external authenticator (if configured)",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "empty",
|
|
||||||
"x-go-name": "LoginName"
|
"x-go-name": "LoginName"
|
||||||
},
|
},
|
||||||
"max_repo_creation": {
|
"max_repo_creation": {
|
||||||
@@ -30658,7 +30655,6 @@
|
|||||||
"login_name": {
|
"login_name": {
|
||||||
"description": "identifier of the user, provided by the external authenticator (if configured)",
|
"description": "identifier of the user, provided by the external authenticator (if configured)",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "empty",
|
|
||||||
"x-go-name": "LoginName"
|
"x-go-name": "LoginName"
|
||||||
},
|
},
|
||||||
"prohibit_login": {
|
"prohibit_login": {
|
||||||
|
|||||||
Generated
+1
-5
@@ -4835,7 +4835,6 @@
|
|||||||
"x-go-name": "FullName"
|
"x-go-name": "FullName"
|
||||||
},
|
},
|
||||||
"login_name": {
|
"login_name": {
|
||||||
"default": "empty",
|
|
||||||
"description": "identifier of the user, provided by the external authenticator (if configured)",
|
"description": "identifier of the user, provided by the external authenticator (if configured)",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "LoginName"
|
"x-go-name": "LoginName"
|
||||||
@@ -6058,7 +6057,6 @@
|
|||||||
"x-go-name": "Location"
|
"x-go-name": "Location"
|
||||||
},
|
},
|
||||||
"login_name": {
|
"login_name": {
|
||||||
"default": "empty",
|
|
||||||
"description": "identifier of the user, provided by the external authenticator (if configured)",
|
"description": "identifier of the user, provided by the external authenticator (if configured)",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "LoginName"
|
"x-go-name": "LoginName"
|
||||||
@@ -6109,8 +6107,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"source_id",
|
"source_id"
|
||||||
"login_name"
|
|
||||||
],
|
],
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"x-go-package": "gitea.dev/modules/structs"
|
"x-go-package": "gitea.dev/modules/structs"
|
||||||
@@ -10469,7 +10466,6 @@
|
|||||||
"x-go-name": "UserName"
|
"x-go-name": "UserName"
|
||||||
},
|
},
|
||||||
"login_name": {
|
"login_name": {
|
||||||
"default": "empty",
|
|
||||||
"description": "identifier of the user, provided by the external authenticator (if configured)",
|
"description": "identifier of the user, provided by the external authenticator (if configured)",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "LoginName"
|
"x-go-name": "LoginName"
|
||||||
|
|||||||
@@ -204,12 +204,7 @@ func TestAPIEditUser(t *testing.T) {
|
|||||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{LoginName: "user2"})
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{LoginName: "user2"})
|
||||||
assert.Equal(t, fullNameToChange, user2.FullName)
|
assert.Equal(t, fullNameToChange, user2.FullName)
|
||||||
|
|
||||||
empty := ""
|
req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{SourceID: 0, Email: new("")}).AddTokenAuth(token)
|
||||||
req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{
|
|
||||||
LoginName: "user2",
|
|
||||||
SourceID: 0,
|
|
||||||
Email: &empty,
|
|
||||||
}).AddTokenAuth(token)
|
|
||||||
resp := MakeRequest(t, req, http.StatusBadRequest)
|
resp := MakeRequest(t, req, http.StatusBadRequest)
|
||||||
|
|
||||||
errMap := make(map[string]any)
|
errMap := make(map[string]any)
|
||||||
@@ -218,14 +213,7 @@ func TestAPIEditUser(t *testing.T) {
|
|||||||
|
|
||||||
user2 = unittest.AssertExistsAndLoadBean(t, &user_model.User{LoginName: "user2"})
|
user2 = unittest.AssertExistsAndLoadBean(t, &user_model.User{LoginName: "user2"})
|
||||||
assert.False(t, user2.IsRestricted)
|
assert.False(t, user2.IsRestricted)
|
||||||
bTrue := true
|
req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{Restricted: new(true)}).AddTokenAuth(token)
|
||||||
req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{
|
|
||||||
// required
|
|
||||||
LoginName: "user2",
|
|
||||||
SourceID: 0,
|
|
||||||
// to change
|
|
||||||
Restricted: &bTrue,
|
|
||||||
}).AddTokenAuth(token)
|
|
||||||
MakeRequest(t, req, http.StatusOK)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
user2 = unittest.AssertExistsAndLoadBean(t, &user_model.User{LoginName: "user2"})
|
user2 = unittest.AssertExistsAndLoadBean(t, &user_model.User{LoginName: "user2"})
|
||||||
assert.True(t, user2.IsRestricted)
|
assert.True(t, user2.IsRestricted)
|
||||||
@@ -361,24 +349,14 @@ func TestAPIEditUser_NotAllowedEmailDomain(t *testing.T) {
|
|||||||
|
|
||||||
adminUsername := "user1"
|
adminUsername := "user1"
|
||||||
token := getUserToken(t, adminUsername, auth_model.AccessTokenScopeWriteAdmin)
|
token := getUserToken(t, adminUsername, auth_model.AccessTokenScopeWriteAdmin)
|
||||||
urlStr := "/api/v1/admin/users/" + "user2"
|
urlStr := "/api/v1/admin/users/user2"
|
||||||
|
|
||||||
newEmail := "user2@example1.com"
|
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{Email: new("user2@example1.com")}).AddTokenAuth(token)
|
||||||
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{
|
|
||||||
LoginName: "user2",
|
|
||||||
SourceID: 0,
|
|
||||||
Email: &newEmail,
|
|
||||||
}).AddTokenAuth(token)
|
|
||||||
resp := MakeRequest(t, req, http.StatusBadRequest)
|
resp := MakeRequest(t, req, http.StatusBadRequest)
|
||||||
errMap := make(map[string]string)
|
errMap := make(map[string]string)
|
||||||
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &errMap))
|
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &errMap))
|
||||||
assert.Equal(t, "the domain of user email user2@example1.com conflicts with EMAIL_DOMAIN_ALLOWLIST or EMAIL_DOMAIN_BLOCKLIST", errMap["message"])
|
assert.Equal(t, "the domain of user email user2@example1.com conflicts with EMAIL_DOMAIN_ALLOWLIST or EMAIL_DOMAIN_BLOCKLIST", errMap["message"])
|
||||||
|
|
||||||
originalEmail := "user2@example.org"
|
req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{Email: new("user2@example.org")}).AddTokenAuth(token)
|
||||||
req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{
|
|
||||||
LoginName: "user2",
|
|
||||||
SourceID: 0,
|
|
||||||
Email: &originalEmail,
|
|
||||||
}).AddTokenAuth(token)
|
|
||||||
MakeRequest(t, req, http.StatusOK)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user