Skip to content

Commit eb5e788

Browse files
committed
API: Admin EditUser: Make FullName, Email, Website & Location optional
1 parent ad2a288 commit eb5e788

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

modules/structs/admin_user.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,20 @@ type CreateUserOption struct {
2323

2424
// EditUserOption edit user options
2525
type EditUserOption struct {
26-
SourceID int64 `json:"source_id"`
27-
LoginName string `json:"login_name"`
28-
FullName string `json:"full_name" binding:"MaxSize(100)"`
29-
// required: true
26+
SourceID int64 `json:"source_id"`
27+
LoginName string `json:"login_name"`
28+
FullName *string `json:"full_name" binding:"MaxSize(100)"`
3029
// swagger:strfmt email
31-
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
32-
Password string `json:"password" binding:"MaxSize(255)"`
33-
MustChangePassword *bool `json:"must_change_password"`
34-
Website string `json:"website" binding:"MaxSize(50)"`
35-
Location string `json:"location" binding:"MaxSize(50)"`
36-
Active *bool `json:"active"`
37-
Admin *bool `json:"admin"`
38-
AllowGitHook *bool `json:"allow_git_hook"`
39-
AllowImportLocal *bool `json:"allow_import_local"`
40-
MaxRepoCreation *int `json:"max_repo_creation"`
41-
ProhibitLogin *bool `json:"prohibit_login"`
42-
AllowCreateOrganization *bool `json:"allow_create_organization"`
30+
Email *string `json:"email" binding:"Email;MaxSize(254)"`
31+
Password string `json:"password" binding:"MaxSize(255)"`
32+
MustChangePassword *bool `json:"must_change_password"`
33+
Website *string `json:"website" binding:"MaxSize(50)"`
34+
Location *string `json:"location" binding:"MaxSize(50)"`
35+
Active *bool `json:"active"`
36+
Admin *bool `json:"admin"`
37+
AllowGitHook *bool `json:"allow_git_hook"`
38+
AllowImportLocal *bool `json:"allow_import_local"`
39+
MaxRepoCreation *int `json:"max_repo_creation"`
40+
ProhibitLogin *bool `json:"prohibit_login"`
41+
AllowCreateOrganization *bool `json:"allow_create_organization"`
4342
}

routers/api/v1/admin/user.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
155155
return
156156
}
157157

158-
if len(form.Password) > 0 {
158+
if len(form.Password) != 0 {
159159
if !password.IsComplexEnough(form.Password) {
160160
err := errors.New("PasswordComplexity")
161161
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
@@ -182,10 +182,23 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
182182
}
183183

184184
u.LoginName = form.LoginName
185-
u.FullName = form.FullName
186-
u.Email = form.Email
187-
u.Website = form.Website
188-
u.Location = form.Location
185+
186+
if form.FullName != nil {
187+
u.FullName = *form.FullName
188+
}
189+
if form.Email != nil {
190+
u.Email = *form.Email
191+
if len(u.Email) == 0 {
192+
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("email is not allowed to be empty"))
193+
return
194+
}
195+
}
196+
if form.Website != nil {
197+
u.Website = *form.Website
198+
}
199+
if form.Location != nil {
200+
u.Location = *form.Location
201+
}
189202
if form.Active != nil {
190203
u.IsActive = *form.Active
191204
}

templates/swagger/v1_json.tmpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13096,9 +13096,6 @@
1309613096
"EditUserOption": {
1309713097
"description": "EditUserOption edit user options",
1309813098
"type": "object",
13099-
"required": [
13100-
"email"
13101-
],
1310213099
"properties": {
1310313100
"active": {
1310413101
"type": "boolean",

0 commit comments

Comments
 (0)