API: Admin EditUser: Make FullName, Email, Website & Location optional (#13562)

* API: Admin EditUser: Make FullName, Email, Website & Location optional

* update swagger docs

* add Tests

Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
6543 2020-11-20 02:56:42 +01:00 committed by GitHub
parent 24b3b2140a
commit 1bb5c09b5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 21 deletions

View file

@ -155,7 +155,7 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
return
}
if len(form.Password) > 0 {
if len(form.Password) != 0 {
if !password.IsComplexEnough(form.Password) {
err := errors.New("PasswordComplexity")
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
@ -182,10 +182,23 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
}
u.LoginName = form.LoginName
u.FullName = form.FullName
u.Email = form.Email
u.Website = form.Website
u.Location = form.Location
if form.FullName != nil {
u.FullName = *form.FullName
}
if form.Email != nil {
u.Email = *form.Email
if len(u.Email) == 0 {
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("email is not allowed to be empty string"))
return
}
}
if form.Website != nil {
u.Website = *form.Website
}
if form.Location != nil {
u.Location = *form.Location
}
if form.Active != nil {
u.IsActive = *form.Active
}