MM-45993: Return errors during sending websocket messages (#20760)
During attaching an object to a websocket message, we would marshal it to json and attach the string output. But if the marshalling failed, we would just log a warning and move on. This would add an empty string to the message. But the client assumes that the object is correctly attached and would fail silently if it cannot find it. So we become more strict and return the error so that it reaches the caller. https://mattermost.atlassian.net/browse/MM-45993 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
151f295d82
Коммит
14246abdef
@@ -18,7 +18,7 @@ import (
|
||||
// only that channel's members are created. If channelID is nil all channel memberships are created.
|
||||
// If includeRemovedMembers is true, then channel members who left or were removed from the channel will
|
||||
// be re-added; otherwise, they will not be re-added.
|
||||
func (a *App) createDefaultChannelMemberships(c *request.Context, since int64, channelID *string, includeRemovedMembers bool) error {
|
||||
func (a *App) createDefaultChannelMemberships(c request.CTX, since int64, channelID *string, includeRemovedMembers bool) error {
|
||||
channelMembers, appErr := a.ChannelMembersToAdd(since, channelID, includeRemovedMembers)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
@@ -40,7 +40,7 @@ func (a *App) createDefaultChannelMemberships(c *request.Context, since int64, c
|
||||
_, err = a.AddTeamMember(c, channel.TeamId, userChannel.UserID)
|
||||
if err != nil {
|
||||
if err.Id == "api.team.join_user_to_team.allowed_domains.app_error" {
|
||||
a.Log().Info("User not added to channel - the domain associated with the user is not in the list of allowed team domains",
|
||||
c.Logger().Info("User not added to channel - the domain associated with the user is not in the list of allowed team domains",
|
||||
mlog.String("user_id", userChannel.UserID),
|
||||
mlog.String("channel_id", userChannel.ChannelID),
|
||||
mlog.String("team_id", channel.TeamId),
|
||||
@@ -49,7 +49,7 @@ func (a *App) createDefaultChannelMemberships(c *request.Context, since int64, c
|
||||
}
|
||||
return err
|
||||
}
|
||||
a.Log().Info("added teammember",
|
||||
c.Logger().Info("added teammember",
|
||||
mlog.String("user_id", userChannel.UserID),
|
||||
mlog.String("team_id", channel.TeamId),
|
||||
)
|
||||
@@ -60,7 +60,7 @@ func (a *App) createDefaultChannelMemberships(c *request.Context, since int64, c
|
||||
})
|
||||
if err != nil {
|
||||
if err.Id == "api.channel.add_user.to.channel.failed.deleted.app_error" {
|
||||
a.Log().Info("Not adding user to channel because they have already left the team",
|
||||
c.Logger().Info("Not adding user to channel because they have already left the team",
|
||||
mlog.String("user_id", userChannel.UserID),
|
||||
mlog.String("channel_id", userChannel.ChannelID),
|
||||
)
|
||||
@@ -69,7 +69,7 @@ func (a *App) createDefaultChannelMemberships(c *request.Context, since int64, c
|
||||
}
|
||||
}
|
||||
|
||||
a.Log().Info("added channelmember",
|
||||
c.Logger().Info("added channelmember",
|
||||
mlog.String("user_id", userChannel.UserID),
|
||||
mlog.String("channel_id", userChannel.ChannelID),
|
||||
)
|
||||
@@ -83,7 +83,7 @@ func (a *App) createDefaultChannelMemberships(c *request.Context, since int64, c
|
||||
// only that team's members are created. If teamID is nil all team memberships are created.
|
||||
// If includeRemovedMembers is true, then team members who left or were removed from the team will
|
||||
// be re-added; otherwise, they will not be re-added.
|
||||
func (a *App) createDefaultTeamMemberships(c *request.Context, since int64, teamID *string, includeRemovedMembers bool) error {
|
||||
func (a *App) createDefaultTeamMemberships(c request.CTX, since int64, teamID *string, includeRemovedMembers bool) error {
|
||||
teamMembers, appErr := a.TeamMembersToAdd(since, teamID, includeRemovedMembers)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
@@ -93,7 +93,7 @@ func (a *App) createDefaultTeamMemberships(c *request.Context, since int64, team
|
||||
_, err := a.AddTeamMember(c, userTeam.TeamID, userTeam.UserID)
|
||||
if err != nil {
|
||||
if err.Id == "api.team.join_user_to_team.allowed_domains.app_error" {
|
||||
a.Log().Info("User not added to team - the domain associated with the user is not in the list of allowed team domains",
|
||||
c.Logger().Info("User not added to team - the domain associated with the user is not in the list of allowed team domains",
|
||||
mlog.String("user_id", userTeam.UserID),
|
||||
mlog.String("team_id", userTeam.TeamID),
|
||||
)
|
||||
@@ -102,7 +102,7 @@ func (a *App) createDefaultTeamMemberships(c *request.Context, since int64, team
|
||||
return err
|
||||
}
|
||||
|
||||
a.Log().Info("added teammember",
|
||||
c.Logger().Info("added teammember",
|
||||
mlog.String("user_id", userTeam.UserID),
|
||||
mlog.String("team_id", userTeam.TeamID),
|
||||
)
|
||||
@@ -148,7 +148,7 @@ func (a *App) DeleteGroupConstrainedMemberships(c *request.Context) error {
|
||||
// deleteGroupConstrainedTeamMemberships deletes team memberships of users who aren't members of the allowed
|
||||
// groups of the given group-constrained team. If a teamID is given then the procedure is scoped to the given team,
|
||||
// if teamID is nil then the procedure affects all teams.
|
||||
func (a *App) deleteGroupConstrainedTeamMemberships(c *request.Context, teamID *string) error {
|
||||
func (a *App) deleteGroupConstrainedTeamMemberships(c request.CTX, teamID *string) error {
|
||||
teamMembers, appErr := a.TeamMembersToRemove(teamID)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
@@ -160,7 +160,7 @@ func (a *App) deleteGroupConstrainedTeamMemberships(c *request.Context, teamID *
|
||||
return err
|
||||
}
|
||||
|
||||
a.Log().Info("removed teammember",
|
||||
c.Logger().Info("removed teammember",
|
||||
mlog.String("user_id", userTeam.UserId),
|
||||
mlog.String("team_id", userTeam.TeamId),
|
||||
)
|
||||
@@ -172,7 +172,7 @@ func (a *App) deleteGroupConstrainedTeamMemberships(c *request.Context, teamID *
|
||||
// deleteGroupConstrainedChannelMemberships deletes channel memberships of users who aren't members of the allowed
|
||||
// groups of the given group-constrained channel. If a channelID is given then the procedure is scoped to the given team,
|
||||
// if channelID is nil then the procedure affects all teams.
|
||||
func (a *App) deleteGroupConstrainedChannelMemberships(c *request.Context, channelID *string) error {
|
||||
func (a *App) deleteGroupConstrainedChannelMemberships(c request.CTX, channelID *string) error {
|
||||
channelMembers, appErr := a.ChannelMembersToRemove(channelID)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
@@ -233,7 +233,7 @@ func (a *App) SyncSyncableRoles(syncableID string, syncableType model.GroupSynca
|
||||
|
||||
// SyncRolesAndMembership updates the SchemeAdmin status and membership of all of the members of the given
|
||||
// syncable.
|
||||
func (a *App) SyncRolesAndMembership(c *request.Context, syncableID string, syncableType model.GroupSyncableType, includeRemovedMembers bool) {
|
||||
func (a *App) SyncRolesAndMembership(c request.CTX, syncableID string, syncableType model.GroupSyncableType, includeRemovedMembers bool) {
|
||||
a.SyncSyncableRoles(syncableID, syncableType)
|
||||
|
||||
lastJob, _ := a.Srv().Store.Job().GetNewestJobByStatusAndType(model.JobStatusSuccess, model.JobTypeLdapSync)
|
||||
@@ -246,10 +246,14 @@ func (a *App) SyncRolesAndMembership(c *request.Context, syncableID string, sync
|
||||
case model.GroupSyncableTypeTeam:
|
||||
a.createDefaultTeamMemberships(c, since, &syncableID, includeRemovedMembers)
|
||||
a.deleteGroupConstrainedTeamMemberships(c, &syncableID)
|
||||
a.ClearTeamMembersCache(syncableID)
|
||||
if err := a.ClearTeamMembersCache(syncableID); err != nil {
|
||||
c.Logger().Warn("Error clearing team members cache", mlog.Err(err))
|
||||
}
|
||||
case model.GroupSyncableTypeChannel:
|
||||
a.createDefaultChannelMemberships(c, since, &syncableID, includeRemovedMembers)
|
||||
a.deleteGroupConstrainedChannelMemberships(c, &syncableID)
|
||||
a.ClearChannelMembersCache(c, syncableID)
|
||||
if err := a.ClearChannelMembersCache(c, syncableID); err != nil {
|
||||
c.Logger().Warn("Error clearing channel members cache", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user