[MM-49180] Error message not clear when creating group with mention name matching username (#22022)
* return the correct error message ID * add test Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
813a7efbcd
Коммит
53d6e7c3f7
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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}}\""
|
||||
|
||||
Ссылка в новой задаче
Block a user