Do not require login_name & source_id for /admin/user/{username}
When editing a user via the API, do not require setting `login_name` or `source_id`: for local accounts, these do not matter. However, when editing a non-local account, require *both*, as before. Fixes #1861. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
parent
787bc6ed94
commit
d07c8c821c
5 changed files with 56 additions and 33 deletions
|
@ -192,9 +192,17 @@ func EditUser(ctx *context.APIContext) {
|
|||
|
||||
form := web.GetForm(ctx).(*api.EditUserOption)
|
||||
|
||||
// If either LoginSource or LoginName is given, the other must be present too.
|
||||
if form.SourceID != nil || form.LoginName != nil {
|
||||
if form.SourceID == nil || form.LoginName == nil {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "LoginSourceAndLoginName", fmt.Errorf("source_id and login_name must be specified together"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
authOpts := &user_service.UpdateAuthOptions{
|
||||
LoginSource: optional.FromNonDefault(form.SourceID),
|
||||
LoginName: optional.Some(form.LoginName),
|
||||
LoginSource: optional.FromPtr(form.SourceID),
|
||||
LoginName: optional.FromPtr(form.LoginName),
|
||||
Password: optional.FromNonDefault(form.Password),
|
||||
MustChangePassword: optional.FromPtr(form.MustChangePassword),
|
||||
ProhibitLogin: optional.FromPtr(form.ProhibitLogin),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue