Fix potential nil dereference in app.isChannelArchivedAndHidden (#30628)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a219fbcfa1
Коммит
7250095f86
@@ -85,13 +85,15 @@ func (a *App) SessionHasPermissionToChannel(c request.CTX, session model.Session
|
||||
channel, appErr := a.GetChannel(c, channelID)
|
||||
if appErr != nil && appErr.StatusCode == http.StatusNotFound {
|
||||
return false
|
||||
} else if appErr != nil {
|
||||
c.Logger().Warn("Failed to get channel", mlog.String("channel_id", channelID), mlog.Err(appErr))
|
||||
}
|
||||
|
||||
if session.IsUnrestricted() || a.RolesGrantPermission(session.GetUserRoles(), model.PermissionManageSystem.Id) {
|
||||
return true
|
||||
}
|
||||
|
||||
if a.isChannelArchivedAndHidden(channel) {
|
||||
if appErr == nil && a.isChannelArchivedAndHidden(channel) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -187,6 +187,15 @@ func TestSessionHasPermissionToChannel(t *testing.T) {
|
||||
// If there's an error returned from the GetChannel call the code should continue to cascade and since there
|
||||
// are no session level permissions in this test case, the permission should be denied.
|
||||
assert.False(t, th.App.SessionHasPermissionToChannel(th.Context, session, th.BasicUser.Id, model.PermissionAddReaction))
|
||||
|
||||
// MM-63624, check with TeamSettings.ExperimentalViewArchivedChannels off
|
||||
th.App.Srv().SetStore(mainHelper.GetStore())
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.TeamSettings.ExperimentalViewArchivedChannels = false
|
||||
})
|
||||
|
||||
th.App.Srv().SetStore(&mockStore)
|
||||
assert.False(t, th.App.SessionHasPermissionToChannel(th.Context, session, th.BasicUser.Id, model.PermissionAddReaction))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -327,6 +336,14 @@ func TestSessionHasPermissionToChannels(t *testing.T) {
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
assert.False(t, th.App.SessionHasPermissionToChannels(th.Context, session, allChannels, model.PermissionReadChannel))
|
||||
|
||||
// MM-63624, check with TeamSettings.ExperimentalViewArchivedChannels off
|
||||
th.App.Srv().SetStore(mainHelper.GetStore())
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.TeamSettings.ExperimentalViewArchivedChannels = false
|
||||
})
|
||||
th.App.Srv().SetStore(&mockStore)
|
||||
assert.False(t, th.App.SessionHasPermissionToChannels(th.Context, session, allChannels, model.PermissionReadChannel))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user