MM-42201: Enforce group is not the same as username. (#19660)
* MM-42201: Enforce group is not the same as username. * MM-42201: Adjust test for change to translation id.
Этот коммит содержится в:
27
app/user.go
27
app/user.go
@@ -219,6 +219,11 @@ func (a *App) CreateGuest(c *request.Context, user *model.User) (*model.User, *m
|
||||
}
|
||||
|
||||
func (a *App) createUserOrGuest(c *request.Context, user *model.User, guest bool) (*model.User, *model.AppError) {
|
||||
if err := a.isUniqueToGroupNames(user.Username); err != nil {
|
||||
err.Where = "createUserOrGuest"
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ruser, nErr := a.ch.srv.userService.CreateUser(user, users.UserCreateOptions{Guest: guest})
|
||||
if nErr != nil {
|
||||
var appErr *model.AppError
|
||||
@@ -1053,6 +1058,21 @@ func (a *App) sendUpdatedUserEvent(user model.User) {
|
||||
a.Publish(sourceUserMessage)
|
||||
}
|
||||
|
||||
func (a *App) isUniqueToGroupNames(val string) *model.AppError {
|
||||
if val == "" {
|
||||
return nil
|
||||
}
|
||||
var notFoundErr *store.ErrNotFound
|
||||
group, err := a.Srv().Store.Group().GetByName(val, model.GroupSearchOpts{})
|
||||
if err != nil && !errors.As(err, ¬FoundErr) {
|
||||
return model.NewAppError("", "app.user.get_by_name_failure", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if group != nil {
|
||||
return model.NewAppError("", "app.user.group_name_conflict", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError) {
|
||||
prev, err := a.ch.srv.userService.GetUser(user.Id)
|
||||
if err != nil {
|
||||
@@ -1065,6 +1085,13 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
|
||||
}
|
||||
}
|
||||
|
||||
if user.Username != prev.Username {
|
||||
if err := a.isUniqueToGroupNames(user.Username); err != nil {
|
||||
err.Where = "UpdateUser"
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var newEmail string
|
||||
if user.Email != prev.Email {
|
||||
if !users.CheckUserDomain(user, *a.Config().TeamSettings.RestrictCreationToDomains) {
|
||||
|
||||
Ссылка в новой задаче
Block a user