[MM-49989] Pass a context.Context to Client4 methods (#22922)

* Migrate all method in model/client4.go to accept a context.Context

* Fix th.*Client

* Fix remaining issues

* Empty commit to triger CI

* Fix test

* Add cancellation test

* Test that returned error is context.Canceled

* Fix bad merge

* Update mmctl code

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Ben Schumacher
2023-06-06 23:29:29 +02:00
коммит произвёл GitHub
родитель 7116e9267a
Коммит 6c82605df0
140 изменённых файлов: 7516 добавлений и 7333 удалений

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

@@ -4,6 +4,7 @@
package commands
import (
"context"
"fmt"
"github.com/hashicorp/go-multierror"
@@ -72,7 +73,7 @@ func addUserToChannel(c client.Client, channel *model.Channel, user *model.User,
printer.PrintError("Can't find user '" + userArg + "'")
return
}
if _, _, err := c.AddChannelMember(channel.Id, user.Id); err != nil {
if _, _, err := c.AddChannelMember(context.TODO(), channel.Id, user.Id); err != nil {
printer.PrintError("Unable to add '" + userArg + "' to " + channel.Name + ". Error: " + err.Error())
}
}
@@ -111,21 +112,21 @@ func removeUserFromChannel(c client.Client, channel *model.Channel, user *model.
printer.PrintError("Can't find user '" + userArg + "'")
return
}
if _, err := c.RemoveUserFromChannel(channel.Id, user.Id); err != nil {
if _, err := c.RemoveUserFromChannel(context.TODO(), channel.Id, user.Id); err != nil {
printer.PrintError("Unable to remove '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
}
}
func removeAllUsersFromChannel(c client.Client, channel *model.Channel) error {
var result *multierror.Error
members, _, err := c.GetChannelMembers(channel.Id, 0, 10000, "")
members, _, err := c.GetChannelMembers(context.TODO(), channel.Id, 0, 10000, "")
if err != nil {
printer.PrintError("Unable to remove all users from " + channel.Name + ". Error: " + err.Error())
return fmt.Errorf("unable to remove all users from %q: %w", channel.Name, err)
}
for _, member := range members {
if _, err := c.RemoveUserFromChannel(channel.Id, member.UserId); err != nil {
if _, err := c.RemoveUserFromChannel(context.TODO(), channel.Id, member.UserId); err != nil {
result = multierror.Append(result, fmt.Errorf("unable to remove %q from %q Error: %w", member.UserId, channel.Name, err))
printer.PrintError("Unable to remove '" + member.UserId + "' from " + channel.Name + ". Error: " + err.Error())
}