MM-11529: Allow to Leave an archived channel from the API (#9204)
* MM-11529: Allow to Leave an archived channel from the API * Remove the restriction to remove user from archive channel to yourself
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7a731d2bd1
Коммит
8cc4f27f7c
@@ -1974,6 +1974,18 @@ func TestRemoveChannelMember(t *testing.T) {
|
||||
_, resp = th.SystemAdminClient.RemoveUserFromChannel(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
// Leave deleted channel
|
||||
th.LoginBasic()
|
||||
deletedChannel := th.CreatePublicChannel()
|
||||
th.App.AddUserToChannel(th.BasicUser, deletedChannel)
|
||||
th.App.AddUserToChannel(th.BasicUser2, deletedChannel)
|
||||
|
||||
deletedChannel.DeleteAt = 1
|
||||
th.App.UpdateChannel(deletedChannel)
|
||||
|
||||
_, resp = Client.RemoveUserFromChannel(deletedChannel.Id, th.BasicUser.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
th.LoginBasic()
|
||||
private := th.CreatePrivateChannel()
|
||||
th.App.AddUserToChannel(th.BasicUser2, private)
|
||||
|
||||
@@ -1380,11 +1380,6 @@ func (a *App) postRemoveFromChannelMessage(removerUserId string, removedUser *mo
|
||||
}
|
||||
|
||||
func (a *App) removeUserFromChannel(userIdToRemove string, removerUserId string, channel *model.Channel) *model.AppError {
|
||||
if channel.DeleteAt > 0 {
|
||||
err := model.NewAppError("RemoveUserFromChannel", "api.channel.remove_user_from_channel.deleted.app_error", nil, "", http.StatusBadRequest)
|
||||
return err
|
||||
}
|
||||
|
||||
if channel.Name == model.DEFAULT_CHANNEL {
|
||||
return model.NewAppError("RemoveUserFromChannel", "api.channel.remove.default.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}, "", http.StatusBadRequest)
|
||||
}
|
||||
@@ -1449,11 +1444,6 @@ func (a *App) RemoveUserFromChannel(userIdToRemove string, removerUserId string,
|
||||
if userIdToRemove == removerUserId {
|
||||
a.postLeaveChannelMessage(user, channel)
|
||||
} else {
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.Go(func() {
|
||||
a.postRemoveFromChannelMessage(removerUserId, user, channel)
|
||||
})
|
||||
|
||||
@@ -22,6 +22,11 @@ const (
|
||||
)
|
||||
|
||||
func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList) ([]string, *model.AppError) {
|
||||
// Do not send notifications in archived channels
|
||||
if channel.DeleteAt > 0 {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
pchan := a.Srv.Store.User().GetAllProfilesInChannel(channel.Id, true)
|
||||
cmnchan := a.Srv.Store.Channel().GetAllChannelMembersNotifyPropsForChannel(channel.Id, true)
|
||||
var fchan store.StoreChannel
|
||||
|
||||
@@ -78,6 +78,11 @@ func TestSendNotifications(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
th.BasicChannel.DeleteAt = 1
|
||||
mentions, err = th.App.SendNotifications(post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil)
|
||||
assert.Nil(t, err)
|
||||
assert.Len(t, mentions, 0)
|
||||
}
|
||||
|
||||
func TestGetExplicitMentions(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user