mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 03:00:18 +08:00
feat: fix "Display name cannot be empty" in /update-user API
This commit is contained in:
@ -282,13 +282,6 @@ func (c *ApiController) UpdateUser() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Input().Get("allowEmpty") == "" {
|
|
||||||
if user.DisplayName == "" {
|
|
||||||
c.ResponseError(c.T("user:Display name cannot be empty"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if user.MfaEmailEnabled && user.Email == "" {
|
if user.MfaEmailEnabled && user.Email == "" {
|
||||||
c.ResponseError(c.T("user:MFA email is enabled but email is empty"))
|
c.ResponseError(c.T("user:MFA email is enabled but email is empty"))
|
||||||
return
|
return
|
||||||
@ -310,7 +303,8 @@ func (c *ApiController) UpdateUser() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isAdmin := c.IsAdmin()
|
isAdmin := c.IsAdmin()
|
||||||
if pass, err := object.CheckPermissionForUpdateUser(oldUser, &user, isAdmin, c.GetAcceptLanguage()); !pass {
|
allowDisplayNameEmpty := c.Input().Get("allowEmpty") != ""
|
||||||
|
if pass, err := object.CheckPermissionForUpdateUser(oldUser, &user, isAdmin, allowDisplayNameEmpty, c.GetAcceptLanguage()); !pass {
|
||||||
c.ResponseError(err)
|
c.ResponseError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ func ClearUserOAuthProperties(user *User, providerType string) (bool, error) {
|
|||||||
return affected != 0, nil
|
return affected != 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckPermissionForUpdateUser(oldUser, newUser *User, isAdmin bool, lang string) (bool, string) {
|
func CheckPermissionForUpdateUser(oldUser, newUser *User, isAdmin bool, allowDisplayNameEmpty bool, lang string) (bool, string) {
|
||||||
organization, err := GetOrganizationByUser(oldUser)
|
organization, err := GetOrganizationByUser(oldUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err.Error()
|
return false, err.Error()
|
||||||
@ -300,6 +300,10 @@ func CheckPermissionForUpdateUser(oldUser, newUser *User, isAdmin bool, lang str
|
|||||||
if item == nil {
|
if item == nil {
|
||||||
newUser.DisplayName = oldUser.DisplayName
|
newUser.DisplayName = oldUser.DisplayName
|
||||||
} else {
|
} else {
|
||||||
|
if !allowDisplayNameEmpty && newUser.DisplayName == "" {
|
||||||
|
return false, i18n.Translate(lang, "user:Display name cannot be empty")
|
||||||
|
}
|
||||||
|
|
||||||
itemsChanged = append(itemsChanged, item)
|
itemsChanged = append(itemsChanged, item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user