MM-15485: In-channel system behaviour for at-mentions and slash commands for group-constrained channels. (#10855)
* MM-15108: Prevent non-group-members from being added to group-constrained channels. * MM-15485: Updates ephemeral message when non-group member is invited to group-constrained channel. * MM-15485: Prevent group-permitted members from being removed from group-constrained channels. Show custom ephemeral when attempting /kick or /remove.
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
6d2fa0f3d2
Коммит
8d8a4d8614
@@ -897,6 +897,16 @@ func (a *App) addUserToChannel(user *model.User, channel *model.Channel, teamMem
|
||||
return channelMember, nil
|
||||
}
|
||||
|
||||
if channel.IsGroupConstrained() {
|
||||
nonMembers, err := a.FilterNonGroupChannelMembers([]string{user.Id}, channel)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("addUserToChannel", "api.channel.add_user_to_channel.type.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
if len(nonMembers) > 0 {
|
||||
return nil, model.NewAppError("addUserToChannel", "api.channel.add_members.user_denied", map[string]interface{}{"UserIDs": nonMembers}, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
newMember := &model.ChannelMember{
|
||||
ChannelId: channel.Id,
|
||||
UserId: user.Id,
|
||||
@@ -1593,6 +1603,16 @@ func (a *App) removeUserFromChannel(userIdToRemove string, removerUserId string,
|
||||
return model.NewAppError("RemoveUserFromChannel", "api.channel.remove.default.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if channel.IsGroupConstrained() && userIdToRemove != removerUserId {
|
||||
nonMembers, err := a.FilterNonGroupChannelMembers([]string{userIdToRemove}, channel)
|
||||
if err != nil {
|
||||
return model.NewAppError("removeUserFromChannel", "api.channel.remove_user_from_channel.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
if len(nonMembers) == 0 {
|
||||
return model.NewAppError("removeUserFromChannel", "api.channel.remove_members.denied", map[string]interface{}{"UserIDs": nonMembers}, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
cm, err := a.GetChannelMember(channel.Id, userIdToRemove)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -142,8 +142,14 @@ func (me *InviteProvider) DoCommand(a *App, args *model.CommandArgs, message str
|
||||
}
|
||||
|
||||
if _, err := a.AddChannelMember(userProfile.Id, channelToJoin, args.Session.UserId, ""); err != nil {
|
||||
var text string
|
||||
if err.Id == "api.channel.add_members.user_denied" {
|
||||
text = args.T("api.command_invite.group_constrained_user_denied")
|
||||
} else {
|
||||
text = args.T("api.command_invite.fail.app_error")
|
||||
}
|
||||
return &model.CommandResponse{
|
||||
Text: args.T("api.command_invite.fail.app_error"),
|
||||
Text: text,
|
||||
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,10 +135,16 @@ func doCommand(a *App, args *model.CommandArgs, message string) *model.CommandRe
|
||||
}
|
||||
|
||||
if err = a.RemoveUserFromChannel(userProfile.Id, args.UserId, channel); err != nil {
|
||||
return &model.CommandResponse{
|
||||
Text: args.T(err.Id, map[string]interface{}{
|
||||
var text string
|
||||
if err.Id == "api.channel.remove_members.denied" {
|
||||
text = args.T("api.command_remove.group_constrained_user_denied")
|
||||
} else {
|
||||
text = args.T(err.Id, map[string]interface{}{
|
||||
"Channel": model.DEFAULT_CHANNEL,
|
||||
}),
|
||||
})
|
||||
}
|
||||
return &model.CommandResponse{
|
||||
Text: text,
|
||||
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
var outOfChannelMentions model.UserSlice
|
||||
var outOfGroupsMentions model.UserSlice
|
||||
|
||||
if channel.GroupConstrained != nil && *channel.GroupConstrained {
|
||||
if channel.IsGroupConstrained() {
|
||||
nonMemberIDs, err := a.FilterNonGroupChannelMembers(channelMentions.IDs(), channel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -437,7 +437,7 @@ func (a *App) AddUserToTeamByToken(userId string, tokenId string) (*model.Team,
|
||||
}
|
||||
team := result.Data.(*model.Team)
|
||||
|
||||
if team.GroupConstrained != nil && *team.GroupConstrained {
|
||||
if team.IsGroupConstrained() {
|
||||
return nil, model.NewAppError("AddUserToTeamByToken", "app.team.invite_token.group_constrained.error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
@@ -789,7 +789,7 @@ func (a *App) AddTeamMemberByInviteId(inviteId, userId string) (*model.TeamMembe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if team.GroupConstrained != nil && *team.GroupConstrained {
|
||||
if team.IsGroupConstrained() {
|
||||
return nil, model.NewAppError("AddTeamMemberByInviteId", "app.team.invite_id.group_constrained.error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user