MM-43829: Default for user display_name preference (#20087)
We fall back to TeammateNameDisplay if a user display_name preference is not found. This makes the logic consistent with other parts of the app. https://mattermost.atlassian.net/browse/MM-43829 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
cb3d8f0a1c
Коммит
c0eb0fd3c3
@@ -95,10 +95,9 @@ func postProcessChannels(c *web.Context, channels []*model.Channel) ([]*channel,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var pref *model.Preference
|
var nameFormat string
|
||||||
var userInfo map[string][]*model.User
|
var userInfo map[string][]*model.User
|
||||||
var err error
|
var err error
|
||||||
var appErr *model.AppError
|
|
||||||
|
|
||||||
// Avoiding unnecessary queries unless necessary.
|
// Avoiding unnecessary queries unless necessary.
|
||||||
if len(channelIDs) > 0 {
|
if len(channelIDs) > 0 {
|
||||||
@@ -107,10 +106,8 @@ func postProcessChannels(c *web.Context, channels []*model.Channel) ([]*channel,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pref, appErr = c.App.GetPreferenceByCategoryAndNameForUser(c.AppContext.Session().UserId, "display_settings", "name_format")
|
user := &model.User{Id: c.AppContext.Session().UserId}
|
||||||
if appErr != nil {
|
nameFormat = c.App.GetNotificationNameFormat(user)
|
||||||
return nil, appErr
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to the wrapper format.
|
// Convert to the wrapper format.
|
||||||
@@ -124,7 +121,7 @@ func postProcessChannels(c *web.Context, channels []*model.Channel) ([]*channel,
|
|||||||
if users == nil {
|
if users == nil {
|
||||||
return nil, fmt.Errorf("user info not found for channel id: %s", ch.Id)
|
return nil, fmt.Errorf("user info not found for channel id: %s", ch.Id)
|
||||||
}
|
}
|
||||||
prettyName = getPrettyDNForUsers(pref.Value, users, c.AppContext.Session().UserId)
|
prettyName = getPrettyDNForUsers(nameFormat, users, c.AppContext.Session().UserId)
|
||||||
}
|
}
|
||||||
|
|
||||||
res = append(res, &channel{Channel: *ch, PrettyDisplayName: prettyName})
|
res = append(res, &channel{Channel: *ch, PrettyDisplayName: prettyName})
|
||||||
|
|||||||
@@ -26,20 +26,22 @@ func TestGraphQLChannels(t *testing.T) {
|
|||||||
th.LinkUserToTeam(th.BasicUser, myTeam)
|
th.LinkUserToTeam(th.BasicUser, myTeam)
|
||||||
th.App.AddUserToChannel(th.BasicUser, ch1, false)
|
th.App.AddUserToChannel(th.BasicUser, ch1, false)
|
||||||
th.App.AddUserToChannel(th.BasicUser, ch2, false)
|
th.App.AddUserToChannel(th.BasicUser, ch2, false)
|
||||||
|
th.CreateDmChannel(th.BasicUser2)
|
||||||
|
|
||||||
var q struct {
|
var q struct {
|
||||||
Channels []struct {
|
Channels []struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
CreateAt float64 `json:"createAt"`
|
CreateAt float64 `json:"createAt"`
|
||||||
UpdateAt float64 `json:"updateAt"`
|
UpdateAt float64 `json:"updateAt"`
|
||||||
Type model.ChannelType `json:"type"`
|
Type model.ChannelType `json:"type"`
|
||||||
DisplayName string `json:"displayName"`
|
DisplayName string `json:"displayName"`
|
||||||
Name string `json:"name"`
|
PrettyDisplayName string `json:"prettyDisplayName"`
|
||||||
Header string `json:"header"`
|
Name string `json:"name"`
|
||||||
Purpose string `json:"purpose"`
|
Header string `json:"header"`
|
||||||
SchemeId string `json:"schemeId"`
|
Purpose string `json:"purpose"`
|
||||||
Cursor string `json:"cursor"`
|
SchemeId string `json:"schemeId"`
|
||||||
Team struct {
|
Cursor string `json:"cursor"`
|
||||||
|
Team struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
DisplayName string `json:"displayName"`
|
DisplayName string `json:"displayName"`
|
||||||
} `json:"team"`
|
} `json:"team"`
|
||||||
@@ -63,6 +65,7 @@ func TestGraphQLChannels(t *testing.T) {
|
|||||||
updateAt
|
updateAt
|
||||||
type
|
type
|
||||||
displayName
|
displayName
|
||||||
|
prettyDisplayName
|
||||||
name
|
name
|
||||||
header
|
header
|
||||||
purpose
|
purpose
|
||||||
@@ -77,7 +80,7 @@ func TestGraphQLChannels(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, resp.Errors, 0)
|
require.Len(t, resp.Errors, 0)
|
||||||
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
||||||
assert.Len(t, q.Channels, 9)
|
assert.Len(t, q.Channels, 10)
|
||||||
|
|
||||||
numPrivate := 0
|
numPrivate := 0
|
||||||
numPublic := 0
|
numPublic := 0
|
||||||
@@ -87,6 +90,7 @@ func TestGraphQLChannels(t *testing.T) {
|
|||||||
assert.NotEmpty(t, ch.ID)
|
assert.NotEmpty(t, ch.ID)
|
||||||
assert.NotEmpty(t, ch.Name)
|
assert.NotEmpty(t, ch.Name)
|
||||||
assert.NotEmpty(t, ch.Cursor)
|
assert.NotEmpty(t, ch.Cursor)
|
||||||
|
assert.NotEmpty(t, ch.PrettyDisplayName)
|
||||||
assert.NotEmpty(t, ch.CreateAt)
|
assert.NotEmpty(t, ch.CreateAt)
|
||||||
assert.NotEmpty(t, ch.UpdateAt)
|
assert.NotEmpty(t, ch.UpdateAt)
|
||||||
if ch.Type == model.ChannelTypeOpen {
|
if ch.Type == model.ChannelTypeOpen {
|
||||||
@@ -192,7 +196,7 @@ func TestGraphQLChannels(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, resp.Errors, 0)
|
require.Len(t, resp.Errors, 0)
|
||||||
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
||||||
assert.Len(t, q.Channels, 1)
|
assert.Len(t, q.Channels, 2)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("team_filter", func(t *testing.T) {
|
t.Run("team_filter", func(t *testing.T) {
|
||||||
@@ -215,7 +219,7 @@ func TestGraphQLChannels(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, resp.Errors, 0)
|
require.Len(t, resp.Errors, 0)
|
||||||
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
||||||
assert.Len(t, q.Channels, 4)
|
assert.Len(t, q.Channels, 5)
|
||||||
|
|
||||||
input = graphQLInput{
|
input = graphQLInput{
|
||||||
OperationName: "channels",
|
OperationName: "channels",
|
||||||
@@ -248,7 +252,7 @@ func TestGraphQLChannels(t *testing.T) {
|
|||||||
OperationName: "channels",
|
OperationName: "channels",
|
||||||
Query: query,
|
Query: query,
|
||||||
Variables: map[string]interface{}{
|
Variables: map[string]interface{}{
|
||||||
"first": 1,
|
"first": 2,
|
||||||
"teamId": myTeam.Id,
|
"teamId": myTeam.Id,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -257,11 +261,16 @@ func TestGraphQLChannels(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, resp.Errors, 0)
|
require.Len(t, resp.Errors, 0)
|
||||||
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
||||||
assert.Len(t, q.Channels, 1)
|
assert.Len(t, q.Channels, 2)
|
||||||
|
|
||||||
|
// Iterating because one of them can be a DM channel.
|
||||||
|
for _, ch := range q.Channels {
|
||||||
|
if ch.Team.ID != "" {
|
||||||
|
assert.Equal(t, myTeam.Id, ch.Team.ID)
|
||||||
|
assert.Equal(t, myTeam.DisplayName, ch.Team.DisplayName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gotTeam := q.Channels[0].Team
|
|
||||||
assert.Equal(t, myTeam.Id, gotTeam.ID)
|
|
||||||
assert.Equal(t, myTeam.DisplayName, gotTeam.DisplayName)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Delete+Update", func(t *testing.T) {
|
t.Run("Delete+Update", func(t *testing.T) {
|
||||||
@@ -286,7 +295,7 @@ func TestGraphQLChannels(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, resp.Errors, 0)
|
require.Len(t, resp.Errors, 0)
|
||||||
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
||||||
assert.Len(t, q.Channels, 9)
|
assert.Len(t, q.Channels, 10)
|
||||||
|
|
||||||
now := model.GetMillis()
|
now := model.GetMillis()
|
||||||
input = graphQLInput{
|
input = graphQLInput{
|
||||||
@@ -339,7 +348,7 @@ func TestGraphQLChannels(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, resp.Errors, 0)
|
require.Len(t, resp.Errors, 0)
|
||||||
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
||||||
assert.Len(t, q.Channels, 7)
|
assert.Len(t, q.Channels, 8)
|
||||||
|
|
||||||
input = graphQLInput{
|
input = graphQLInput{
|
||||||
OperationName: "channels",
|
OperationName: "channels",
|
||||||
@@ -354,7 +363,7 @@ func TestGraphQLChannels(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, resp.Errors, 0)
|
require.Len(t, resp.Errors, 0)
|
||||||
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
||||||
assert.Len(t, q.Channels, 7)
|
assert.Len(t, q.Channels, 8)
|
||||||
|
|
||||||
input = graphQLInput{
|
input = graphQLInput{
|
||||||
OperationName: "channels",
|
OperationName: "channels",
|
||||||
@@ -397,7 +406,7 @@ func TestGraphQLChannels(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, resp.Errors, 0)
|
require.Len(t, resp.Errors, 0)
|
||||||
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
||||||
require.Len(t, q.Channels, 2)
|
require.Len(t, q.Channels, 3)
|
||||||
for _, ch := range q.Channels {
|
for _, ch := range q.Channels {
|
||||||
require.Equal(t, ch.ID, ch.Stats.ChannelId)
|
require.Equal(t, ch.ID, ch.Stats.ChannelId)
|
||||||
count, appErr := th.App.GetChannelMemberCount(ch.Stats.ChannelId)
|
count, appErr := th.App.GetChannelMemberCount(ch.Stats.ChannelId)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user