Improve self checks when adding a new channel member (#33404) (#33925)

Automatic Merge
Этот коммит содержится в:
Mattermost Build
2025-09-18 10:19:15 +03:00
коммит произвёл GitHub
родитель 98acefe911
Коммит fcd316844e
2 изменённых файлов: 43 добавлений и 6 удалений

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

@@ -1972,16 +1972,15 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
lastError = err
continue
}
} else {
// user is already a member, go to next
c.Logger.Warn("User is already a channel member, skipping", mlog.String("UserId", userId), mlog.String("ChannelId", channel.Id))
newChannelMembers = append(newChannelMembers, *existingMember)
continue
}
if channel.Type == model.ChannelTypeOpen {
isSelfAdd := member.UserId == c.AppContext.Session().UserId
if isSelfAdd && !canAddSelf {
if isSelfAdd && existingMember != nil {
// users should be able to add themselves if they're already a member, even if they don't have permissions
newChannelMembers = append(newChannelMembers, *existingMember)
continue
} else if isSelfAdd && !canAddSelf {
c.Logger.Warn("Error adding channel member, Invalid Permission to add self", mlog.String("UserId", userId), mlog.String("ChannelId", channel.Id))
c.SetPermissionError(model.PermissionJoinPublicChannels)
lastError = c.Err
@@ -1994,6 +1993,13 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
if existingMember != nil {
// user is already a member, go to next
c.Logger.Warn("User is already a channel member, skipping", mlog.String("UserId", userId), mlog.String("ChannelId", channel.Id))
newChannelMembers = append(newChannelMembers, *existingMember)
continue
}
cm, err := c.App.AddChannelMember(c.AppContext, member.UserId, channel, app.ChannelMemberOpts{
UserRequestorID: c.AppContext.Session().UserId,
PostRootID: postRootId,