diff --git a/app/group.go b/app/group.go index a01b369e41..507a56072e 100644 --- a/app/group.go +++ b/app/group.go @@ -6,7 +6,6 @@ package app import ( "encoding/json" "errors" - "fmt" "net/http" "github.com/mattermost/mattermost-server/v6/model" @@ -117,7 +116,7 @@ func (a *App) isUniqueToUsernames(val string) *model.AppError { return model.NewAppError("isUniqueToUsernames", model.NoTranslation, nil, "", http.StatusInternalServerError).Wrap(err) } if user != nil { - return model.NewAppError("isUniqueToUsernames", model.NoTranslation, nil, fmt.Sprintf("user name %s exists", val), http.StatusBadRequest) + return model.NewAppError("isUniqueToUsernames", "app.group.username_conflict", map[string]interface{}{"Username": val}, "", http.StatusBadRequest) } return nil } diff --git a/app/group_test.go b/app/group_test.go index 4419eff777..fb53d3e637 100644 --- a/app/group_test.go +++ b/app/group_test.go @@ -84,16 +84,19 @@ func TestCreateGroup(t *testing.T) { require.NotNil(t, err) require.Nil(t, g) - user := th.CreateUser() - usernameGroup := &model.Group{ - DisplayName: "dn_" + model.NewId(), - Name: &user.Username, - Source: model.GroupSourceLdap, - RemoteId: model.NewString(model.NewId()), - } - g, err = th.App.CreateGroup(usernameGroup) - require.NotNil(t, err) - require.Nil(t, g) + t.Run("should check if the group mention is in use as a username", func(t *testing.T) { + user := th.CreateUser() + usernameGroup := &model.Group{ + DisplayName: "dn_" + model.NewId(), + Name: &user.Username, + Source: model.GroupSourceLdap, + RemoteId: model.NewString(model.NewId()), + } + g, err = th.App.CreateGroup(usernameGroup) + require.NotNil(t, err) + require.Equal(t, "app.group.username_conflict", err.Id) + require.Nil(t, g) + }) } func TestUpdateGroup(t *testing.T) { diff --git a/i18n/en.json b/i18n/en.json index 5ce385139d..da4d987d34 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -5163,6 +5163,10 @@ "id": "app.group.uniqueness_error", "translation": "group member already exists" }, + { + "id": "app.group.username_conflict", + "translation": "user with username \"{{.Username}}\" already exists." + }, { "id": "app.import.attachment.bad_file.error", "translation": "Error reading the file at: \"{{.FilePath}}\""