[MM-56174] Account for archived channels in channel member for post permission check (#25837)

* [MM-56174] Account for archived channels in channel member for post permission check

* Add tests
Этот коммит содержится в:
Devin Binnie
2024-01-10 15:50:00 -05:00
коммит произвёл GitHub
родитель 1d108f0d9f
Коммит 43cca04f04
9 изменённых файлов: 129 добавлений и 21 удалений

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

@@ -2107,7 +2107,7 @@ func (s SqlChannelStore) IsUserInChannelUseCache(userId string, channelId string
return false
}
func (s SqlChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, error) {
func (s SqlChannelStore) GetMemberForPost(postId string, userId string, includeArchivedChannels bool) (*model.ChannelMember, error) {
var dbMember channelMemberWithSchemeRoles
query := `
SELECT
@@ -2147,6 +2147,10 @@ func (s SqlChannelStore) GetMemberForPost(postId string, userId string) (*model.
ChannelMembers.UserId = ?
AND
Posts.Id = ?`
if !includeArchivedChannels {
query += " AND Channels.DeleteAt = 0"
}
if err := s.GetReplicaX().Get(&dbMember, query, userId, postId); err != nil {
return nil, errors.Wrapf(err, "failed to get ChannelMember with postId=%s and userId=%s", postId, userId)
}