[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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"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)
|
return model.NewAppError("isUniqueToUsernames", model.NoTranslation, nil, "", http.StatusInternalServerError).Wrap(err)
|
||||||
}
|
}
|
||||||
if user != nil {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,16 +84,19 @@ func TestCreateGroup(t *testing.T) {
|
|||||||
require.NotNil(t, err)
|
require.NotNil(t, err)
|
||||||
require.Nil(t, g)
|
require.Nil(t, g)
|
||||||
|
|
||||||
user := th.CreateUser()
|
t.Run("should check if the group mention is in use as a username", func(t *testing.T) {
|
||||||
usernameGroup := &model.Group{
|
user := th.CreateUser()
|
||||||
DisplayName: "dn_" + model.NewId(),
|
usernameGroup := &model.Group{
|
||||||
Name: &user.Username,
|
DisplayName: "dn_" + model.NewId(),
|
||||||
Source: model.GroupSourceLdap,
|
Name: &user.Username,
|
||||||
RemoteId: model.NewString(model.NewId()),
|
Source: model.GroupSourceLdap,
|
||||||
}
|
RemoteId: model.NewString(model.NewId()),
|
||||||
g, err = th.App.CreateGroup(usernameGroup)
|
}
|
||||||
require.NotNil(t, err)
|
g, err = th.App.CreateGroup(usernameGroup)
|
||||||
require.Nil(t, g)
|
require.NotNil(t, err)
|
||||||
|
require.Equal(t, "app.group.username_conflict", err.Id)
|
||||||
|
require.Nil(t, g)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateGroup(t *testing.T) {
|
func TestUpdateGroup(t *testing.T) {
|
||||||
|
|||||||
@@ -5163,6 +5163,10 @@
|
|||||||
"id": "app.group.uniqueness_error",
|
"id": "app.group.uniqueness_error",
|
||||||
"translation": "group member already exists"
|
"translation": "group member already exists"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "app.group.username_conflict",
|
||||||
|
"translation": "user with username \"{{.Username}}\" already exists."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "app.import.attachment.bad_file.error",
|
"id": "app.import.attachment.bad_file.error",
|
||||||
"translation": "Error reading the file at: \"{{.FilePath}}\""
|
"translation": "Error reading the file at: \"{{.FilePath}}\""
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user