MM-21481: Fixed several issues from user marshalling (#13627)

* MM-21481: Fixed several issues from user marshalling

- Fixed the root cause for panic by properly converting
the map to a User struct.
- Added a check for type conversion for extra safety.
- Fixed a somewhat unrelated issue of a pointer to pointer reference.

* Fix tests
Этот коммит содержится в:
Agniva De Sarker
2020-01-16 13:48:08 +05:30
коммит произвёл Claudio Costa
родитель 87eb7697f9
Коммит 2a28edcd93
5 изменённых файлов: 28 добавлений и 9 удалений

Просмотреть файл

@@ -1111,7 +1111,7 @@ func (a *App) sendUpdatedUserEvent(user model.User) {
adminCopyOfUser := user.DeepCopy()
a.SanitizeProfile(adminCopyOfUser, true)
adminMessage := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_USER_UPDATED, "", "", "", nil)
adminMessage.Add("user", &adminCopyOfUser)
adminMessage.Add("user", adminCopyOfUser)
adminMessage.GetBroadcast().ContainsSensitiveData = true
a.Publish(adminMessage)

Просмотреть файл

@@ -305,7 +305,12 @@ func (wc *WebConn) shouldSendEventToGuest(msg *model.WebSocketEvent) bool {
switch msg.EventType() {
case model.WEBSOCKET_EVENT_USER_UPDATED:
userId = msg.GetData()["user"].(*model.User).Id
user, ok := msg.GetData()["user"].(*model.User)
if !ok {
mlog.Error("webhub.shouldSendEvent: user not found in message", mlog.Any("user", msg.GetData()["user"]))
return false
}
userId = user.Id
case model.WEBSOCKET_EVENT_NEW_USER:
userId = msg.GetData()["user_id"].(string)
default: