summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-11-20 02:56:42 +0100
committerGitHub <noreply@github.com>2020-11-19 20:56:42 -0500
commit1bb5c09b5d973ac184922380b1e6379875ac5fa7 (patch)
tree293984f50fd016e9da7cfb78102eeacc5f14b01a /routers
parent24b3b2140a094a108707c2994946b5a99eda016f (diff)
downloadgitea-1bb5c09b5d973ac184922380b1e6379875ac5fa7.tar.gz
gitea-1bb5c09b5d973ac184922380b1e6379875ac5fa7.zip
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>
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/admin/user.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go
index c4b52e4bd6..93b28c2175 100644
--- a/routers/api/v1/admin/user.go
+++ b/routers/api/v1/admin/user.go
@@ -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
}