* add request context

* move initialialization to server

* use app interface instead of global app functions

* remove app context from webconn

* cleanup

* remove duplicated services

* move context to separate package

* remove finalize init method and move content to NewServer function

* restart workers and schedulers after adding license for tests

* reflect review comments

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2021-05-11 13:00:44 +03:00
коммит произвёл GitHub
родитель c09369f14a
Коммит 5ea06e51d0
235 изменённых файлов: 4048 добавлений и 3819 удалений

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils"
)
@@ -35,7 +36,7 @@ func NewAutoChannelCreator(a *app.App, team *model.Team, userID string) *AutoCha
}
}
func (cfg *AutoChannelCreator) createRandomChannel() (*model.Channel, error) {
func (cfg *AutoChannelCreator) createRandomChannel(c *request.Context) (*model.Channel, error) {
var displayName string
if cfg.Fuzzy {
displayName = utils.FuzzName()
@@ -52,20 +53,20 @@ func (cfg *AutoChannelCreator) createRandomChannel() (*model.Channel, error) {
CreatorId: cfg.userID,
}
channel, err := cfg.a.CreateChannel(channel, true)
channel, err := cfg.a.CreateChannel(c, channel, true)
if err != nil {
return nil, err
}
return channel, nil
}
func (cfg *AutoChannelCreator) CreateTestChannels(num utils.Range) ([]*model.Channel, error) {
func (cfg *AutoChannelCreator) CreateTestChannels(c *request.Context, num utils.Range) ([]*model.Channel, error) {
numChannels := utils.RandIntFromRange(num)
channels := make([]*model.Channel, numChannels)
for i := 0; i < numChannels; i++ {
var err error
channels[i], err = cfg.createRandomChannel()
channels[i], err = cfg.createRandomChannel(c)
if err != nil {
return nil, err
}

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

@@ -8,6 +8,7 @@ import (
"time"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils"
)
@@ -17,7 +18,7 @@ type TestEnvironment struct {
Environments []TeamEnvironment
}
func CreateTestEnvironmentWithTeams(a *app.App, client *model.Client4, rangeTeams utils.Range, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TestEnvironment, error) {
func CreateTestEnvironmentWithTeams(a *app.App, c *request.Context, client *model.Client4, rangeTeams utils.Range, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TestEnvironment, error) {
rand.Seed(time.Now().UTC().UnixNano())
teamCreator := NewAutoTeamCreator(client)
@@ -32,12 +33,12 @@ func CreateTestEnvironmentWithTeams(a *app.App, client *model.Client4, rangeTeam
for i, team := range teams {
userCreator := NewAutoUserCreator(a, client, team)
userCreator.Fuzzy = fuzzy
randomUser, err := userCreator.createRandomUser()
randomUser, err := userCreator.createRandomUser(c)
if err != nil {
return TestEnvironment{}, err
}
client.LoginById(randomUser.Id, UserPassword)
teamEnvironment, err := CreateTestEnvironmentInTeam(a, client, team, rangeChannels, rangeUsers, rangePosts, fuzzy)
teamEnvironment, err := CreateTestEnvironmentInTeam(a, c, client, team, rangeChannels, rangeUsers, rangePosts, fuzzy)
if err != nil {
return TestEnvironment{}, err
}
@@ -47,7 +48,7 @@ func CreateTestEnvironmentWithTeams(a *app.App, client *model.Client4, rangeTeam
return environment, nil
}
func CreateTestEnvironmentInTeam(a *app.App, client *model.Client4, team *model.Team, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TeamEnvironment, error) {
func CreateTestEnvironmentInTeam(a *app.App, c *request.Context, client *model.Client4, team *model.Team, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TeamEnvironment, error) {
rand.Seed(time.Now().UTC().UnixNano())
// We need to create at least one user
@@ -57,7 +58,7 @@ func CreateTestEnvironmentInTeam(a *app.App, client *model.Client4, team *model.
userCreator := NewAutoUserCreator(a, client, team)
userCreator.Fuzzy = fuzzy
users, err := userCreator.CreateTestUsers(rangeUsers)
users, err := userCreator.CreateTestUsers(c, rangeUsers)
if err != nil {
return TeamEnvironment{}, nil
}
@@ -68,7 +69,7 @@ func CreateTestEnvironmentInTeam(a *app.App, client *model.Client4, team *model.
channelCreator := NewAutoChannelCreator(a, team, users[0].Id)
channelCreator.Fuzzy = fuzzy
channels, err := channelCreator.CreateTestChannels(rangeChannels)
channels, err := channelCreator.CreateTestChannels(c, rangeChannels)
if err != nil {
return TeamEnvironment{}, nil
}
@@ -102,7 +103,7 @@ func CreateTestEnvironmentInTeam(a *app.App, client *model.Client4, team *model.
postCreator.HasImage = i < numImages
postCreator.Users = usernames
postCreator.Fuzzy = fuzzy
_, err := postCreator.CreateRandomPost()
_, err := postCreator.CreateRandomPost(c)
if err != nil {
return TeamEnvironment{}, err
}

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

@@ -10,6 +10,7 @@ import (
"path/filepath"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils"
"github.com/mattermost/mattermost-server/v5/utils/fileutils"
@@ -44,7 +45,7 @@ func NewAutoPostCreator(a *app.App, channelid, userid string) *AutoPostCreator {
}
}
func (cfg *AutoPostCreator) UploadTestFile() ([]string, error) {
func (cfg *AutoPostCreator) UploadTestFile(c *request.Context) ([]string, error) {
filename := cfg.ImageFilenames[utils.RandIntFromRange(utils.Range{Begin: 0, End: len(cfg.ImageFilenames) - 1})]
path, _ := fileutils.FindDir("tests")
@@ -60,7 +61,7 @@ func (cfg *AutoPostCreator) UploadTestFile() ([]string, error) {
return nil, err
}
fileResp, err2 := cfg.a.UploadFile(data.Bytes(), cfg.channelid, filename)
fileResp, err2 := cfg.a.UploadFile(c, data.Bytes(), cfg.channelid, filename)
if err2 != nil {
return nil, err2
}
@@ -68,15 +69,15 @@ func (cfg *AutoPostCreator) UploadTestFile() ([]string, error) {
return []string{fileResp.Id}, nil
}
func (cfg *AutoPostCreator) CreateRandomPost() (*model.Post, error) {
return cfg.CreateRandomPostNested("", "")
func (cfg *AutoPostCreator) CreateRandomPost(c *request.Context) (*model.Post, error) {
return cfg.CreateRandomPostNested(c, "", "")
}
func (cfg *AutoPostCreator) CreateRandomPostNested(parentId, rootId string) (*model.Post, error) {
func (cfg *AutoPostCreator) CreateRandomPostNested(c *request.Context, parentId, rootId string) (*model.Post, error) {
var fileIDs []string
if cfg.HasImage {
var err error
fileIDs, err = cfg.UploadTestFile()
fileIDs, err = cfg.UploadTestFile(c)
if err != nil {
return nil, err
}
@@ -97,7 +98,7 @@ func (cfg *AutoPostCreator) CreateRandomPostNested(parentId, rootId string) (*mo
Message: postText,
FileIds: fileIDs,
}
rpost, err := cfg.a.CreatePostMissingChannel(post, true)
rpost, err := cfg.a.CreatePostMissingChannel(c, post, true)
if err != nil {
return nil, err
}

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

@@ -8,6 +8,7 @@ import (
"net/http"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils"
@@ -77,7 +78,7 @@ func CreateBasicUser(a *app.App, client *model.Client4) *model.AppError {
return nil
}
func (cfg *AutoUserCreator) createRandomUser() (*model.User, error) {
func (cfg *AutoUserCreator) createRandomUser(c *request.Context) (*model.User, error) {
var userEmail string
var userName string
if cfg.Fuzzy {
@@ -93,7 +94,7 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, error) {
Nickname: userName,
Password: UserPassword}
ruser, appErr := cfg.app.CreateUserWithInviteId(user, cfg.team.InviteId, "")
ruser, appErr := cfg.app.CreateUserWithInviteId(c, user, cfg.team.InviteId, "")
if appErr != nil {
return nil, appErr
}
@@ -112,13 +113,13 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, error) {
return ruser, nil
}
func (cfg *AutoUserCreator) CreateTestUsers(num utils.Range) ([]*model.User, error) {
func (cfg *AutoUserCreator) CreateTestUsers(c *request.Context, num utils.Range) ([]*model.User, error) {
numUsers := utils.RandIntFromRange(num)
users := make([]*model.User, numUsers)
for i := 0; i < numUsers; i++ {
var err error
users[i], err = cfg.createRandomUser()
users[i], err = cfg.createRandomUser(c)
if err != nil {
return nil, err
}

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -33,7 +34,7 @@ func (*AwayProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
}
}
func (*AwayProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*AwayProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
a.SetStatusAwayIfNeeded(args.UserId, true)
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_away.success")}

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

@@ -7,6 +7,7 @@ import (
"context"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -36,7 +37,7 @@ func (*HeaderProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
}
}
func (*HeaderProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*HeaderProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
channel, err := a.GetChannel(args.ChannelId)
if err != nil {
return &model.CommandResponse{
@@ -92,7 +93,7 @@ func (*HeaderProvider) DoCommand(a *app.App, args *model.CommandArgs, message st
}
*patch.Header = message
_, err = a.PatchChannel(channel, patch, args.UserId)
_, err = a.PatchChannel(c, channel, patch, args.UserId)
if err != nil {
text := args.T("api.command_channel_header.update_channel.app_error")
if err.Id == "model.channel.is_valid.header.app_error" {

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

@@ -30,7 +30,7 @@ func TestHeaderProviderDoCommand(t *testing.T) {
"": "api.command_channel_header.message.app_error",
"hello": "",
} {
actual := hp.DoCommand(th.App, args, msg).Text
actual := hp.DoCommand(th.App, th.Context, args, msg).Text
assert.Equal(t, expected, actual)
}
@@ -43,7 +43,7 @@ func TestHeaderProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual := hp.DoCommand(th.App, args, "hello").Text
actual := hp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "api.command_channel_header.permission.app_error", actual)
th.addPermissionToRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
@@ -57,7 +57,7 @@ func TestHeaderProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = hp.DoCommand(th.App, args, "hello").Text
actual = hp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "", actual)
th.removePermissionFromRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
@@ -69,7 +69,7 @@ func TestHeaderProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = hp.DoCommand(th.App, args, "hello").Text
actual = hp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "api.command_channel_header.permission.app_error", actual)
// Try a group channel *with* being a member.
@@ -85,7 +85,7 @@ func TestHeaderProviderDoCommand(t *testing.T) {
UserId: user1.Id,
}
actual = hp.DoCommand(th.App, args, "hello").Text
actual = hp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "", actual)
// Try a group channel *without* being a member.
@@ -95,7 +95,7 @@ func TestHeaderProviderDoCommand(t *testing.T) {
UserId: user3.Id,
}
actual = hp.DoCommand(th.App, args, "hello").Text
actual = hp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "api.command_channel_header.permission.app_error", actual)
// Try a direct channel *with* being a member.
@@ -107,7 +107,7 @@ func TestHeaderProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = hp.DoCommand(th.App, args, "hello").Text
actual = hp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "", actual)
// Try a direct channel *without* being a member.
@@ -117,6 +117,6 @@ func TestHeaderProviderDoCommand(t *testing.T) {
UserId: user2.Id,
}
actual = hp.DoCommand(th.App, args, "hello").Text
actual = hp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "api.command_channel_header.permission.app_error", actual)
}

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -34,7 +35,7 @@ func (*PurposeProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comm
}
}
func (*PurposeProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*PurposeProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
channel, err := a.GetChannel(args.ChannelId)
if err != nil {
return &model.CommandResponse{
@@ -77,7 +78,7 @@ func (*PurposeProvider) DoCommand(a *app.App, args *model.CommandArgs, message s
}
*patch.Purpose = message
_, err = a.PatchChannel(channel, patch, args.UserId)
_, err = a.PatchChannel(c, channel, patch, args.UserId)
if err != nil {
text := args.T("api.command_channel_purpose.update_channel.app_error")
if err.Id == "model.channel.is_valid.purpose.app_error" {

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

@@ -30,7 +30,7 @@ func TestPurposeProviderDoCommand(t *testing.T) {
"": "api.command_channel_purpose.message.app_error",
"hello": "",
} {
actual := pp.DoCommand(th.App, args, msg).Text
actual := pp.DoCommand(th.App, th.Context, args, msg).Text
assert.Equal(t, expected, actual)
}
@@ -42,7 +42,7 @@ func TestPurposeProviderDoCommand(t *testing.T) {
ChannelId: th.BasicChannel.Id,
}
actual := pp.DoCommand(th.App, args, "hello").Text
actual := pp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "api.command_channel_purpose.permission.app_error", actual)
// Try a private channel *with* permission.
@@ -56,7 +56,7 @@ func TestPurposeProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = pp.DoCommand(th.App, args, "hello").Text
actual = pp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "", actual)
// Try a private channel *without* permission.
@@ -67,7 +67,7 @@ func TestPurposeProviderDoCommand(t *testing.T) {
ChannelId: privateChannel.Id,
}
actual = pp.DoCommand(th.App, args, "hello").Text
actual = pp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "api.command_channel_purpose.permission.app_error", actual)
// Try a group channel *with* being a member.
@@ -81,7 +81,7 @@ func TestPurposeProviderDoCommand(t *testing.T) {
ChannelId: groupChannel.Id,
}
actual = pp.DoCommand(th.App, args, "hello").Text
actual = pp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "api.command_channel_purpose.direct_group.app_error", actual)
// Try a direct channel *with* being a member.
@@ -92,6 +92,6 @@ func TestPurposeProviderDoCommand(t *testing.T) {
ChannelId: directChannel.Id,
}
actual = pp.DoCommand(th.App, args, "hello").Text
actual = pp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "api.command_channel_purpose.direct_group.app_error", actual)
}

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -37,7 +38,7 @@ func (*RenameProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
}
}
func (*RenameProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*RenameProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
channel, err := a.GetChannel(args.ChannelId)
if err != nil {
return &model.CommandResponse{
@@ -91,7 +92,7 @@ func (*RenameProvider) DoCommand(a *app.App, args *model.CommandArgs, message st
}
*patch.DisplayName = message
_, err = a.PatchChannel(channel, patch, args.UserId)
_, err = a.PatchChannel(c, channel, patch, args.UserId)
if err != nil {
return &model.CommandResponse{
Text: args.T("api.command_channel_rename.update_channel.app_error"),

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

@@ -33,7 +33,7 @@ func TestRenameProviderDoCommand(t *testing.T) {
"More than 22 chars but less than 64": "",
strings.Repeat("12345", 13): "api.command_channel_rename.too_long.app_error",
} {
actual := rp.DoCommand(th.App, args, msg).Text
actual := rp.DoCommand(th.App, th.Context, args, msg).Text
assert.Equal(t, expected, actual)
}
@@ -46,7 +46,7 @@ func TestRenameProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual := rp.DoCommand(th.App, args, "hello").Text
actual := rp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "api.command_channel_rename.permission.app_error", actual)
// Try a private channel *with* permission.
@@ -60,7 +60,7 @@ func TestRenameProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = rp.DoCommand(th.App, args, "hello").Text
actual = rp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "", actual)
// Try a private channel *without* permission.
@@ -72,7 +72,7 @@ func TestRenameProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = rp.DoCommand(th.App, args, "hello").Text
actual = rp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "api.command_channel_rename.permission.app_error", actual)
// Try a group channel *with* being a member.
@@ -87,7 +87,7 @@ func TestRenameProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = rp.DoCommand(th.App, args, "hello").Text
actual = rp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "api.command_channel_rename.direct_group.app_error", actual)
// Try a direct channel *with* being a member.
@@ -99,6 +99,6 @@ func TestRenameProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = rp.DoCommand(th.App, args, "hello").Text
actual = rp.DoCommand(th.App, th.Context, args, "hello").Text
assert.Equal(t, "api.command_channel_rename.direct_group.app_error", actual)
}

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

@@ -7,6 +7,7 @@ import (
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -36,7 +37,7 @@ func (*CodeProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
}
}
func (*CodeProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*CodeProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
if message == "" {
return &model.CommandResponse{Text: args.T("api.command_code.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}

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

@@ -21,7 +21,7 @@ func TestCodeProviderDoCommand(t *testing.T) {
"foo\nbar": " foo\n bar",
"foo\nbar\n": " foo\n bar\n ",
} {
actual := cp.DoCommand(nil, args, msg).Text
actual := cp.DoCommand(nil, nil, args, msg).Text
if actual != expected {
t.Errorf("expected `%v`, got `%v`", expected, actual)
}

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

@@ -7,6 +7,7 @@ import (
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/shared/mlog"
@@ -40,7 +41,7 @@ func (*CustomStatusProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model
}
}
func (*CustomStatusProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*CustomStatusProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
if !*a.Config().TeamSettings.EnableCustomUserStatuses {
return nil
}

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -33,7 +34,7 @@ func (*DndProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
}
}
func (*DndProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*DndProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
a.SetStatusDoNotDisturb(args.UserId)
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_dnd.success")}

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

@@ -9,6 +9,7 @@ import (
"time"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/shared/mlog"
@@ -41,7 +42,7 @@ func (*EchoProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
}
}
func (*EchoProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*EchoProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
if message == "" {
return &model.CommandResponse{Text: args.T("api.command_echo.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
@@ -89,7 +90,7 @@ func (*EchoProvider) DoCommand(a *app.App, args *model.CommandArgs, message stri
time.Sleep(time.Duration(delay) * time.Second)
if _, err := a.CreatePostMissingChannel(post, true); err != nil {
if _, err := a.CreatePostMissingChannel(c, post, true); err != nil {
mlog.Error("Unable to create /echo post.", mlog.Err(err))
}
})

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

@@ -7,6 +7,7 @@ import (
"strconv"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -53,11 +54,11 @@ func (*CollapseProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Com
}
}
func (*ExpandProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*ExpandProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
return setCollapsePreference(a, args, false)
}
func (*CollapseProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*CollapseProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
return setCollapsePreference(a, args, true)
}

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

@@ -8,6 +8,7 @@ import (
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/shared/mlog"
@@ -38,7 +39,7 @@ func (*groupmsgProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Com
}
}
func (*groupmsgProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*groupmsgProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
targetUsers := map[string]*model.User{}
targetUsersSlice := []string{args.UserId}
invalidUsernames := []string{}
@@ -82,7 +83,7 @@ func (*groupmsgProvider) DoCommand(a *app.App, args *model.CommandArgs, message
}
if len(targetUsersSlice) == 2 {
return app.GetCommandProvider("msg").DoCommand(a, args, fmt.Sprintf("%s %s", targetUsers[targetUsersSlice[1]].Username, parsedMessage))
return app.GetCommandProvider("msg").DoCommand(a, c, args, fmt.Sprintf("%s %s", targetUsers[targetUsersSlice[1]].Username, parsedMessage))
}
if len(targetUsersSlice) < model.CHANNEL_GROUP_MIN_USERS {
@@ -126,7 +127,7 @@ func (*groupmsgProvider) DoCommand(a *app.App, args *model.CommandArgs, message
post.Message = parsedMessage
post.ChannelId = groupChannel.Id
post.UserId = args.UserId
if _, err := a.CreatePostMissingChannel(post, true); err != nil {
if _, err := a.CreatePostMissingChannel(c, post, true); err != nil {
return &model.CommandResponse{Text: args.T("api.command_groupmsg.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
}

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

@@ -67,7 +67,7 @@ func TestGroupMsgProvider(t *testing.T) {
th.removePermissionFromRole(model.PERMISSION_CREATE_GROUP_CHANNEL.Id, model.SYSTEM_USER_ROLE_ID)
t.Run("Check without permission to create a GM channel.", func(t *testing.T) {
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
SiteURL: "http://test.url",
TeamId: team.Id,
@@ -83,7 +83,7 @@ func TestGroupMsgProvider(t *testing.T) {
t.Run("Check without permissions to view a user in the list.", func(t *testing.T) {
th.removePermissionFromRole(model.PERMISSION_VIEW_MEMBERS.Id, model.SYSTEM_USER_ROLE_ID)
defer th.addPermissionToRole(model.PERMISSION_VIEW_MEMBERS.Id, model.SYSTEM_USER_ROLE_ID)
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
SiteURL: "http://test.url",
TeamId: team.Id,
@@ -95,7 +95,7 @@ func TestGroupMsgProvider(t *testing.T) {
})
t.Run("Check with permission to create a GM channel.", func(t *testing.T) {
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
SiteURL: "http://test.url",
TeamId: team.Id,
@@ -108,7 +108,7 @@ func TestGroupMsgProvider(t *testing.T) {
})
t.Run("Check without permission to post to an existing GM channel.", func(t *testing.T) {
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
SiteURL: "http://test.url",
TeamId: team.Id,

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -33,7 +34,7 @@ func (h *HelpProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
}
}
func (h *HelpProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (h *HelpProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
helpLink := *a.Config().SupportSettings.HelpLink
if helpLink == "" {

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

@@ -8,6 +8,7 @@ import (
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/shared/mlog"
@@ -38,7 +39,7 @@ func (*InviteProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
}
}
func (*InviteProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*InviteProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
if message == "" {
return &model.CommandResponse{
Text: args.T("api.command_invite.missing_message.app_error"),
@@ -140,7 +141,7 @@ func (*InviteProvider) DoCommand(a *app.App, args *model.CommandArgs, message st
}
}
if _, err := a.AddChannelMember(userProfile.Id, channelToJoin, app.ChannelMemberOpts{
if _, err := a.AddChannelMember(c, userProfile.Id, channelToJoin, app.ChannelMemberOpts{
UserRequestorID: args.UserId,
}); err != nil {
var text string

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

@@ -7,6 +7,7 @@ import (
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/shared/mlog"
@@ -41,7 +42,7 @@ func (*InvitePeopleProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model
}
}
func (*InvitePeopleProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*InvitePeopleProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
if !a.HasPermissionToTeam(args.UserId, args.TeamId, model.PERMISSION_INVITE_USER) {
return &model.CommandResponse{Text: args.T("api.command_invite_people.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}

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

@@ -32,11 +32,11 @@ func TestInvitePeopleProvider(t *testing.T) {
UserId: notTeamUser.Id,
}
actual := cmd.DoCommand(th.App, args, model.NewId()+"@simulator.amazonses.com")
actual := cmd.DoCommand(th.App, th.Context, args, model.NewId()+"@simulator.amazonses.com")
assert.Equal(t, "api.command_invite_people.permission.app_error", actual.Text)
// Test with required permissions.
args.UserId = th.BasicUser.Id
actual = cmd.DoCommand(th.App, args, model.NewId()+"@simulator.amazonses.com")
actual = cmd.DoCommand(th.App, th.Context, args, model.NewId()+"@simulator.amazonses.com")
assert.Equal(t, "api.command.invite_people.sent", actual.Text)
}

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

@@ -26,34 +26,34 @@ func TestInviteProvider(t *testing.T) {
th.linkUserToTeam(basicUser3, th.BasicTeam)
basicUser4 := th.createUser()
deactivatedUser := th.createUser()
th.App.UpdateActive(deactivatedUser, false)
th.App.UpdateActive(th.Context, deactivatedUser, false)
var err *model.AppError
_, err = th.App.CreateBot(&model.Bot{
_, err = th.App.CreateBot(th.Context, &model.Bot{
Username: "bot1",
OwnerId: basicUser3.Id,
Description: "a test bot",
})
require.Nil(t, err)
bot2, err := th.App.CreateBot(&model.Bot{
bot2, err := th.App.CreateBot(th.Context, &model.Bot{
Username: "bot2",
OwnerId: basicUser3.Id,
Description: "a test bot",
})
require.Nil(t, err)
_, _, err = th.App.AddUserToTeam(th.BasicTeam.Id, bot2.UserId, basicUser3.Id)
_, _, err = th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, bot2.UserId, basicUser3.Id)
require.Nil(t, err)
bot3, err := th.App.CreateBot(&model.Bot{
bot3, err := th.App.CreateBot(th.Context, &model.Bot{
Username: "bot3",
OwnerId: basicUser3.Id,
Description: "a test bot",
})
require.Nil(t, err)
_, _, err = th.App.AddUserToTeam(th.BasicTeam.Id, bot3.UserId, basicUser3.Id)
_, _, err = th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, bot3.UserId, basicUser3.Id)
require.Nil(t, err)
err = th.App.RemoveUserFromTeam(th.BasicTeam.Id, bot3.UserId, basicUser3.Id)
err = th.App.RemoveUserFromTeam(th.Context, th.BasicTeam.Id, bot3.UserId, basicUser3.Id)
require.Nil(t, err)
InviteP := InviteProvider{}
@@ -73,7 +73,7 @@ func TestInviteProvider(t *testing.T) {
deactivatedUserPublicChannel := "@" + deactivatedUser.Username + " ~" + channel.Name
groupChannel := th.createChannel(th.BasicTeam, model.CHANNEL_PRIVATE)
_, err = th.App.AddChannelMember(th.BasicUser.Id, groupChannel, app.ChannelMemberOpts{})
_, err = th.App.AddChannelMember(th.Context, th.BasicUser.Id, groupChannel, app.ChannelMemberOpts{})
require.Nil(t, err)
groupChannel.GroupConstrained = model.NewBool(true)
groupChannel, _ = th.App.UpdateChannel(groupChannel)
@@ -169,7 +169,7 @@ func TestInviteProvider(t *testing.T) {
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
actual := InviteP.DoCommand(th.App, args, test.msg).Text
actual := InviteP.DoCommand(th.App, th.Context, args, test.msg).Text
assert.Equal(t, test.expected, actual)
})
}
@@ -181,8 +181,8 @@ func TestInviteGroup(t *testing.T) {
th.BasicTeam.GroupConstrained = model.NewBool(true)
var err *model.AppError
_, _ = th.App.AddTeamMember(th.BasicTeam.Id, th.BasicUser.Id)
_, err = th.App.AddTeamMember(th.BasicTeam.Id, th.BasicUser2.Id)
_, _ = th.App.AddTeamMember(th.Context, th.BasicTeam.Id, th.BasicUser.Id)
_, err = th.App.AddTeamMember(th.Context, th.BasicTeam.Id, th.BasicUser2.Id)
require.Nil(t, err)
th.BasicTeam, _ = th.App.UpdateTeam(th.BasicTeam)
@@ -225,7 +225,7 @@ func TestInviteGroup(t *testing.T) {
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
actual := InviteP.DoCommand(th.App, args, test.msg).Text
actual := InviteP.DoCommand(th.App, th.Context, args, test.msg).Text
assert.Equal(t, test.expected, actual)
})
}

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

@@ -7,6 +7,7 @@ import (
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -36,7 +37,7 @@ func (*JoinProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
}
}
func (*JoinProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*JoinProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
channelName := strings.ToLower(message)
if strings.HasPrefix(message, "~") {
@@ -65,7 +66,7 @@ func (*JoinProvider) DoCommand(a *app.App, args *model.CommandArgs, message stri
return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
if appErr := a.JoinChannel(channel, args.UserId); appErr != nil {
if appErr := a.JoinChannel(c, channel, args.UserId); appErr != nil {
return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}

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

@@ -21,7 +21,7 @@ func TestJoinCommandNoChannel(t *testing.T) {
}
cmd := &JoinProvider{}
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
UserId: th.BasicUser2.Id,
SiteURL: "http://test.url",
@@ -39,7 +39,7 @@ func TestJoinCommandForExistingChannel(t *testing.T) {
t.SkipNow()
}
channel2, _ := th.App.CreateChannel(&model.Channel{
channel2, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.CHANNEL_OPEN,
@@ -48,7 +48,7 @@ func TestJoinCommandForExistingChannel(t *testing.T) {
}, false)
cmd := &JoinProvider{}
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
UserId: th.BasicUser2.Id,
SiteURL: "http://test.url",
@@ -67,7 +67,7 @@ func TestJoinCommandWithTilde(t *testing.T) {
t.SkipNow()
}
channel2, _ := th.App.CreateChannel(&model.Channel{
channel2, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.CHANNEL_OPEN,
@@ -76,7 +76,7 @@ func TestJoinCommandWithTilde(t *testing.T) {
}, false)
cmd := &JoinProvider{}
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
UserId: th.BasicUser2.Id,
SiteURL: "http://test.url",
@@ -91,7 +91,7 @@ func TestJoinCommandPermissions(t *testing.T) {
th := setup(t).initBasic()
defer th.tearDown()
channel2, _ := th.App.CreateChannel(&model.Channel{
channel2, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.CHANNEL_OPEN,
@@ -111,7 +111,7 @@ func TestJoinCommandPermissions(t *testing.T) {
TeamId: th.BasicTeam.Id,
}
actual := cmd.DoCommand(th.App, args, "~"+channel2.Name).Text
actual := cmd.DoCommand(th.App, th.Context, args, "~"+channel2.Name).Text
assert.Equal(t, "api.command_join.fail.app_error", actual)
// Try a public channel with permission.
@@ -122,11 +122,11 @@ func TestJoinCommandPermissions(t *testing.T) {
TeamId: th.BasicTeam.Id,
}
actual = cmd.DoCommand(th.App, args, "~"+channel2.Name).Text
actual = cmd.DoCommand(th.App, th.Context, args, "~"+channel2.Name).Text
assert.Equal(t, "", actual)
// Try a private channel *without* permission.
channel3, _ := th.App.CreateChannel(&model.Channel{
channel3, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "BB",
Name: "aa" + model.NewId() + "a",
Type: model.CHANNEL_PRIVATE,
@@ -141,6 +141,6 @@ func TestJoinCommandPermissions(t *testing.T) {
TeamId: th.BasicTeam.Id,
}
actual = cmd.DoCommand(th.App, args, "~"+channel3.Name).Text
actual = cmd.DoCommand(th.App, th.Context, args, "~"+channel3.Name).Text
assert.Equal(t, "api.command_join.fail.app_error", actual)
}

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -33,7 +34,7 @@ func (*LeaveProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comman
}
}
func (*LeaveProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*LeaveProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
var channel *model.Channel
var noChannelErr *model.AppError
if channel, noChannelErr = a.GetChannel(args.ChannelId); noChannelErr != nil {
@@ -45,7 +46,7 @@ func (*LeaveProvider) DoCommand(a *app.App, args *model.CommandArgs, message str
return &model.CommandResponse{Text: args.T("api.command_leave.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
err = a.LeaveChannel(args.ChannelId, args.UserId)
err = a.LeaveChannel(c, args.ChannelId, args.UserId)
if err != nil {
if channel.Name == model.DEFAULT_CHANNEL {
return &model.CommandResponse{Text: args.T("api.channel.leave.default.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}

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

@@ -19,7 +19,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
lp := LeaveProvider{}
publicChannel, _ := th.App.CreateChannel(&model.Channel{
publicChannel, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.CHANNEL_OPEN,
@@ -27,7 +27,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
CreatorId: th.BasicUser.Id,
}, false)
privateChannel, _ := th.App.CreateChannel(&model.Channel{
privateChannel, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "BB",
Name: "aa" + model.NewId() + "a",
Type: model.CHANNEL_OPEN,
@@ -40,10 +40,10 @@ func TestLeaveProviderDoCommand(t *testing.T) {
guest := th.createGuest()
th.App.AddUserToTeam(th.BasicTeam.Id, th.BasicUser.Id, th.BasicUser.Id)
th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, th.BasicUser.Id, th.BasicUser.Id)
th.App.AddUserToChannel(th.BasicUser, publicChannel, false)
th.App.AddUserToChannel(th.BasicUser, privateChannel, false)
th.App.AddUserToTeam(th.BasicTeam.Id, guest.Id, guest.Id)
th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, guest.Id, guest.Id)
th.App.AddUserToChannel(guest, publicChannel, false)
th.App.AddUserToChannel(guest, defaultChannel, false)
@@ -52,7 +52,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
T: func(s string, args ...interface{}) string { return s },
}
actual := lp.DoCommand(th.App, args, "")
actual := lp.DoCommand(th.App, th.Context, args, "")
assert.Equal(t, "api.command_leave.fail.app_error", actual.Text)
assert.Equal(t, model.COMMAND_RESPONSE_TYPE_EPHEMERAL, actual.ResponseType)
})
@@ -63,7 +63,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
ChannelId: publicChannel.Id,
T: func(s string, args ...interface{}) string { return s },
}
actual := lp.DoCommand(th.App, args, "")
actual := lp.DoCommand(th.App, th.Context, args, "")
assert.Equal(t, "api.command_leave.fail.app_error", actual.Text)
assert.Equal(t, model.COMMAND_RESPONSE_TYPE_EPHEMERAL, actual.ResponseType)
})
@@ -76,7 +76,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
TeamId: th.BasicTeam.Id,
SiteURL: "http://localhost:8065",
}
actual := lp.DoCommand(th.App, args, "")
actual := lp.DoCommand(th.App, th.Context, args, "")
assert.Equal(t, "", actual.Text)
assert.Equal(t, args.SiteURL+"/"+th.BasicTeam.Name+"/channels/"+model.DEFAULT_CHANNEL, actual.GotoLocation)
assert.Equal(t, "", actual.ResponseType)
@@ -94,7 +94,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
TeamId: th.BasicTeam.Id,
SiteURL: "http://localhost:8065",
}
actual := lp.DoCommand(th.App, args, "")
actual := lp.DoCommand(th.App, th.Context, args, "")
assert.Equal(t, "", actual.Text)
})
@@ -106,7 +106,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
TeamId: th.BasicTeam.Id,
SiteURL: "http://localhost:8065",
}
actual := lp.DoCommand(th.App, args, "")
actual := lp.DoCommand(th.App, th.Context, args, "")
assert.Equal(t, "api.channel.leave.default.app_error", actual.Text)
})
@@ -118,7 +118,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
TeamId: th.BasicTeam.Id,
SiteURL: "http://localhost:8065",
}
actual := lp.DoCommand(th.App, args, "")
actual := lp.DoCommand(th.App, th.Context, args, "")
assert.Equal(t, "", actual.Text)
assert.Equal(t, args.SiteURL+"/"+th.BasicTeam.Name+"/channels/"+publicChannel.Name, actual.GotoLocation)
assert.Equal(t, "", actual.ResponseType)
@@ -136,7 +136,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
TeamId: th.BasicTeam.Id,
SiteURL: "http://localhost:8065",
}
actual := lp.DoCommand(th.App, args, "")
actual := lp.DoCommand(th.App, th.Context, args, "")
assert.Equal(t, "", actual.Text)
assert.Equal(t, args.SiteURL+"/", actual.GotoLocation)
assert.Equal(t, "", actual.ResponseType)

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

@@ -15,6 +15,7 @@ import (
"github.com/pkg/errors"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/shared/mlog"
@@ -108,8 +109,8 @@ func (*LoadTestProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Com
}
}
func (lt *LoadTestProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
commandResponse, err := lt.doCommand(a, args, message)
func (lt *LoadTestProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
commandResponse, err := lt.doCommand(a, c, args, message)
if err != nil {
mlog.Error("failed command /"+CmdTest, mlog.Err(err))
}
@@ -117,34 +118,34 @@ func (lt *LoadTestProvider) DoCommand(a *app.App, args *model.CommandArgs, messa
return commandResponse
}
func (lt *LoadTestProvider) doCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (lt *LoadTestProvider) doCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
//This command is only available when EnableTesting is true
if !*a.Config().ServiceSettings.EnableTesting {
return &model.CommandResponse{}, nil
}
if strings.HasPrefix(message, "setup") {
return lt.SetupCommand(a, args, message)
return lt.SetupCommand(a, c, args, message)
}
if strings.HasPrefix(message, "users") {
return lt.UsersCommand(a, args, message)
return lt.UsersCommand(a, c, args, message)
}
if strings.HasPrefix(message, "activate_user") {
return lt.ActivateUserCommand(a, args, message)
return lt.ActivateUserCommand(a, c, args, message)
}
if strings.HasPrefix(message, "deactivate_user") {
return lt.DeActivateUserCommand(a, args, message)
return lt.DeActivateUserCommand(a, c, args, message)
}
if strings.HasPrefix(message, "channels") {
return lt.ChannelsCommand(a, args, message)
return lt.ChannelsCommand(a, c, args, message)
}
if strings.HasPrefix(message, "posts") {
return lt.PostsCommand(a, args, message)
return lt.PostsCommand(a, c, args, message)
}
if strings.HasPrefix(message, "post") {
@@ -152,15 +153,15 @@ func (lt *LoadTestProvider) doCommand(a *app.App, args *model.CommandArgs, messa
}
if strings.HasPrefix(message, "threaded_post") {
return lt.ThreadedPostCommand(a, args, message)
return lt.ThreadedPostCommand(a, c, args, message)
}
if strings.HasPrefix(message, "url") {
return lt.UrlCommand(a, args, message)
return lt.UrlCommand(a, c, args, message)
}
if strings.HasPrefix(message, "json") {
return lt.JsonCommand(a, args, message)
return lt.JsonCommand(a, c, args, message)
}
return lt.HelpCommand(args, message), nil
@@ -170,7 +171,7 @@ func (*LoadTestProvider) HelpCommand(args *model.CommandArgs, message string) *m
return &model.CommandResponse{Text: usage, ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
func (*LoadTestProvider) SetupCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (*LoadTestProvider) SetupCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
tokens := strings.Fields(strings.TrimPrefix(message, "setup"))
doTeams := contains(tokens, "teams")
doFuzz := contains(tokens, "fuzz")
@@ -220,6 +221,7 @@ func (*LoadTestProvider) SetupCommand(a *app.App, args *model.CommandArgs, messa
}
environment, err := CreateTestEnvironmentWithTeams(
a,
c,
client,
utils.Range{Begin: numTeams, End: numTeams},
utils.Range{Begin: numChannels, End: numChannels},
@@ -243,6 +245,7 @@ func (*LoadTestProvider) SetupCommand(a *app.App, args *model.CommandArgs, messa
CreateTestEnvironmentInTeam(
a,
c,
client,
team,
utils.Range{Begin: numChannels, End: numChannels},
@@ -254,25 +257,25 @@ func (*LoadTestProvider) SetupCommand(a *app.App, args *model.CommandArgs, messa
return &model.CommandResponse{Text: "Created environment", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (*LoadTestProvider) ActivateUserCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (*LoadTestProvider) ActivateUserCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
user_id := strings.TrimSpace(strings.TrimPrefix(message, "activate_user"))
if err := a.UpdateUserActive(user_id, true); err != nil {
if err := a.UpdateUserActive(c, user_id, true); err != nil {
return &model.CommandResponse{Text: "Failed to activate user", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
}
return &model.CommandResponse{Text: "Activated user", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (*LoadTestProvider) DeActivateUserCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (*LoadTestProvider) DeActivateUserCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
user_id := strings.TrimSpace(strings.TrimPrefix(message, "deactivate_user"))
if err := a.UpdateUserActive(user_id, false); err != nil {
if err := a.UpdateUserActive(c, user_id, false); err != nil {
return &model.CommandResponse{Text: "Failed to deactivate user", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
}
return &model.CommandResponse{Text: "DeActivated user", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (*LoadTestProvider) UsersCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (*LoadTestProvider) UsersCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
cmd := strings.TrimSpace(strings.TrimPrefix(message, "users"))
doFuzz := false
@@ -294,14 +297,14 @@ func (*LoadTestProvider) UsersCommand(a *app.App, args *model.CommandArgs, messa
client := model.NewAPIv4Client(args.SiteURL)
userCreator := NewAutoUserCreator(a, client, team)
userCreator.Fuzzy = doFuzz
if _, err := userCreator.CreateTestUsers(usersr); err != nil {
if _, err := userCreator.CreateTestUsers(c, usersr); err != nil {
return &model.CommandResponse{Text: "Failed to add users: " + err.Error(), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
}
return &model.CommandResponse{Text: "Added users", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (*LoadTestProvider) ChannelsCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (*LoadTestProvider) ChannelsCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
cmd := strings.TrimSpace(strings.TrimPrefix(message, "channels"))
doFuzz := false
@@ -322,14 +325,14 @@ func (*LoadTestProvider) ChannelsCommand(a *app.App, args *model.CommandArgs, me
channelCreator := NewAutoChannelCreator(a, team, args.UserId)
channelCreator.Fuzzy = doFuzz
if _, err := channelCreator.CreateTestChannels(channelsr); err != nil {
if _, err := channelCreator.CreateTestChannels(c, channelsr); err != nil {
return &model.CommandResponse{Text: "Failed to create test channels: " + err.Error(), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
}
return &model.CommandResponse{Text: "Added channels", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (*LoadTestProvider) ThreadedPostCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (*LoadTestProvider) ThreadedPostCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
var usernames []string
options := &model.UserGetOptions{InTeamId: args.TeamId, Page: 0, PerPage: 1000}
if profileUsers, err := a.Srv().Store.User().GetProfiles(options); err == nil {
@@ -344,18 +347,18 @@ func (*LoadTestProvider) ThreadedPostCommand(a *app.App, args *model.CommandArgs
testPoster := NewAutoPostCreator(a, args.ChannelId, args.UserId)
testPoster.Fuzzy = true
testPoster.Users = usernames
rpost, err2 := testPoster.CreateRandomPost()
rpost, err2 := testPoster.CreateRandomPost(c)
if err2 != nil {
return &model.CommandResponse{Text: "Failed to create a post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err2
}
for i := 0; i < 1000; i++ {
testPoster.CreateRandomPostNested(rpost.Id, rpost.Id)
testPoster.CreateRandomPostNested(c, rpost.Id, rpost.Id)
}
return &model.CommandResponse{Text: "Added threaded post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (*LoadTestProvider) PostsCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (*LoadTestProvider) PostsCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
cmd := strings.TrimSpace(strings.TrimPrefix(message, "posts"))
doFuzz := false
@@ -396,7 +399,7 @@ func (*LoadTestProvider) PostsCommand(a *app.App, args *model.CommandArgs, messa
numPosts := utils.RandIntFromRange(postsr)
for i := 0; i < numPosts; i++ {
testPoster.HasImage = (i < numImages)
_, err := testPoster.CreateRandomPost()
_, err := testPoster.CreateRandomPost(c)
if err != nil {
return &model.CommandResponse{Text: "Failed to add posts", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
}
@@ -457,7 +460,7 @@ func (*LoadTestProvider) PostCommand(a *app.App, args *model.CommandArgs, messag
return &model.CommandResponse{Text: "Added a post to " + channel.DisplayName, ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (*LoadTestProvider) UrlCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (*LoadTestProvider) UrlCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
url := strings.TrimSpace(strings.TrimPrefix(message, "url"))
if url == "" {
return &model.CommandResponse{Text: "Command must contain a url", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
@@ -503,7 +506,7 @@ func (*LoadTestProvider) UrlCommand(a *app.App, args *model.CommandArgs, message
post.ChannelId = args.ChannelId
post.UserId = args.UserId
if _, err := a.CreatePostMissingChannel(post, false); err != nil {
if _, err := a.CreatePostMissingChannel(c, post, false); err != nil {
return &model.CommandResponse{Text: "Unable to create post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
}
}
@@ -511,7 +514,7 @@ func (*LoadTestProvider) UrlCommand(a *app.App, args *model.CommandArgs, message
return &model.CommandResponse{Text: "Loaded data", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (*LoadTestProvider) JsonCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (*LoadTestProvider) JsonCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
url := strings.TrimSpace(strings.TrimPrefix(message, "json"))
if url == "" {
return &model.CommandResponse{Text: "Command must contain a url", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
@@ -549,7 +552,7 @@ func (*LoadTestProvider) JsonCommand(a *app.App, args *model.CommandArgs, messag
post.Message = message
}
if _, err := a.CreatePostMissingChannel(post, false); err != nil {
if _, err := a.CreatePostMissingChannel(c, post, false); err != nil {
return &model.CommandResponse{Text: "Unable to create post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
}

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -34,7 +35,7 @@ func (*LogoutProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
}
}
func (*LogoutProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*LogoutProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
// Actual logout is handled client side.
return &model.CommandResponse{GotoLocation: "/login"}
}

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -34,7 +35,7 @@ func (*MeProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command {
}
}
func (*MeProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*MeProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL,
Type: model.POST_ME,

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

@@ -19,7 +19,7 @@ func TestMeProviderDoCommand(t *testing.T) {
msg := "hello"
resp := mp.DoCommand(th.App, &model.CommandArgs{}, msg)
resp := mp.DoCommand(th.App, th.Context, &model.CommandArgs{}, msg)
assert.Equal(t, model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, resp.ResponseType)
assert.Equal(t, model.POST_ME, resp.Type)

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

@@ -8,6 +8,7 @@ import (
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/shared/mlog"
@@ -39,7 +40,7 @@ func (*msgProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
}
}
func (*msgProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*msgProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
splitMessage := strings.SplitN(message, " ", 2)
parsedMessage := ""
@@ -82,7 +83,7 @@ func (*msgProvider) DoCommand(a *app.App, args *model.CommandArgs, message strin
}
var directChannel *model.Channel
if directChannel, err = a.GetOrCreateDirectChannel(args.UserId, userProfile.Id); err != nil {
if directChannel, err = a.GetOrCreateDirectChannel(c, args.UserId, userProfile.Id); err != nil {
mlog.Error(err.Error())
return &model.CommandResponse{Text: args.T("api.command_msg.dm_fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
@@ -100,7 +101,7 @@ func (*msgProvider) DoCommand(a *app.App, args *model.CommandArgs, message strin
post.Message = parsedMessage
post.ChannelId = targetChannelId
post.UserId = args.UserId
if _, err = a.CreatePostMissingChannel(post, true); err != nil {
if _, err = a.CreatePostMissingChannel(c, post, true); err != nil {
return &model.CommandResponse{Text: args.T("api.command_msg.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
}

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

@@ -23,7 +23,7 @@ func TestMsgProvider(t *testing.T) {
th.removePermissionFromRole(model.PERMISSION_CREATE_DIRECT_CHANNEL.Id, model.SYSTEM_USER_ROLE_ID)
// Check without permission to create a DM channel.
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
SiteURL: "http://test.url",
TeamId: team.Id,
@@ -37,7 +37,7 @@ func TestMsgProvider(t *testing.T) {
th.addPermissionToRole(model.PERMISSION_CREATE_DIRECT_CHANNEL.Id, model.SYSTEM_USER_ROLE_ID)
// Check with permission to create a DM channel.
resp = cmd.DoCommand(th.App, &model.CommandArgs{
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
SiteURL: "http://test.url",
TeamId: team.Id,
@@ -48,7 +48,7 @@ func TestMsgProvider(t *testing.T) {
assert.Equal(t, "http://test.url/"+team.Name+"/channels/"+channelName, resp.GotoLocation)
// Check without permission to post to an existing DM channel.
resp = cmd.DoCommand(th.App, &model.CommandArgs{
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
SiteURL: "http://test.url",
TeamId: team.Id,
@@ -66,7 +66,7 @@ func TestMsgProvider(t *testing.T) {
th.linkUserToTeam(guest, th.BasicTeam)
th.addUserToChannel(guest, th.BasicChannel)
resp = cmd.DoCommand(th.App, &model.CommandArgs{
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
SiteURL: "http://test.url",
TeamId: th.BasicTeam.Id,
@@ -80,7 +80,7 @@ func TestMsgProvider(t *testing.T) {
th.linkUserToTeam(user, th.BasicTeam)
th.addUserToChannel(user, th.BasicChannel)
resp = cmd.DoCommand(th.App, &model.CommandArgs{
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
SiteURL: "http://test.url",
TeamId: th.BasicTeam.Id,

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

@@ -7,6 +7,7 @@ import (
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -36,7 +37,7 @@ func (*MuteProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
}
}
func (*MuteProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*MuteProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
var channel *model.Channel
var noChannelErr *model.AppError

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

@@ -34,7 +34,7 @@ func TestMuteCommandNoChannel(t *testing.T) {
)
cmd := &MuteProvider{}
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
UserId: th.BasicUser.Id,
}, "")
@@ -53,7 +53,7 @@ func TestMuteCommandNoArgs(t *testing.T) {
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
@@ -62,7 +62,7 @@ func TestMuteCommandNoArgs(t *testing.T) {
// Now unmute the channel
time.Sleep(time.Millisecond)
resp = cmd.DoCommand(th.App, &model.CommandArgs{
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
@@ -80,7 +80,7 @@ func TestMuteCommandSpecificChannel(t *testing.T) {
}
channel1 := th.BasicChannel
channel2, _ := th.App.CreateChannel(&model.Channel{
channel2, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.CHANNEL_OPEN,
@@ -95,7 +95,7 @@ func TestMuteCommandSpecificChannel(t *testing.T) {
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
@@ -105,7 +105,7 @@ func TestMuteCommandSpecificChannel(t *testing.T) {
assert.Equal(t, model.CHANNEL_NOTIFY_MENTION, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
// Now unmute the channel
resp = cmd.DoCommand(th.App, &model.CommandArgs{
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
@@ -125,7 +125,7 @@ func TestMuteCommandNotMember(t *testing.T) {
}
channel1 := th.BasicChannel
channel2, _ := th.App.CreateChannel(&model.Channel{
channel2, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.CHANNEL_OPEN,
@@ -136,7 +136,7 @@ func TestMuteCommandNotMember(t *testing.T) {
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
@@ -157,7 +157,7 @@ func TestMuteCommandNotChannel(t *testing.T) {
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel1.Id,
UserId: th.BasicUser.Id,
@@ -173,7 +173,7 @@ func TestMuteCommandDMChannel(t *testing.T) {
t.SkipNow()
}
channel2, _ := th.App.GetOrCreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
channel2, _ := th.App.GetOrCreateDirectChannel(th.Context, th.BasicUser.Id, th.BasicUser2.Id)
channel2M, _ := th.App.GetChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
assert.Equal(t, model.CHANNEL_NOTIFY_ALL, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
@@ -181,7 +181,7 @@ func TestMuteCommandDMChannel(t *testing.T) {
cmd := &MuteProvider{}
// First mute the channel
resp := cmd.DoCommand(th.App, &model.CommandArgs{
resp := cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel2.Id,
UserId: th.BasicUser.Id,
@@ -192,7 +192,7 @@ func TestMuteCommandDMChannel(t *testing.T) {
assert.Equal(t, model.CHANNEL_NOTIFY_MENTION, channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
// Now unmute the channel
resp = cmd.DoCommand(th.App, &model.CommandArgs{
resp = cmd.DoCommand(th.App, th.Context, &model.CommandArgs{
T: i18n.IdentityTfunc(),
ChannelId: channel2.Id,
UserId: th.BasicUser.Id,

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -33,7 +34,7 @@ func (*OfflineProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comm
}
}
func (*OfflineProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*OfflineProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
a.SetStatusOffline(args.UserId, true)
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_offline.success")}

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -33,7 +34,7 @@ func (*OnlineProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comma
}
}
func (*OnlineProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*OnlineProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
a.SetStatusOnline(args.UserId, true)
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_online.success")}

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

@@ -10,6 +10,7 @@ import (
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -68,7 +69,7 @@ func (rp *RemoteProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Co
}
}
func (rp *RemoteProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (rp *RemoteProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
if !a.HasPermissionTo(args.UserId, model.PERMISSION_MANAGE_SECURE_CONNECTIONS) {
return responsef(args.T("api.command_remote.permission_required", map[string]interface{}{"Permission": "manage_secure_connections"}))
}

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

@@ -8,6 +8,7 @@ import (
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
"github.com/mattermost/mattermost-server/v5/shared/mlog"
@@ -57,15 +58,15 @@ func (*KickProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Command
}
}
func (*RemoveProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
return doCommand(a, args, message)
func (*RemoveProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
return doCommand(a, c, args, message)
}
func (*KickProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
return doCommand(a, args, message)
func (*KickProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
return doCommand(a, c, args, message)
}
func doCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func doCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
channel, err := a.GetChannel(args.ChannelId)
if err != nil {
return &model.CommandResponse{
@@ -134,7 +135,7 @@ func doCommand(a *app.App, args *model.CommandArgs, message string) *model.Comma
}
}
if err = a.RemoveUserFromChannel(userProfile.Id, args.UserId, channel); err != nil {
if err = a.RemoveUserFromChannel(c, userProfile.Id, args.UserId, channel); err != nil {
var text string
if err.Id == "api.channel.remove_members.denied" {
text = args.T("api.command_remove.group_constrained_user_denied")

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

@@ -17,7 +17,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
rp := RemoveProvider{}
publicChannel, _ := th.App.CreateChannel(&model.Channel{
publicChannel, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "AA",
Name: "aa" + model.NewId() + "a",
Type: model.CHANNEL_OPEN,
@@ -25,7 +25,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
CreatorId: th.BasicUser.Id,
}, false)
privateChannel, _ := th.App.CreateChannel(&model.Channel{
privateChannel, _ := th.App.CreateChannel(th.Context, &model.Channel{
DisplayName: "BB",
Name: "aa" + model.NewId() + "a",
Type: model.CHANNEL_OPEN,
@@ -34,7 +34,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
}, false)
targetUser := th.createUser()
th.App.AddUserToTeam(th.BasicTeam.Id, targetUser.Id, targetUser.Id)
th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, targetUser.Id, targetUser.Id)
th.App.AddUserToChannel(targetUser, publicChannel, false)
th.App.AddUserToChannel(targetUser, privateChannel, false)
@@ -45,7 +45,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual := rp.DoCommand(th.App, args, targetUser.Username).Text
actual := rp.DoCommand(th.App, th.Context, args, targetUser.Username).Text
assert.Equal(t, "api.command_remove.permission.app_error", actual)
// Try a public channel *with* permission.
@@ -56,7 +56,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = rp.DoCommand(th.App, args, targetUser.Username).Text
actual = rp.DoCommand(th.App, th.Context, args, targetUser.Username).Text
assert.Equal(t, "", actual)
// Try a private channel *without* permission.
@@ -66,7 +66,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = rp.DoCommand(th.App, args, targetUser.Username).Text
actual = rp.DoCommand(th.App, th.Context, args, targetUser.Username).Text
assert.Equal(t, "api.command_remove.permission.app_error", actual)
// Try a private channel *with* permission.
@@ -77,7 +77,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = rp.DoCommand(th.App, args, targetUser.Username).Text
actual = rp.DoCommand(th.App, th.Context, args, targetUser.Username).Text
assert.Equal(t, "", actual)
// Try a group channel
@@ -92,7 +92,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = rp.DoCommand(th.App, args, user1.Username).Text
actual = rp.DoCommand(th.App, th.Context, args, user1.Username).Text
assert.Equal(t, "api.command_remove.direct_group.app_error", actual)
// Try a direct channel *with* being a member.
@@ -104,14 +104,14 @@ func TestRemoveProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = rp.DoCommand(th.App, args, user1.Username).Text
actual = rp.DoCommand(th.App, th.Context, args, user1.Username).Text
assert.Equal(t, "api.command_remove.direct_group.app_error", actual)
// Try a public channel with a deactivated user.
deactivatedUser := th.createUser()
th.App.AddUserToTeam(th.BasicTeam.Id, deactivatedUser.Id, deactivatedUser.Id)
th.App.AddUserToTeam(th.Context, th.BasicTeam.Id, deactivatedUser.Id, deactivatedUser.Id)
th.App.AddUserToChannel(deactivatedUser, publicChannel, false)
th.App.UpdateActive(deactivatedUser, false)
th.App.UpdateActive(th.Context, deactivatedUser, false)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -119,6 +119,6 @@ func TestRemoveProviderDoCommand(t *testing.T) {
UserId: th.BasicUser.Id,
}
actual = rp.DoCommand(th.App, args, deactivatedUser.Username).Text
actual = rp.DoCommand(th.App, th.Context, args, deactivatedUser.Username).Text
assert.Equal(t, "api.command_remove.missing.app_error", actual)
}

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -34,7 +35,7 @@ func (search *SearchProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *mode
}
}
func (search *SearchProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (search *SearchProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
// This command is handled client-side and shouldn't hit the server.
return &model.CommandResponse{
Text: args.T("api.command_search.unsupported.app_error"),

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -34,7 +35,7 @@ func (settings *SettingsProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *
}
}
func (settings *SettingsProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (settings *SettingsProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
// This command is handled client-side and shouldn't hit the server.
return &model.CommandResponse{
Text: args.T("api.command_settings.unsupported.app_error"),

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

@@ -9,6 +9,7 @@ import (
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -119,7 +120,7 @@ func (sp *ShareProvider) getAutoCompleteUnInviteRemote(a *app.App, _ *model.Comm
}
}
func (sp *ShareProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (sp *ShareProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
if !a.HasPermissionTo(args.UserId, model.PERMISSION_MANAGE_SHARED_CHANNELS) {
return responsef(args.T("api.command_share.permission_required", map[string]interface{}{"Permission": "manage_shared_channels"}))
}

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

@@ -46,7 +46,7 @@ func TestShareProviderDoCommand(t *testing.T) {
Command: "/share-channel share",
}
response := commandProvider.DoCommand(th.App, args, "")
response := commandProvider.DoCommand(th.App, th.Context, args, "")
require.Equal(t, "##### "+args.T("api.command_share.channel_shared"), response.Text)
channelConvertedMessages := testCluster.SelectMessages(func(msg *model.ClusterMessage) bool {
@@ -81,7 +81,7 @@ func TestShareProviderDoCommand(t *testing.T) {
Command: "/share-channel unshare",
}
response := commandProvider.DoCommand(th.App, args, "")
response := commandProvider.DoCommand(th.App, th.Context, args, "")
require.Equal(t, "##### "+args.T("api.command_share.shared_channel_unavailable"), response.Text)
channelConvertedMessages := testCluster.SelectMessages(func(msg *model.ClusterMessage) bool {

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -34,7 +35,7 @@ func (*ShortcutsProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Co
}
}
func (*ShortcutsProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*ShortcutsProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
// This command is handled client-side and shouldn't hit the server.
return &model.CommandResponse{
Text: args.T("api.command_shortcuts.unsupported.app_error"),

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

@@ -5,6 +5,7 @@ package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/i18n"
)
@@ -34,7 +35,7 @@ func (*ShrugProvider) GetCommand(a *app.App, T i18n.TranslateFunc) *model.Comman
}
}
func (*ShrugProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
func (*ShrugProvider) DoCommand(a *app.App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
rmsg := `¯\\\_(ツ)\_/¯`
if message != "" {
rmsg = message + " " + rmsg

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

@@ -82,7 +82,7 @@ func TestCreateCommandPost(t *testing.T) {
}
skipSlackParsing := false
_, err := th.App.CreateCommandPost(post, th.BasicTeam.Id, resp, skipSlackParsing)
_, err := th.App.CreateCommandPost(th.Context, post, th.BasicTeam.Id, resp, skipSlackParsing)
require.NotNil(t, err)
require.Equal(t, err.Id, "api.context.invalid_param.app_error")
}
@@ -108,7 +108,7 @@ func TestExecuteCommand(t *testing.T) {
UserId: th.BasicUser.Id,
T: func(s string, args ...interface{}) string { return s },
}
resp, err := th.App.ExecuteCommand(args)
resp, err := th.App.ExecuteCommand(th.Context, args)
require.Nil(t, err)
require.NotNil(t, resp)
@@ -121,7 +121,7 @@ func TestExecuteCommand(t *testing.T) {
Command: "missing leading slash character",
T: func(s string, args ...interface{}) string { return s },
}
_, err := th.App.ExecuteCommand(argsMissingSlashCharacter)
_, err := th.App.ExecuteCommand(th.Context, argsMissingSlashCharacter)
require.Equal(t, "api.command.execute_command.format.app_error", err.Id)
})
@@ -130,7 +130,7 @@ func TestExecuteCommand(t *testing.T) {
Command: "",
T: func(s string, args ...interface{}) string { return s },
}
_, err := th.App.ExecuteCommand(argsMissingSlashCharacter)
_, err := th.App.ExecuteCommand(th.Context, argsMissingSlashCharacter)
require.Equal(t, "api.command.execute_command.format.app_error", err.Id)
})
}
@@ -157,7 +157,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
builtIn := true
post, err := th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err := th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
assert.Equal(t, args.ChannelId, post.ChannelId)
assert.Equal(t, args.RootId, post.RootId)
@@ -172,7 +172,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
// Command is not built in, so it is a bot command.
builtIn = false
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err = th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
assert.Equal(t, "true", post.GetProp("from_webhook"))
@@ -183,7 +183,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
resp.ChannelId = channel.Id
th.addUserToChannel(th.BasicUser, channel)
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err = th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
assert.Equal(t, resp.ChannelId, post.ChannelId)
assert.NotEqual(t, args.ChannelId, post.ChannelId)
@@ -194,14 +194,14 @@ func TestHandleCommandResponsePost(t *testing.T) {
command.Username = "Command username"
resp.Username = "Response username"
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err = th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
assert.Nil(t, post.GetProp("override_username"))
*th.App.Config().ServiceSettings.EnablePostUsernameOverride = true
// Override username config is turned on. Override username through command property.
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err = th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
assert.Equal(t, command.Username, post.GetProp("override_username"))
assert.Equal(t, "true", post.GetProp("from_webhook"))
@@ -209,7 +209,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
command.Username = ""
// Override username through response property.
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err = th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
assert.Equal(t, resp.Username, post.GetProp("override_username"))
assert.Equal(t, "true", post.GetProp("from_webhook"))
@@ -221,14 +221,14 @@ func TestHandleCommandResponsePost(t *testing.T) {
command.IconURL = "Command icon url"
resp.IconURL = "Response icon url"
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err = th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
assert.Nil(t, post.GetProp("override_icon_url"))
*th.App.Config().ServiceSettings.EnablePostIconOverride = true
// Override icon url config is turned on. Override icon url through command property.
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err = th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
assert.Equal(t, command.IconURL, post.GetProp("override_icon_url"))
assert.Equal(t, "true", post.GetProp("from_webhook"))
@@ -236,7 +236,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
command.IconURL = ""
// Override icon url through response property.
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err = th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
assert.Equal(t, resp.IconURL, post.GetProp("override_icon_url"))
assert.Equal(t, "true", post.GetProp("from_webhook"))
@@ -244,7 +244,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
// Test Slack text conversion.
resp.Text = "<!channel>"
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err = th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
assert.Equal(t, "@channel", post.Message)
assert.Equal(t, "true", post.GetProp("from_webhook"))
@@ -256,7 +256,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
},
}
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err = th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
assert.Equal(t, "@channel", post.Message)
if assert.Len(t, post.Attachments(), 1) {
@@ -267,7 +267,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
channel = th.createPrivateChannel(th.BasicTeam)
resp.ChannelId = channel.Id
args.UserId = th.BasicUser2.Id
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err = th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
require.NotNil(t, err)
require.Equal(t, err.Id, "api.command.command_post.forbidden.app_error")
@@ -284,7 +284,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
// set and unset SkipSlackParsing here seems the nicest way as no separate response objects are created for every testcase.
resp.SkipSlackParsing = true
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
post, err = th.App.HandleCommandResponsePost(th.Context, command, args, resp, builtIn)
resp.SkipSlackParsing = false
assert.Nil(t, err)
@@ -311,7 +311,7 @@ func TestHandleCommandResponse(t *testing.T) {
builtIn := true
_, err := th.App.HandleCommandResponse(command, args, resp, builtIn)
_, err := th.App.HandleCommandResponse(th.Context, command, args, resp, builtIn)
require.NotNil(t, err)
require.Equal(t, err.Id, "api.command.execute_command.create_post_failed.app_error")
@@ -319,7 +319,7 @@ func TestHandleCommandResponse(t *testing.T) {
Text: "message 1",
}
_, err = th.App.HandleCommandResponse(command, args, resp, builtIn)
_, err = th.App.HandleCommandResponse(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
resp = &model.CommandResponse{
@@ -335,7 +335,7 @@ func TestHandleCommandResponse(t *testing.T) {
},
}
_, err = th.App.HandleCommandResponse(command, args, resp, builtIn)
_, err = th.App.HandleCommandResponse(th.Context, command, args, resp, builtIn)
require.NotNil(t, err)
require.Equal(t, err.Id, "api.command.execute_command.create_post_failed.app_error")
@@ -346,7 +346,7 @@ func TestHandleCommandResponse(t *testing.T) {
},
}
_, err = th.App.HandleCommandResponse(command, args, resp, builtIn)
_, err = th.App.HandleCommandResponse(th.Context, command, args, resp, builtIn)
assert.Nil(t, err)
}

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

@@ -15,6 +15,7 @@ import (
"time"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/config"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/mlog"
@@ -25,6 +26,7 @@ import (
type TestHelper struct {
App *app.App
Context *request.Context
Server *app.Server
BasicTeam *model.Team
BasicUser *model.User
@@ -80,6 +82,7 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
th := &TestHelper{
App: app.New(app.ServerConnector(s)),
Context: &request.Context{},
Server: s,
LogBuffer: buffer,
IncludeCacheLayer: includeCacheLayer,
@@ -113,6 +116,8 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
if enterprise {
th.App.Srv().SetLicense(model.NewTestLicense())
th.App.Srv().Jobs.InitWorkers()
th.App.Srv().Jobs.InitSchedulers()
} else {
th.App.Srv().SetLicense(nil)
}
@@ -121,8 +126,6 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
th.tempWorkspace = tempWorkspace
}
th.App.InitServer()
return th
}
@@ -186,7 +189,7 @@ func (th *TestHelper) createTeam() *model.Team {
utils.DisableDebugLogForTest()
var err *model.AppError
if team, err = th.App.CreateTeam(team); err != nil {
if team, err = th.App.CreateTeam(th.Context, team); err != nil {
panic(err)
}
utils.EnableDebugLogForTest()
@@ -215,11 +218,11 @@ func (th *TestHelper) createUserOrGuest(guest bool) *model.User {
utils.DisableDebugLogForTest()
var err *model.AppError
if guest {
if user, err = th.App.CreateGuest(user); err != nil {
if user, err = th.App.CreateGuest(th.Context, user); err != nil {
panic(err)
}
} else {
if user, err = th.App.CreateUser(user); err != nil {
if user, err = th.App.CreateUser(th.Context, user); err != nil {
panic(err)
}
}
@@ -260,7 +263,7 @@ func (th *TestHelper) createChannel(team *model.Team, channelType string, option
utils.DisableDebugLogForTest()
var err *model.AppError
if channel, err = th.App.CreateChannel(channel, true); err != nil {
if channel, err = th.App.CreateChannel(th.Context, channel, true); err != nil {
panic(err)
}
@@ -297,7 +300,7 @@ func (th *TestHelper) createChannelWithAnotherUser(team *model.Team, channelType
utils.DisableDebugLogForTest()
var err *model.AppError
if channel, err = th.App.CreateChannel(channel, true); err != nil {
if channel, err = th.App.CreateChannel(th.Context, channel, true); err != nil {
panic(err)
}
utils.EnableDebugLogForTest()
@@ -308,7 +311,7 @@ func (th *TestHelper) createDmChannel(user *model.User) *model.Channel {
utils.DisableDebugLogForTest()
var err *model.AppError
var channel *model.Channel
if channel, err = th.App.GetOrCreateDirectChannel(th.BasicUser.Id, user.Id); err != nil {
if channel, err = th.App.GetOrCreateDirectChannel(th.Context, th.BasicUser.Id, user.Id); err != nil {
panic(err)
}
utils.EnableDebugLogForTest()
@@ -338,7 +341,7 @@ func (th *TestHelper) createPost(channel *model.Channel) *model.Post {
utils.DisableDebugLogForTest()
var err *model.AppError
if post, err = th.App.CreatePost(post, channel, false, true); err != nil {
if post, err = th.App.CreatePost(th.Context, post, channel, false, true); err != nil {
panic(err)
}
utils.EnableDebugLogForTest()
@@ -348,7 +351,7 @@ func (th *TestHelper) createPost(channel *model.Channel) *model.Post {
func (th *TestHelper) linkUserToTeam(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest()
_, err := th.App.JoinUserToTeam(team, user, "")
_, err := th.App.JoinUserToTeam(th.Context, team, user, "")
if err != nil {
panic(err)
}