MM-37575: Handle nil value in override_username (#18057)
* MM-37575: Handle nil value in override_username
Since props is a map[string]interface{}, an ", ok" check doesn't
really help because even if a key is not present, by default, a map
will always return the default value of the value, which would be a
nil interface.
So we can just check for the value of the map instead.
https://mattermost.atlassian.net/browse/MM-37575
```release-note
NONE
```
* Fix for integer case as well
```release-note
NONE
```
* Update app/notification.go
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
20a73757d0
Коммит
7c22202330
@@ -1068,8 +1068,10 @@ func (n *PostNotification) GetSenderName(userNameFormat string, overridesAllowed
|
|||||||
}
|
}
|
||||||
|
|
||||||
if overridesAllowed && n.Channel.Type != model.ChannelTypeDirect {
|
if overridesAllowed && n.Channel.Type != model.ChannelTypeDirect {
|
||||||
if value, ok := n.Post.GetProps()["override_username"]; ok && n.Post.GetProp("from_webhook") == "true" {
|
if value := n.Post.GetProps()["override_username"]; value != nil && n.Post.GetProp("from_webhook") == "true" {
|
||||||
return value.(string)
|
if s, ok := value.(string); ok {
|
||||||
|
return s
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1799,6 +1799,20 @@ func TestPostNotificationGetSenderName(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
overriddenPost2 := &model.Post{
|
||||||
|
Props: model.StringInterface{
|
||||||
|
"override_username": nil,
|
||||||
|
"from_webhook": "true",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
overriddenPost3 := &model.Post{
|
||||||
|
Props: model.StringInterface{
|
||||||
|
"override_username": 10,
|
||||||
|
"from_webhook": "true",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
for name, testCase := range map[string]struct {
|
for name, testCase := range map[string]struct {
|
||||||
channel *model.Channel
|
channel *model.Channel
|
||||||
post *model.Post
|
post *model.Post
|
||||||
@@ -1841,6 +1855,16 @@ func TestPostNotificationGetSenderName(t *testing.T) {
|
|||||||
allowOverrides: false,
|
allowOverrides: false,
|
||||||
expected: "@" + sender.Username,
|
expected: "@" + sender.Username,
|
||||||
},
|
},
|
||||||
|
"nil override_username": {
|
||||||
|
post: overriddenPost2,
|
||||||
|
allowOverrides: true,
|
||||||
|
expected: "@" + sender.Username,
|
||||||
|
},
|
||||||
|
"integer override_username": {
|
||||||
|
post: overriddenPost3,
|
||||||
|
allowOverrides: true,
|
||||||
|
expected: "@" + sender.Username,
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
channel := defaultChannel
|
channel := defaultChannel
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user