(c *context.APIContext, form api.EditUserOption)
| 68 | } |
| 69 | |
| 70 | func EditUser(c *context.APIContext, form api.EditUserOption) { |
| 71 | u := user.GetUserByParams(c) |
| 72 | if c.Written() { |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | parseLoginSource(c, form.SourceID) |
| 77 | if c.Written() { |
| 78 | return |
| 79 | } |
| 80 | |
| 81 | opts := database.UpdateUserOptions{ |
| 82 | LoginSource: &form.SourceID, |
| 83 | LoginName: &form.LoginName, |
| 84 | FullName: &form.FullName, |
| 85 | Website: &form.Website, |
| 86 | Location: &form.Location, |
| 87 | MaxRepoCreation: form.MaxRepoCreation, |
| 88 | IsActivated: form.Active, |
| 89 | IsAdmin: form.Admin, |
| 90 | AllowGitHook: form.AllowGitHook, |
| 91 | AllowImportLocal: form.AllowImportLocal, |
| 92 | ProhibitLogin: nil, // TODO: Add this option to API |
| 93 | } |
| 94 | |
| 95 | if form.Password != "" { |
| 96 | opts.Password = &form.Password |
| 97 | } |
| 98 | |
| 99 | if u.Email != form.Email { |
| 100 | opts.Email = &form.Email |
| 101 | } |
| 102 | |
| 103 | err := database.Handle.Users().Update(c.Req.Context(), u.ID, opts) |
| 104 | if err != nil { |
| 105 | if database.IsErrEmailAlreadyUsed(err) { |
| 106 | c.ErrorStatus(http.StatusUnprocessableEntity, err) |
| 107 | } else { |
| 108 | c.Error(err, "update user") |
| 109 | } |
| 110 | return |
| 111 | } |
| 112 | log.Trace("Account updated by admin %q: %s", c.User.Name, u.Name) |
| 113 | |
| 114 | u, err = database.Handle.Users().GetByID(c.Req.Context(), u.ID) |
| 115 | if err != nil { |
| 116 | c.Error(err, "get user") |
| 117 | return |
| 118 | } |
| 119 | c.JSONSuccess(u.APIFormat()) |
| 120 | } |
| 121 | |
| 122 | func DeleteUser(c *context.APIContext) { |
| 123 | u := user.GetUserByParams(c) |
nothing calls this directly
no test coverage detected