Moving slash-commands out of app package (#14979)

* Moving slash-commands out of app package

* Fixing golint checks

* Fixing golangci-lint

* Fixing golangci-lint errors
Этот коммит содержится в:
Jesús Espino
2020-08-12 18:29:58 +02:00
коммит произвёл GitHub
родитель 788c130774
Коммит 1f09d86f42
56 изменённых файлов: 897 добавлений и 355 удалений

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

@@ -48,8 +48,6 @@ type AppIface interface {
AddCursorIdsForPostList(originalList *model.PostList, afterPost, beforePost string, since int64, page, perPage int)
// AddPublicKey will add plugin public key to the config. Overwrites the previous file
AddPublicKey(name string, key io.Reader) *model.AppError
// Basic test team and user so you always know one
CreateBasicUser(client *model.Client4) *model.AppError
// Caller must close the first return value
FileReader(path string) (filesstore.ReadCloseSeeker, *model.AppError)
// ChannelMembersMinusGroupMembers returns the set of users in the given channel minus the set of users in the given
@@ -221,6 +219,12 @@ type AppIface interface {
MakeAuditRecord(event string, initialStatus string) *audit.Record
// MarkChanelAsUnreadFromPost will take a post and set the channel as unread from that one.
MarkChannelAsUnreadFromPost(postID string, userID string) (*model.ChannelUnreadAt, *model.AppError)
// MentionsToPublicChannels returns all the mentions to public channels,
// linking them to their channels
MentionsToPublicChannels(message, teamId string) model.ChannelMentionMap
// MentionsToTeamMembers returns all the @ mentions found in message that
// belong to users in the specified team, linking them to their users
MentionsToTeamMembers(message, teamId string) model.UserMentionMap
// MoveChannel method is prone to data races if someone joins to channel during the move process. However this
// function is only exposed to sysadmins and the possibility of this edge case is realtively small.
MoveChannel(team *model.Team, channel *model.Channel, user *model.User) *model.AppError
@@ -457,6 +461,7 @@ type AppIface interface {
DisableAutoResponder(userId string, asAdmin bool) *model.AppError
DisableUserAccessToken(token *model.UserAccessToken) *model.AppError
DoAppMigrations()
DoCommandRequest(cmd *model.Command, p url.Values) (*model.Command, *model.CommandResponse, *model.AppError)
DoEmojisPermissionsMigration()
DoGuestRolesCreationMigration()
DoLocalRequest(rawURL string, body []byte) (*http.Response, *model.AppError)

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

@@ -215,9 +215,9 @@ func (a *App) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *
return nil, model.NewAppError("command", "api.command.execute_command.not_found.app_error", map[string]interface{}{"Trigger": trigger}, "", http.StatusNotFound)
}
// mentionsToTeamMembers returns all the @ mentions found in message that
// MentionsToTeamMembers returns all the @ mentions found in message that
// belong to users in the specified team, linking them to their users
func (a *App) mentionsToTeamMembers(message, teamId string) model.UserMentionMap {
func (a *App) MentionsToTeamMembers(message, teamId string) model.UserMentionMap {
type mentionMapItem struct {
Name string
Id string
@@ -286,9 +286,9 @@ func (a *App) mentionsToTeamMembers(message, teamId string) model.UserMentionMap
return atMentionMap
}
// mentionsToPublicChannels returns all the mentions to public channels,
// MentionsToPublicChannels returns all the mentions to public channels,
// linking them to their channels
func (a *App) mentionsToPublicChannels(message, teamId string) model.ChannelMentionMap {
func (a *App) MentionsToPublicChannels(message, teamId string) model.ChannelMentionMap {
type mentionMapItem struct {
Name string
Id string
@@ -431,12 +431,12 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
p.Set("trigger_id", args.TriggerId)
userMentionMap := a.mentionsToTeamMembers(message, team.Id)
userMentionMap := a.MentionsToTeamMembers(message, team.Id)
for key, values := range userMentionMap.ToURLValues() {
p[key] = values
}
channelMentionMap := a.mentionsToPublicChannels(message, team.Id)
channelMentionMap := a.MentionsToPublicChannels(message, team.Id)
for key, values := range channelMentionMap.ToURLValues() {
p[key] = values
}
@@ -447,10 +447,10 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
}
p.Set("response_url", args.SiteURL+"/hooks/commands/"+hook.Id)
return a.doCommandRequest(cmd, p)
return a.DoCommandRequest(cmd, p)
}
func (a *App) doCommandRequest(cmd *model.Command, p url.Values) (*model.Command, *model.CommandResponse, *model.AppError) {
func (a *App) DoCommandRequest(cmd *model.Command, p url.Values) (*model.Command, *model.CommandResponse, *model.AppError) {
// Prepare the request
var req *http.Request
var err error

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

@@ -334,29 +334,6 @@ func (me *TestHelper) createChannel(team *model.Team, channelType string) *model
return channel
}
func (me *TestHelper) createChannelWithAnotherUser(team *model.Team, channelType, userId string) *model.Channel {
id := model.NewId()
channel := &model.Channel{
DisplayName: "dn_" + id,
Name: "name_" + id,
Type: channelType,
TeamId: team.Id,
CreatorId: userId,
}
utils.DisableDebugLogForTest()
var err *model.AppError
if channel, err = me.App.CreateChannel(channel, true); err != nil {
mlog.Error(err.Error())
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
return channel
}
func (me *TestHelper) CreateDmChannel(user *model.User) *model.Channel {
utils.DisableDebugLogForTest()
var err *model.AppError

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

@@ -1427,28 +1427,6 @@ func (a *OpenTracingAppLayer) CopyFileInfos(userId string, fileIds []string) ([]
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) CreateBasicUser(client *model.Client4) *model.AppError {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateBasicUser")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
resultVar0 := a.app.CreateBasicUser(client)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}
func (a *OpenTracingAppLayer) CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateBot")
@@ -3058,6 +3036,28 @@ func (a *OpenTracingAppLayer) DoAppMigrations() {
a.app.DoAppMigrations()
}
func (a *OpenTracingAppLayer) DoCommandRequest(cmd *model.Command, p url.Values) (*model.Command, *model.CommandResponse, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DoCommandRequest")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
resultVar0, resultVar1, resultVar2 := a.app.DoCommandRequest(cmd, p)
if resultVar2 != nil {
span.LogFields(spanlog.Error(resultVar2))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1, resultVar2
}
func (a *OpenTracingAppLayer) DoEmojisPermissionsMigration() {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DoEmojisPermissionsMigration")
@@ -10103,6 +10103,40 @@ func (a *OpenTracingAppLayer) MaxPostSize() int {
return resultVar0
}
func (a *OpenTracingAppLayer) MentionsToPublicChannels(message string, teamId string) model.ChannelMentionMap {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.MentionsToPublicChannels")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
resultVar0 := a.app.MentionsToPublicChannels(message, teamId)
return resultVar0
}
func (a *OpenTracingAppLayer) MentionsToTeamMembers(message string, teamId string) model.UserMentionMap {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.MentionsToTeamMembers")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
resultVar0 := a.app.MentionsToTeamMembers(message, teamId)
return resultVar0
}
func (a *OpenTracingAppLayer) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.MigrateFilenamesToFileInfos")

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

@@ -141,11 +141,11 @@ func (a *App) tryExecutePluginCommand(args *model.CommandArgs) (*model.Command,
return matched.Command, nil, model.NewAppError("ExecutePluginCommand", "model.plugin_command.error.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
}
for username, userId := range a.mentionsToTeamMembers(args.Command, args.TeamId) {
for username, userId := range a.MentionsToTeamMembers(args.Command, args.TeamId) {
args.AddUserMention(username, userId)
}
for channelName, channelId := range a.mentionsToPublicChannels(args.Command, args.TeamId) {
for channelName, channelId := range a.MentionsToPublicChannels(args.Command, args.TeamId) {
args.AddChannelMention(channelName, channelId)
}

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

@@ -1,15 +1,16 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils"
)
type AutoChannelCreator struct {
a *App
a *app.App
userId string
team *model.Team
Fuzzy bool
@@ -20,7 +21,7 @@ type AutoChannelCreator struct {
ChannelType string
}
func NewAutoChannelCreator(a *App, team *model.Team, userId string) *AutoChannelCreator {
func NewAutoChannelCreator(a *app.App, team *model.Team, userId string) *AutoChannelCreator {
return &AutoChannelCreator{
a: a,
team: team,

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/model"

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

@@ -1,12 +1,13 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"math/rand"
"time"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils"
)
@@ -16,7 +17,7 @@ type TestEnvironment struct {
Environments []TeamEnvironment
}
func CreateTestEnvironmentWithTeams(a *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, 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)
@@ -46,7 +47,7 @@ func CreateTestEnvironmentWithTeams(a *App, client *model.Client4, rangeTeams ut
return environment, nil
}
func CreateTestEnvironmentInTeam(a *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, 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

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"bytes"
@@ -9,13 +9,14 @@ import (
"os"
"path/filepath"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils"
"github.com/mattermost/mattermost-server/v5/utils/fileutils"
)
type AutoPostCreator struct {
a *App
a *app.App
channelid string
userid string
Fuzzy bool
@@ -28,7 +29,7 @@ type AutoPostCreator struct {
}
// Automatic poster used for testing
func NewAutoPostCreator(a *App, channelid, userid string) *AutoPostCreator {
func NewAutoPostCreator(a *app.App, channelid, userid string) *AutoPostCreator {
return &AutoPostCreator{
a: a,
channelid: channelid,

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/model"

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

@@ -1,15 +1,16 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils"
)
type AutoUserCreator struct {
app *App
app *app.App
client *model.Client4
team *model.Team
EmailLength utils.Range
@@ -19,7 +20,7 @@ type AutoUserCreator struct {
Fuzzy bool
}
func NewAutoUserCreator(a *App, client *model.Client4, team *model.Team) *AutoUserCreator {
func NewAutoUserCreator(a *app.App, client *model.Client4, team *model.Team) *AutoUserCreator {
return &AutoUserCreator{
app: a,
client: client,
@@ -33,7 +34,7 @@ func NewAutoUserCreator(a *App, client *model.Client4, team *model.Team) *AutoUs
}
// Basic test team and user so you always know one
func (a *App) CreateBasicUser(client *model.Client4) *model.AppError {
func CreateBasicUser(a *app.App, client *model.Client4) *model.AppError {
found, _ := client.TeamExists(BTEST_TEAM_NAME, "")
if found {
return nil

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -16,14 +17,14 @@ const (
)
func init() {
RegisterCommandProvider(&AwayProvider{})
app.RegisterCommandProvider(&AwayProvider{})
}
func (me *AwayProvider) GetTrigger() string {
return CMD_AWAY
}
func (me *AwayProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *AwayProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_AWAY,
AutoComplete: true,
@@ -32,7 +33,7 @@ func (me *AwayProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comman
}
}
func (me *AwayProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *AwayProvider) DoCommand(a *app.App, 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")}

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

@@ -1,11 +1,12 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -17,14 +18,14 @@ const (
)
func init() {
RegisterCommandProvider(&HeaderProvider{})
app.RegisterCommandProvider(&HeaderProvider{})
}
func (me *HeaderProvider) GetTrigger() string {
return CMD_HEADER
}
func (me *HeaderProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *HeaderProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_HEADER,
AutoComplete: true,
@@ -34,7 +35,7 @@ func (me *HeaderProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comm
}
}
func (me *HeaderProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *HeaderProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
channel, err := a.GetChannel(args.ChannelId)
if err != nil {
return &model.CommandResponse{

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"testing"
@@ -12,12 +12,12 @@ import (
)
func TestHeaderProviderDoCommand(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
hp := HeaderProvider{}
th.AddPermissionToRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
th.addPermissionToRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
// Try a public channel *with* permission.
args := &model.CommandArgs{
@@ -34,7 +34,7 @@ func TestHeaderProviderDoCommand(t *testing.T) {
assert.Equal(t, expected, actual)
}
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
th.removePermissionFromRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
// Try a public channel *without* permission.
args = &model.CommandArgs{
@@ -46,10 +46,10 @@ func TestHeaderProviderDoCommand(t *testing.T) {
actual := hp.DoCommand(th.App, 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)
th.addPermissionToRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
// Try a private channel *with* permission.
privateChannel := th.CreatePrivateChannel(th.BasicTeam)
privateChannel := th.createPrivateChannel(th.BasicTeam)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -60,7 +60,7 @@ func TestHeaderProviderDoCommand(t *testing.T) {
actual = hp.DoCommand(th.App, args, "hello").Text
assert.Equal(t, "", actual)
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
th.removePermissionFromRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
// Try a private channel *without* permission.
args = &model.CommandArgs{
@@ -73,11 +73,11 @@ func TestHeaderProviderDoCommand(t *testing.T) {
assert.Equal(t, "api.command_channel_header.permission.app_error", actual)
// Try a group channel *with* being a member.
user1 := th.CreateUser()
user2 := th.CreateUser()
user3 := th.CreateUser()
user1 := th.createUser()
user2 := th.createUser()
user3 := th.createUser()
groupChannel := th.CreateGroupChannel(user1, user2)
groupChannel := th.createGroupChannel(user1, user2)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -99,7 +99,7 @@ func TestHeaderProviderDoCommand(t *testing.T) {
assert.Equal(t, "api.command_channel_header.permission.app_error", actual)
// Try a direct channel *with* being a member.
directChannel := th.CreateDmChannel(user1)
directChannel := th.createDmChannel(user1)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },

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

@@ -1,11 +1,12 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -17,14 +18,14 @@ const (
)
func init() {
RegisterCommandProvider(&PurposeProvider{})
app.RegisterCommandProvider(&PurposeProvider{})
}
func (me *PurposeProvider) GetTrigger() string {
return CMD_PURPOSE
}
func (me *PurposeProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *PurposeProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_PURPOSE,
AutoComplete: true,
@@ -34,7 +35,7 @@ func (me *PurposeProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Com
}
}
func (me *PurposeProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *PurposeProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
channel, err := a.GetChannel(args.ChannelId)
if err != nil {
return &model.CommandResponse{

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"testing"
@@ -12,13 +12,13 @@ import (
)
func TestPurposeProviderDoCommand(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
pp := PurposeProvider{}
// Try a public channel *with* permission.
th.AddPermissionToRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
th.addPermissionToRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
args := &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -35,7 +35,7 @@ func TestPurposeProviderDoCommand(t *testing.T) {
}
// Try a public channel *without* permission.
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
th.removePermissionFromRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -46,9 +46,9 @@ func TestPurposeProviderDoCommand(t *testing.T) {
assert.Equal(t, "api.command_channel_purpose.permission.app_error", actual)
// Try a private channel *with* permission.
privateChannel := th.CreatePrivateChannel(th.BasicTeam)
privateChannel := th.createPrivateChannel(th.BasicTeam)
th.AddPermissionToRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
th.addPermissionToRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -60,7 +60,7 @@ func TestPurposeProviderDoCommand(t *testing.T) {
assert.Equal(t, "", actual)
// Try a private channel *without* permission.
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
th.removePermissionFromRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -71,10 +71,10 @@ func TestPurposeProviderDoCommand(t *testing.T) {
assert.Equal(t, "api.command_channel_purpose.permission.app_error", actual)
// Try a group channel *with* being a member.
user1 := th.CreateUser()
user2 := th.CreateUser()
user1 := th.createUser()
user2 := th.createUser()
groupChannel := th.CreateGroupChannel(user1, user2)
groupChannel := th.createGroupChannel(user1, user2)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -85,7 +85,7 @@ func TestPurposeProviderDoCommand(t *testing.T) {
assert.Equal(t, "api.command_channel_purpose.direct_group.app_error", actual)
// Try a direct channel *with* being a member.
directChannel := th.CreateDmChannel(user1)
directChannel := th.createDmChannel(user1)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },

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

@@ -1,11 +1,12 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -17,14 +18,14 @@ const (
)
func init() {
RegisterCommandProvider(&RenameProvider{})
app.RegisterCommandProvider(&RenameProvider{})
}
func (me *RenameProvider) GetTrigger() string {
return CMD_RENAME
}
func (me *RenameProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *RenameProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
renameAutocompleteData := model.NewAutocompleteData(CMD_RENAME, T("api.command_channel_rename.hint"), T("api.command_channel_rename.desc"))
renameAutocompleteData.AddTextArgument(T("api.command_channel_rename.hint"), "[text]", "")
return &model.Command{
@@ -37,7 +38,7 @@ func (me *RenameProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comm
}
}
func (me *RenameProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *RenameProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
channel, err := a.GetChannel(args.ChannelId)
if err != nil {
return &model.CommandResponse{

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"strings"
@@ -13,10 +13,10 @@ import (
)
func TestRenameProviderDoCommand(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
th.AddPermissionToRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
th.addPermissionToRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
rp := RenameProvider{}
args := &model.CommandArgs{
@@ -38,7 +38,7 @@ func TestRenameProviderDoCommand(t *testing.T) {
}
// Try a public channel *without* permission.
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
th.removePermissionFromRole(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -50,9 +50,9 @@ func TestRenameProviderDoCommand(t *testing.T) {
assert.Equal(t, "api.command_channel_rename.permission.app_error", actual)
// Try a private channel *with* permission.
privateChannel := th.CreatePrivateChannel(th.BasicTeam)
privateChannel := th.createPrivateChannel(th.BasicTeam)
th.AddPermissionToRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
th.addPermissionToRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -64,7 +64,7 @@ func TestRenameProviderDoCommand(t *testing.T) {
assert.Equal(t, "", actual)
// Try a private channel *without* permission.
th.RemovePermissionFromRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
th.removePermissionFromRole(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES.Id, model.CHANNEL_USER_ROLE_ID)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -76,10 +76,10 @@ func TestRenameProviderDoCommand(t *testing.T) {
assert.Equal(t, "api.command_channel_rename.permission.app_error", actual)
// Try a group channel *with* being a member.
user1 := th.CreateUser()
user2 := th.CreateUser()
user1 := th.createUser()
user2 := th.createUser()
groupChannel := th.CreateGroupChannel(user1, user2)
groupChannel := th.createGroupChannel(user1, user2)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -91,7 +91,7 @@ func TestRenameProviderDoCommand(t *testing.T) {
assert.Equal(t, "api.command_channel_rename.direct_group.app_error", actual)
// Try a direct channel *with* being a member.
directChannel := th.CreateDmChannel(user1)
directChannel := th.createDmChannel(user1)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },

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

@@ -1,12 +1,13 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -18,14 +19,14 @@ const (
)
func init() {
RegisterCommandProvider(&CodeProvider{})
app.RegisterCommandProvider(&CodeProvider{})
}
func (me *CodeProvider) GetTrigger() string {
return CMD_CODE
}
func (me *CodeProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *CodeProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_CODE,
AutoComplete: true,
@@ -35,7 +36,7 @@ func (me *CodeProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comman
}
}
func (me *CodeProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *CodeProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
if len(message) == 0 {
return &model.CommandResponse{Text: args.T("api.command_code.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"testing"

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -16,14 +17,14 @@ const (
)
func init() {
RegisterCommandProvider(&DndProvider{})
app.RegisterCommandProvider(&DndProvider{})
}
func (me *DndProvider) GetTrigger() string {
return CMD_DND
}
func (me *DndProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *DndProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_DND,
AutoComplete: true,
@@ -32,7 +33,7 @@ func (me *DndProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command
}
}
func (me *DndProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *DndProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
status, err := a.GetStatus(args.UserId)
if err != nil {
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_dnd.error")}

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"strconv"
@@ -9,6 +9,7 @@ import (
"time"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -23,14 +24,14 @@ const (
)
func init() {
RegisterCommandProvider(&EchoProvider{})
app.RegisterCommandProvider(&EchoProvider{})
}
func (me *EchoProvider) GetTrigger() string {
return CMD_ECHO
}
func (me *EchoProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *EchoProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_ECHO,
AutoComplete: true,
@@ -40,7 +41,7 @@ func (me *EchoProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comman
}
}
func (me *EchoProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *EchoProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
if len(message) == 0 {
return &model.CommandResponse{Text: args.T("api.command_echo.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}

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

@@ -1,12 +1,13 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"strconv"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -22,8 +23,8 @@ const (
)
func init() {
RegisterCommandProvider(&ExpandProvider{})
RegisterCommandProvider(&CollapseProvider{})
app.RegisterCommandProvider(&ExpandProvider{})
app.RegisterCommandProvider(&CollapseProvider{})
}
func (me *ExpandProvider) GetTrigger() string {
@@ -34,7 +35,7 @@ func (me *CollapseProvider) GetTrigger() string {
return CMD_COLLAPSE
}
func (me *ExpandProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *ExpandProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_EXPAND,
AutoComplete: true,
@@ -43,7 +44,7 @@ func (me *ExpandProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comm
}
}
func (me *CollapseProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *CollapseProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_COLLAPSE,
AutoComplete: true,
@@ -52,15 +53,15 @@ func (me *CollapseProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Co
}
}
func (me *ExpandProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
return a.setCollapsePreference(args, false)
func (me *ExpandProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
return setCollapsePreference(a, args, false)
}
func (me *CollapseProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
return a.setCollapsePreference(args, true)
func (me *CollapseProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
return setCollapsePreference(a, args, true)
}
func (a *App) setCollapsePreference(args *model.CommandArgs, isCollapse bool) *model.CommandResponse {
func setCollapsePreference(a *app.App, args *model.CommandArgs, isCollapse bool) *model.CommandResponse {
pref := model.Preference{
UserId: args.UserId,
Category: model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS,

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

@@ -1,13 +1,14 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"fmt"
"strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -20,14 +21,14 @@ const (
)
func init() {
RegisterCommandProvider(&groupmsgProvider{})
app.RegisterCommandProvider(&groupmsgProvider{})
}
func (me *groupmsgProvider) GetTrigger() string {
return CMD_GROUPMSG
}
func (me *groupmsgProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *groupmsgProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_GROUPMSG,
AutoComplete: true,
@@ -37,7 +38,7 @@ func (me *groupmsgProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Co
}
}
func (me *groupmsgProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *groupmsgProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
targetUsers := map[string]*model.User{}
targetUsersSlice := []string{args.UserId}
invalidUsernames := []string{}
@@ -81,7 +82,7 @@ func (me *groupmsgProvider) DoCommand(a *App, args *model.CommandArgs, message s
}
if len(targetUsersSlice) == 2 {
return GetCommandProvider("msg").DoCommand(a, args, fmt.Sprintf("%s %s", targetUsers[targetUsersSlice[1]].Username, parsedMessage))
return app.GetCommandProvider("msg").DoCommand(a, args, fmt.Sprintf("%s %s", targetUsers[targetUsersSlice[1]].Username, parsedMessage))
}
if len(targetUsersSlice) < model.CHANNEL_GROUP_MIN_USERS {

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"testing"
@@ -54,17 +54,17 @@ func TestGroupMsgUsernames(t *testing.T) {
}
func TestGroupMsgProvider(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
user3 := th.CreateUser()
user3 := th.createUser()
targetUsers := "@" + th.BasicUser2.Username + ",@" + user3.Username + " "
team := th.CreateTeam()
th.LinkUserToTeam(th.BasicUser, team)
team := th.createTeam()
th.linkUserToTeam(th.BasicUser, team)
cmd := &groupmsgProvider{}
th.RemovePermissionFromRole(model.PERMISSION_CREATE_GROUP_CHANNEL.Id, model.SYSTEM_USER_ROLE_ID)
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{
@@ -78,11 +78,11 @@ func TestGroupMsgProvider(t *testing.T) {
assert.Equal(t, "", resp.GotoLocation)
})
th.AddPermissionToRole(model.PERMISSION_CREATE_GROUP_CHANNEL.Id, model.SYSTEM_USER_ROLE_ID)
th.addPermissionToRole(model.PERMISSION_CREATE_GROUP_CHANNEL.Id, model.SYSTEM_USER_ROLE_ID)
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)
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{
T: i18n.IdentityTfunc(),
SiteURL: "http://test.url",

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -16,14 +17,14 @@ const (
)
func init() {
RegisterCommandProvider(&HelpProvider{})
app.RegisterCommandProvider(&HelpProvider{})
}
func (h *HelpProvider) GetTrigger() string {
return CMD_HELP
}
func (h *HelpProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (h *HelpProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_HELP,
AutoComplete: true,
@@ -32,7 +33,7 @@ func (h *HelpProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command
}
}
func (h *HelpProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (h *HelpProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
helpLink := *a.Config().SupportSettings.HelpLink
if helpLink == "" {

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

@@ -1,13 +1,14 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -20,14 +21,14 @@ const (
)
func init() {
RegisterCommandProvider(&InviteProvider{})
app.RegisterCommandProvider(&InviteProvider{})
}
func (me *InviteProvider) GetTrigger() string {
return CMD_INVITE
}
func (me *InviteProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *InviteProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_INVITE,
AutoComplete: true,
@@ -37,7 +38,7 @@ func (me *InviteProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comm
}
}
func (me *InviteProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *InviteProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
if message == "" {
return &model.CommandResponse{
Text: args.T("api.command_invite.missing_message.app_error"),

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

@@ -1,12 +1,13 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -19,14 +20,14 @@ const (
)
func init() {
RegisterCommandProvider(&InvitePeopleProvider{})
app.RegisterCommandProvider(&InvitePeopleProvider{})
}
func (me *InvitePeopleProvider) GetTrigger() string {
return CMD_INVITE_PEOPLE
}
func (me *InvitePeopleProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *InvitePeopleProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
autoComplete := true
if !*a.Config().EmailSettings.SendEmailNotifications || !*a.Config().TeamSettings.EnableUserCreation || !*a.Config().ServiceSettings.EnableEmailInvitations {
autoComplete = false
@@ -40,7 +41,7 @@ func (me *InvitePeopleProvider) GetCommand(a *App, T goi18n.TranslateFunc) *mode
}
}
func (me *InvitePeopleProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *InvitePeopleProvider) DoCommand(a *app.App, 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}
}

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"testing"
@@ -12,8 +12,8 @@ import (
)
func TestInvitePeopleProvider(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.EmailSettings.SendEmailNotifications = true
@@ -22,7 +22,7 @@ func TestInvitePeopleProvider(t *testing.T) {
cmd := InvitePeopleProvider{}
notTeamUser := th.CreateUser()
notTeamUser := th.createUser()
// Test without required permissions
args := &model.CommandArgs{

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"testing"
@@ -13,18 +13,18 @@ import (
)
func TestInviteProvider(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
channel := th.createChannel(th.BasicTeam, model.CHANNEL_OPEN)
privateChannel := th.createChannel(th.BasicTeam, model.CHANNEL_PRIVATE)
dmChannel := th.CreateDmChannel(th.BasicUser2)
dmChannel := th.createDmChannel(th.BasicUser2)
privateChannel2 := th.createChannelWithAnotherUser(th.BasicTeam, model.CHANNEL_PRIVATE, th.BasicUser2.Id)
basicUser3 := th.CreateUser()
th.LinkUserToTeam(basicUser3, th.BasicTeam)
basicUser4 := th.CreateUser()
deactivatedUser := th.CreateUser()
basicUser3 := th.createUser()
th.linkUserToTeam(basicUser3, th.BasicTeam)
basicUser4 := th.createUser()
deactivatedUser := th.createUser()
th.App.UpdateActive(deactivatedUser, false)
var err *model.AppError
@@ -175,8 +175,8 @@ func TestInviteProvider(t *testing.T) {
}
func TestInviteGroup(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
th.BasicTeam.GroupConstrained = model.NewBool(true)
var err *model.AppError
@@ -189,7 +189,7 @@ func TestInviteGroup(t *testing.T) {
groupChannelUser1 := "@" + th.BasicUser.Username + " ~" + privateChannel.Name
groupChannelUser2 := "@" + th.BasicUser2.Username + " ~" + privateChannel.Name
basicUser3 := th.CreateUser()
basicUser3 := th.createUser()
groupChannelUser3 := "@" + basicUser3.Username + " ~" + privateChannel.Name
InviteP := InviteProvider{}

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

@@ -1,12 +1,13 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -18,14 +19,14 @@ const (
)
func init() {
RegisterCommandProvider(&JoinProvider{})
app.RegisterCommandProvider(&JoinProvider{})
}
func (me *JoinProvider) GetTrigger() string {
return CMD_JOIN
}
func (me *JoinProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *JoinProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_JOIN,
AutoComplete: true,
@@ -35,7 +36,7 @@ func (me *JoinProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comman
}
}
func (me *JoinProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *JoinProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
channelName := message
if strings.HasPrefix(message, "~") {

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"testing"
@@ -13,8 +13,8 @@ import (
)
func TestJoinCommandNoChannel(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
if testing.Short() {
t.SkipNow()
@@ -32,8 +32,8 @@ func TestJoinCommandNoChannel(t *testing.T) {
}
func TestJoinCommandForExistingChannel(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
if testing.Short() {
t.SkipNow()
@@ -60,8 +60,8 @@ func TestJoinCommandForExistingChannel(t *testing.T) {
}
func TestJoinCommandWithTilde(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
if testing.Short() {
t.SkipNow()
@@ -88,8 +88,8 @@ func TestJoinCommandWithTilde(t *testing.T) {
}
func TestJoinCommandPermissions(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
channel2, _ := th.App.CreateChannel(&model.Channel{
DisplayName: "AA",
@@ -101,7 +101,7 @@ func TestJoinCommandPermissions(t *testing.T) {
cmd := &JoinProvider{}
user3 := th.CreateUser()
user3 := th.createUser()
// Try a public channel *without* permission.
args := &model.CommandArgs{

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -16,14 +17,14 @@ const (
)
func init() {
RegisterCommandProvider(&LeaveProvider{})
app.RegisterCommandProvider(&LeaveProvider{})
}
func (me *LeaveProvider) GetTrigger() string {
return CMD_LEAVE
}
func (me *LeaveProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *LeaveProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_LEAVE,
AutoComplete: true,
@@ -32,7 +33,7 @@ func (me *LeaveProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comma
}
}
func (me *LeaveProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *LeaveProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
var channel *model.Channel
var noChannelErr *model.AppError
if channel, noChannelErr = a.GetChannel(args.ChannelId); noChannelErr != nil {

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"testing"
@@ -13,8 +13,8 @@ import (
)
func TestLeaveProviderDoCommand(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
lp := LeaveProvider{}
@@ -37,7 +37,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
defaultChannel, err := th.App.GetChannelByName(model.DEFAULT_CHANNEL, th.BasicTeam.Id, false)
require.Nil(t, err)
guest := th.CreateGuest()
guest := th.createGuest()
th.App.AddUserToTeam(th.BasicTeam.Id, th.BasicUser.Id, th.BasicUser.Id)
th.App.AddUserToChannel(th.BasicUser, publicChannel)

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"io"
@@ -13,6 +13,7 @@ import (
"strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils"
@@ -86,14 +87,14 @@ type LoadTestProvider struct {
}
func init() {
RegisterCommandProvider(&LoadTestProvider{})
app.RegisterCommandProvider(&LoadTestProvider{})
}
func (me *LoadTestProvider) GetTrigger() string {
return CMD_TEST
}
func (me *LoadTestProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *LoadTestProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
if !*a.Config().ServiceSettings.EnableTesting {
return nil
}
@@ -106,7 +107,7 @@ func (me *LoadTestProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Co
}
}
func (me *LoadTestProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *LoadTestProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
commandResponse, err := me.doCommand(a, args, message)
if err != nil {
mlog.Error("failed command /"+CMD_TEST, mlog.Err(err))
@@ -115,7 +116,7 @@ func (me *LoadTestProvider) DoCommand(a *App, args *model.CommandArgs, message s
return commandResponse
}
func (me *LoadTestProvider) doCommand(a *App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (me *LoadTestProvider) doCommand(a *app.App, 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
@@ -168,7 +169,7 @@ func (me *LoadTestProvider) HelpCommand(args *model.CommandArgs, message string)
return &model.CommandResponse{Text: usage, ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
func (me *LoadTestProvider) SetupCommand(a *App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (me *LoadTestProvider) SetupCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
tokens := strings.Fields(strings.TrimPrefix(message, "setup"))
doTeams := contains(tokens, "teams")
doFuzz := contains(tokens, "fuzz")
@@ -209,7 +210,7 @@ func (me *LoadTestProvider) SetupCommand(a *App, args *model.CommandArgs, messag
client := model.NewAPIv4Client(args.SiteURL)
if doTeams {
if err := a.CreateBasicUser(client); err != nil {
if err := CreateBasicUser(a, client); err != nil {
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
}
_, resp := client.Login(BTEST_USER_EMAIL, BTEST_USER_PASSWORD)
@@ -252,7 +253,7 @@ func (me *LoadTestProvider) SetupCommand(a *App, args *model.CommandArgs, messag
return &model.CommandResponse{Text: "Created environment", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (me *LoadTestProvider) ActivateUserCommand(a *App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (me *LoadTestProvider) ActivateUserCommand(a *app.App, 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 {
return &model.CommandResponse{Text: "Failed to activate user", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
@@ -261,7 +262,7 @@ func (me *LoadTestProvider) ActivateUserCommand(a *App, args *model.CommandArgs,
return &model.CommandResponse{Text: "Activated user", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (me *LoadTestProvider) DeActivateUserCommand(a *App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (me *LoadTestProvider) DeActivateUserCommand(a *app.App, 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 {
return &model.CommandResponse{Text: "Failed to deactivate user", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, err
@@ -270,7 +271,7 @@ func (me *LoadTestProvider) DeActivateUserCommand(a *App, args *model.CommandArg
return &model.CommandResponse{Text: "DeActivated user", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (me *LoadTestProvider) UsersCommand(a *App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (me *LoadTestProvider) UsersCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
cmd := strings.TrimSpace(strings.TrimPrefix(message, "users"))
doFuzz := false
@@ -297,7 +298,7 @@ func (me *LoadTestProvider) UsersCommand(a *App, args *model.CommandArgs, messag
return &model.CommandResponse{Text: "Added users", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (me *LoadTestProvider) ChannelsCommand(a *App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (me *LoadTestProvider) ChannelsCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
cmd := strings.TrimSpace(strings.TrimPrefix(message, "channels"))
doFuzz := false
@@ -325,7 +326,7 @@ func (me *LoadTestProvider) ChannelsCommand(a *App, args *model.CommandArgs, mes
return &model.CommandResponse{Text: "Added channels", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (me *LoadTestProvider) ThreadedPostCommand(a *App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (me *LoadTestProvider) ThreadedPostCommand(a *app.App, 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 {
@@ -351,7 +352,7 @@ func (me *LoadTestProvider) ThreadedPostCommand(a *App, args *model.CommandArgs,
return &model.CommandResponse{Text: "Added threaded post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (me *LoadTestProvider) PostsCommand(a *App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (me *LoadTestProvider) PostsCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
cmd := strings.TrimSpace(strings.TrimPrefix(message, "posts"))
doFuzz := false
@@ -410,7 +411,7 @@ func getMatch(re *regexp.Regexp, text string) string {
return ""
}
func (me *LoadTestProvider) PostCommand(a *App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (me *LoadTestProvider) PostCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
textMessage := getMatch(messageRE, message)
if textMessage == "" {
return &model.CommandResponse{Text: "No message to post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
@@ -453,7 +454,7 @@ func (me *LoadTestProvider) PostCommand(a *App, args *model.CommandArgs, message
return &model.CommandResponse{Text: "Added a post to " + channel.DisplayName, ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (me *LoadTestProvider) UrlCommand(a *App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (me *LoadTestProvider) UrlCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
url := strings.TrimSpace(strings.TrimPrefix(message, "url"))
if len(url) == 0 {
return &model.CommandResponse{Text: "Command must contain a url", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
@@ -507,7 +508,7 @@ func (me *LoadTestProvider) UrlCommand(a *App, args *model.CommandArgs, message
return &model.CommandResponse{Text: "Loaded data", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil
}
func (me *LoadTestProvider) JsonCommand(a *App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
func (me *LoadTestProvider) JsonCommand(a *app.App, args *model.CommandArgs, message string) (*model.CommandResponse, error) {
url := strings.TrimSpace(strings.TrimPrefix(message, "json"))
if len(url) == 0 {
return &model.CommandResponse{Text: "Command must contain a url", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}, nil

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -16,14 +17,14 @@ const (
)
func init() {
RegisterCommandProvider(&LogoutProvider{})
app.RegisterCommandProvider(&LogoutProvider{})
}
func (me *LogoutProvider) GetTrigger() string {
return CMD_LOGOUT
}
func (me *LogoutProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *LogoutProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_LOGOUT,
AutoComplete: true,
@@ -33,7 +34,7 @@ func (me *LogoutProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comm
}
}
func (me *LogoutProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *LogoutProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
// Actual logout is handled client side.
return &model.CommandResponse{GotoLocation: "/login"}
}

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -16,14 +17,14 @@ const (
)
func init() {
RegisterCommandProvider(&MeProvider{})
app.RegisterCommandProvider(&MeProvider{})
}
func (me *MeProvider) GetTrigger() string {
return CMD_ME
}
func (me *MeProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *MeProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_ME,
AutoComplete: true,
@@ -33,7 +34,7 @@ func (me *MeProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command
}
}
func (me *MeProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *MeProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL,
Type: model.POST_ME,

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"testing"
@@ -12,8 +12,8 @@ import (
)
func TestMeProviderDoCommand(t *testing.T) {
th := Setup(t)
defer th.TearDown()
th := setup(t)
defer th.tearDown()
mp := MeProvider{}

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

@@ -1,13 +1,14 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"errors"
"strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
@@ -21,14 +22,14 @@ const (
)
func init() {
RegisterCommandProvider(&msgProvider{})
app.RegisterCommandProvider(&msgProvider{})
}
func (me *msgProvider) GetTrigger() string {
return CMD_MSG
}
func (me *msgProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *msgProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_MSG,
AutoComplete: true,
@@ -38,7 +39,7 @@ func (me *msgProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command
}
}
func (me *msgProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *msgProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
splitMessage := strings.SplitN(message, " ", 2)
parsedMessage := ""

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"testing"
@@ -13,14 +13,14 @@ import (
)
func TestMsgProvider(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
team := th.CreateTeam()
th.LinkUserToTeam(th.BasicUser, team)
team := th.createTeam()
th.linkUserToTeam(th.BasicUser, team)
cmd := &msgProvider{}
th.RemovePermissionFromRole(model.PERMISSION_CREATE_DIRECT_CHANNEL.Id, model.SYSTEM_USER_ROLE_ID)
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{
@@ -34,7 +34,7 @@ func TestMsgProvider(t *testing.T) {
assert.Equal(t, "api.command_msg.permission.app_error", resp.Text)
assert.Equal(t, "", resp.GotoLocation)
th.AddPermissionToRole(model.PERMISSION_CREATE_DIRECT_CHANNEL.Id, model.SYSTEM_USER_ROLE_ID)
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{
@@ -59,12 +59,12 @@ func TestMsgProvider(t *testing.T) {
assert.Equal(t, "http://test.url/"+team.Name+"/channels/"+channelName, resp.GotoLocation)
// Check that a guest user cannot message a user who is not in a channel/team with him
guest := th.CreateGuest()
user := th.CreateUser()
guest := th.createGuest()
user := th.createUser()
th.LinkUserToTeam(user, team)
th.LinkUserToTeam(guest, th.BasicTeam)
th.AddUserToChannel(guest, th.BasicChannel)
th.linkUserToTeam(user, team)
th.linkUserToTeam(guest, th.BasicTeam)
th.addUserToChannel(guest, th.BasicChannel)
resp = cmd.DoCommand(th.App, &model.CommandArgs{
T: i18n.IdentityTfunc(),
@@ -77,8 +77,8 @@ func TestMsgProvider(t *testing.T) {
assert.Equal(t, "", resp.GotoLocation)
// Check that a guest user can message a user who is in a channel/team with him
th.LinkUserToTeam(user, th.BasicTeam)
th.AddUserToChannel(user, th.BasicChannel)
th.linkUserToTeam(user, th.BasicTeam)
th.addUserToChannel(user, th.BasicChannel)
resp = cmd.DoCommand(th.App, &model.CommandArgs{
T: i18n.IdentityTfunc(),

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

@@ -1,12 +1,13 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -18,14 +19,14 @@ const (
)
func init() {
RegisterCommandProvider(&MuteProvider{})
app.RegisterCommandProvider(&MuteProvider{})
}
func (me *MuteProvider) GetTrigger() string {
return CMD_MUTE
}
func (me *MuteProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *MuteProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_MUTE,
AutoComplete: true,
@@ -35,7 +36,7 @@ func (me *MuteProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comman
}
}
func (me *MuteProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *MuteProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
var channel *model.Channel
var noChannelErr *model.AppError
@@ -88,7 +89,7 @@ func (me *MuteProvider) DoCommand(a *App, args *model.CommandArgs, message strin
}
}
func publishChannelMemberEvt(a *App, channelMember *model.ChannelMember, userId string) {
func publishChannelMemberEvt(a *app.App, channelMember *model.ChannelMember, userId string) {
evt := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_MEMBER_UPDATED, "", "", userId, nil)
evt.Add("channelMember", channelMember.ToJson())
a.Publish(evt)

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"testing"
@@ -13,8 +13,8 @@ import (
)
func TestMuteCommandNoChannel(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
if testing.Short() {
t.SkipNow()
@@ -40,8 +40,8 @@ func TestMuteCommandNoChannel(t *testing.T) {
}
func TestMuteCommandNoArgs(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
channel1 := th.BasicChannel
channel1M, _ := th.App.GetChannelMember(channel1.Id, th.BasicUser.Id)
@@ -70,8 +70,8 @@ func TestMuteCommandNoArgs(t *testing.T) {
}
func TestMuteCommandSpecificChannel(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
if testing.Short() {
t.SkipNow()
@@ -115,8 +115,8 @@ func TestMuteCommandSpecificChannel(t *testing.T) {
}
func TestMuteCommandNotMember(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
if testing.Short() {
t.SkipNow()
@@ -143,8 +143,8 @@ func TestMuteCommandNotMember(t *testing.T) {
}
func TestMuteCommandNotChannel(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
if testing.Short() {
t.SkipNow()
@@ -164,8 +164,8 @@ func TestMuteCommandNotChannel(t *testing.T) {
}
func TestMuteCommandDMChannel(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
if testing.Short() {
t.SkipNow()

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -16,14 +17,14 @@ const (
)
func init() {
RegisterCommandProvider(&OfflineProvider{})
app.RegisterCommandProvider(&OfflineProvider{})
}
func (me *OfflineProvider) GetTrigger() string {
return CMD_OFFLINE
}
func (me *OfflineProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *OfflineProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_OFFLINE,
AutoComplete: true,
@@ -32,7 +33,7 @@ func (me *OfflineProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Com
}
}
func (me *OfflineProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *OfflineProvider) DoCommand(a *app.App, 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")}

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -16,14 +17,14 @@ const (
)
func init() {
RegisterCommandProvider(&OnlineProvider{})
app.RegisterCommandProvider(&OnlineProvider{})
}
func (me *OnlineProvider) GetTrigger() string {
return CMD_ONLINE
}
func (me *OnlineProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *OnlineProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_ONLINE,
AutoComplete: true,
@@ -32,7 +33,7 @@ func (me *OnlineProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comm
}
}
func (me *OnlineProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *OnlineProvider) DoCommand(a *app.App, 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")}

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -17,14 +18,14 @@ const (
)
func init() {
RegisterCommandProvider(&OpenProvider{})
app.RegisterCommandProvider(&OpenProvider{})
}
func (open *OpenProvider) GetTrigger() string {
return CMD_OPEN
}
func (open *OpenProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (open *OpenProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
cmd := open.JoinProvider.GetCommand(a, T)
cmd.Trigger = CMD_OPEN
cmd.DisplayName = T("api.command_open.name")

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

@@ -1,13 +1,14 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"strings"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -24,8 +25,8 @@ const (
)
func init() {
RegisterCommandProvider(&RemoveProvider{})
RegisterCommandProvider(&KickProvider{})
app.RegisterCommandProvider(&RemoveProvider{})
app.RegisterCommandProvider(&KickProvider{})
}
func (me *RemoveProvider) GetTrigger() string {
@@ -36,7 +37,7 @@ func (me *KickProvider) GetTrigger() string {
return CMD_KICK
}
func (me *RemoveProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *RemoveProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_REMOVE,
AutoComplete: true,
@@ -46,7 +47,7 @@ func (me *RemoveProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comm
}
}
func (me *KickProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *KickProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_KICK,
AutoComplete: true,
@@ -56,15 +57,15 @@ func (me *KickProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comman
}
}
func (me *RemoveProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *RemoveProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
return doCommand(a, args, message)
}
func (me *KickProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *KickProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
return doCommand(a, args, message)
}
func doCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func doCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
channel, err := a.GetChannel(args.ChannelId)
if err != nil {
return &model.CommandResponse{

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"testing"
@@ -12,8 +12,8 @@ import (
)
func TestRemoveProviderDoCommand(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
rp := RemoveProvider{}
@@ -33,7 +33,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
CreatorId: th.BasicUser.Id,
}, false)
targetUser := th.CreateUser()
targetUser := th.createUser()
th.App.AddUserToTeam(th.BasicTeam.Id, targetUser.Id, targetUser.Id)
th.App.AddUserToChannel(targetUser, publicChannel)
th.App.AddUserToChannel(targetUser, privateChannel)
@@ -81,10 +81,10 @@ func TestRemoveProviderDoCommand(t *testing.T) {
assert.Equal(t, "", actual)
// Try a group channel
user1 := th.CreateUser()
user2 := th.CreateUser()
user1 := th.createUser()
user2 := th.createUser()
groupChannel := th.CreateGroupChannel(user1, user2)
groupChannel := th.createGroupChannel(user1, user2)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -96,7 +96,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
assert.Equal(t, "api.command_remove.direct_group.app_error", actual)
// Try a direct channel *with* being a member.
directChannel := th.CreateDmChannel(user1)
directChannel := th.createDmChannel(user1)
args = &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
@@ -108,7 +108,7 @@ func TestRemoveProviderDoCommand(t *testing.T) {
assert.Equal(t, "api.command_remove.direct_group.app_error", actual)
// Try a public channel with a deactivated user.
deactivatedUser := th.CreateUser()
deactivatedUser := th.createUser()
th.App.AddUserToTeam(th.BasicTeam.Id, deactivatedUser.Id, deactivatedUser.Id)
th.App.AddUserToChannel(deactivatedUser, publicChannel)
th.App.UpdateActive(deactivatedUser, false)

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -16,14 +17,14 @@ const (
)
func init() {
RegisterCommandProvider(&SearchProvider{})
app.RegisterCommandProvider(&SearchProvider{})
}
func (search *SearchProvider) GetTrigger() string {
return CMD_SEARCH
}
func (search *SearchProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (search *SearchProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_SEARCH,
AutoComplete: true,
@@ -33,7 +34,7 @@ func (search *SearchProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.
}
}
func (search *SearchProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (search *SearchProvider) DoCommand(a *app.App, 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"),

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -16,14 +17,14 @@ const (
)
func init() {
RegisterCommandProvider(&SettingsProvider{})
app.RegisterCommandProvider(&SettingsProvider{})
}
func (settings *SettingsProvider) GetTrigger() string {
return CMD_SETTINGS
}
func (settings *SettingsProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (settings *SettingsProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_SETTINGS,
AutoComplete: true,
@@ -33,7 +34,7 @@ func (settings *SettingsProvider) GetCommand(a *App, T goi18n.TranslateFunc) *mo
}
}
func (settings *SettingsProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (settings *SettingsProvider) DoCommand(a *app.App, 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"),

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -16,14 +17,14 @@ const (
)
func init() {
RegisterCommandProvider(&ShortcutsProvider{})
app.RegisterCommandProvider(&ShortcutsProvider{})
}
func (me *ShortcutsProvider) GetTrigger() string {
return CMD_SHORTCUTS
}
func (me *ShortcutsProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *ShortcutsProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_SHORTCUTS,
AutoComplete: true,
@@ -33,7 +34,7 @@ func (me *ShortcutsProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.C
}
}
func (me *ShortcutsProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *ShortcutsProvider) DoCommand(a *app.App, 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"),

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

@@ -1,10 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
)
@@ -16,14 +17,14 @@ const (
)
func init() {
RegisterCommandProvider(&ShrugProvider{})
app.RegisterCommandProvider(&ShrugProvider{})
}
func (me *ShrugProvider) GetTrigger() string {
return CMD_SHRUG
}
func (me *ShrugProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
func (me *ShrugProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_SHRUG,
AutoComplete: true,
@@ -33,7 +34,7 @@ func (me *ShrugProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Comma
}
}
func (me *ShrugProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
func (me *ShrugProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
rmsg := `¯\\\_(ツ)\_/¯`
if len(message) > 0 {
rmsg = message + " " + rmsg

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

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
package slashcommands
import (
"fmt"
@@ -20,12 +20,24 @@ import (
"github.com/mattermost/mattermost-server/v5/services/httpservice"
)
func TestMoveCommand(t *testing.T) {
th := Setup(t)
defer th.TearDown()
type InfiniteReader struct {
Prefix string
}
sourceTeam := th.CreateTeam()
targetTeam := th.CreateTeam()
func (r InfiniteReader) Read(p []byte) (n int, err error) {
for i := range p {
p[i] = 'a'
}
return len(p), nil
}
func TestMoveCommand(t *testing.T) {
th := setup(t)
defer th.tearDown()
sourceTeam := th.createTeam()
targetTeam := th.createTeam()
command := &model.Command{}
command.CreatorId = model.NewId()
@@ -56,8 +68,8 @@ func TestMoveCommand(t *testing.T) {
}
func TestCreateCommandPost(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
post := &model.Post{
ChannelId: th.BasicChannel.Id,
@@ -76,8 +88,8 @@ func TestCreateCommandPost(t *testing.T) {
}
func TestExecuteCommand(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
t.Run("valid tests with different whitespace characters", func(t *testing.T) {
TestCases := map[string]string{
@@ -124,8 +136,8 @@ func TestExecuteCommand(t *testing.T) {
}
func TestHandleCommandResponsePost(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
command := &model.Command{}
args := &model.CommandArgs{
@@ -168,7 +180,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
// Channel id is specified by response, it should override the command args value.
channel := th.CreateChannel(th.BasicTeam)
resp.ChannelId = channel.Id
th.AddUserToChannel(th.BasicUser, channel)
th.addUserToChannel(th.BasicUser, channel)
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
assert.Nil(t, err)
@@ -251,7 +263,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
}
assert.Equal(t, "true", post.GetProp("from_webhook"))
channel = th.CreatePrivateChannel(th.BasicTeam)
channel = th.createPrivateChannel(th.BasicTeam)
resp.ChannelId = channel.Id
args.UserId = th.BasicUser2.Id
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
@@ -280,8 +292,8 @@ func TestHandleCommandResponsePost(t *testing.T) {
}
func TestHandleCommandResponse(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
command := &model.Command{}
@@ -338,8 +350,8 @@ func TestHandleCommandResponse(t *testing.T) {
}
func TestDoCommandRequest(t *testing.T) {
th := Setup(t)
defer th.TearDown()
th := setup(t)
defer th.tearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.AllowedUntrustedInternalConnections = model.NewString("127.0.0.1")
@@ -352,7 +364,7 @@ func TestDoCommandRequest(t *testing.T) {
}))
defer server.Close()
_, resp, err := th.App.doCommandRequest(&model.Command{URL: server.URL}, url.Values{})
_, resp, err := th.App.DoCommandRequest(&model.Command{URL: server.URL}, url.Values{})
require.Nil(t, err)
assert.NotNil(t, resp)
@@ -367,7 +379,7 @@ func TestDoCommandRequest(t *testing.T) {
}))
defer server.Close()
_, resp, err := th.App.doCommandRequest(&model.Command{URL: server.URL}, url.Values{})
_, resp, err := th.App.DoCommandRequest(&model.Command{URL: server.URL}, url.Values{})
require.Nil(t, err)
assert.NotNil(t, resp)
@@ -382,7 +394,7 @@ func TestDoCommandRequest(t *testing.T) {
// Since we limit the length of the response, no error will be returned and resp.Text will be a finite string
_, resp, err := th.App.doCommandRequest(&model.Command{URL: server.URL}, url.Values{})
_, resp, err := th.App.DoCommandRequest(&model.Command{URL: server.URL}, url.Values{})
require.Nil(t, err)
require.NotNil(t, resp)
})
@@ -395,7 +407,7 @@ func TestDoCommandRequest(t *testing.T) {
}))
defer server.Close()
_, _, err := th.App.doCommandRequest(&model.Command{URL: server.URL}, url.Values{})
_, _, err := th.App.DoCommandRequest(&model.Command{URL: server.URL}, url.Values{})
require.NotNil(t, err)
require.Equal(t, "api.command.execute_command.failed.app_error", err.Id)
})
@@ -408,7 +420,7 @@ func TestDoCommandRequest(t *testing.T) {
}))
defer server.Close()
_, _, err := th.App.doCommandRequest(&model.Command{URL: server.URL}, url.Values{})
_, _, err := th.App.DoCommandRequest(&model.Command{URL: server.URL}, url.Values{})
require.NotNil(t, err)
require.Equal(t, "api.command.execute_command.failed.app_error", err.Id)
})
@@ -426,7 +438,7 @@ func TestDoCommandRequest(t *testing.T) {
th.App.HTTPService().(*httpservice.HTTPServiceImpl).RequestTimeout = httpservice.RequestTimeout
}()
_, _, err := th.App.doCommandRequest(&model.Command{URL: server.URL}, url.Values{})
_, _, err := th.App.DoCommandRequest(&model.Command{URL: server.URL}, url.Values{})
require.NotNil(t, err)
require.Equal(t, "api.command.execute_command.failed.app_error", err.Id)
close(done)
@@ -434,12 +446,12 @@ func TestDoCommandRequest(t *testing.T) {
}
func TestMentionsToTeamMembers(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
otherTeam := th.CreateTeam()
otherUser := th.CreateUser()
th.LinkUserToTeam(otherUser, otherTeam)
otherTeam := th.createTeam()
otherUser := th.createUser()
th.linkUserToTeam(otherUser, otherTeam)
fixture := []struct {
message string
@@ -514,17 +526,17 @@ func TestMentionsToTeamMembers(t *testing.T) {
}
for _, data := range fixture {
actualMap := th.App.mentionsToTeamMembers(data.message, data.inTeam)
actualMap := th.App.MentionsToTeamMembers(data.message, data.inTeam)
require.Equal(t, actualMap, data.expectedMap)
}
}
func TestMentionsToPublicChannels(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th := setup(t).initBasic()
defer th.tearDown()
otherPublicChannel := th.CreateChannel(th.BasicTeam)
privateChannel := th.CreatePrivateChannel(th.BasicTeam)
privateChannel := th.createPrivateChannel(th.BasicTeam)
fixture := []struct {
message string
@@ -599,7 +611,7 @@ func TestMentionsToPublicChannels(t *testing.T) {
}
for _, data := range fixture {
actualMap := th.App.mentionsToPublicChannels(data.message, data.inTeam)
actualMap := th.App.MentionsToPublicChannels(data.message, data.inTeam)
require.Equal(t, actualMap, data.expectedMap)
}
}

455
app/slashcommands/helper_test.go Обычный файл
Просмотреть файл

@@ -0,0 +1,455 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package slashcommands
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
"time"
"testing"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/config"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/store/localcachelayer"
"github.com/mattermost/mattermost-server/v5/utils"
)
type TestHelper struct {
App *app.App
Server *app.Server
BasicTeam *model.Team
BasicUser *model.User
BasicUser2 *model.User
BasicChannel *model.Channel
BasicPost *model.Post
SystemAdminUser *model.User
LogBuffer *bytes.Buffer
IncludeCacheLayer bool
tempWorkspace string
}
func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer bool, tb testing.TB, configSet func(*model.Config)) *TestHelper {
tempWorkspace, err := ioutil.TempDir("", "apptest")
if err != nil {
panic(err)
}
memoryStore, err := config.NewMemoryStoreWithOptions(&config.MemoryStoreOptions{IgnoreEnvironmentOverrides: true})
if err != nil {
panic("failed to initialize memory store: " + err.Error())
}
config := memoryStore.Get()
if configSet != nil {
configSet(config)
}
*config.PluginSettings.Directory = filepath.Join(tempWorkspace, "plugins")
*config.PluginSettings.ClientDirectory = filepath.Join(tempWorkspace, "webapp")
*config.LogSettings.EnableSentry = false // disable error reporting during tests
memoryStore.Set(config)
buffer := &bytes.Buffer{}
var options []app.Option
options = append(options, app.ConfigStore(memoryStore))
options = append(options, app.StoreOverride(dbStore))
options = append(options, app.SetLogger(mlog.NewTestingLogger(tb, buffer)))
s, err := app.NewServer(options...)
if err != nil {
panic(err)
}
if includeCacheLayer {
// Adds the cache layer to the test store
s.Store = localcachelayer.NewLocalCacheLayer(s.Store, s.Metrics, s.Cluster, s.CacheProvider)
}
th := &TestHelper{
App: app.New(app.ServerConnector(s)),
Server: s,
LogBuffer: buffer,
IncludeCacheLayer: includeCacheLayer,
}
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.RateLimitSettings.Enable = false })
prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
serverErr := th.Server.Start()
if serverErr != nil {
panic(serverErr)
}
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = prevListenAddress })
th.App.Srv().SearchEngine = mainHelper.SearchEngine
th.App.Srv().Store.MarkSystemRanUnitTests()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = true })
// Disable strict password requirements for test
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PasswordSettings.MinimumLength = 5
*cfg.PasswordSettings.Lowercase = false
*cfg.PasswordSettings.Uppercase = false
*cfg.PasswordSettings.Symbol = false
*cfg.PasswordSettings.Number = false
})
if enterprise {
th.App.Srv().SetLicense(model.NewTestLicense())
} else {
th.App.Srv().SetLicense(nil)
}
if th.tempWorkspace == "" {
th.tempWorkspace = tempWorkspace
}
th.App.InitServer()
return th
}
func setup(tb testing.TB) *TestHelper {
if testing.Short() {
tb.SkipNow()
}
dbStore := mainHelper.GetStore()
dbStore.DropAllTables()
dbStore.MarkSystemRanUnitTests()
return setupTestHelper(dbStore, false, true, tb, nil)
}
var initBasicOnce sync.Once
var userCache struct {
SystemAdminUser *model.User
BasicUser *model.User
BasicUser2 *model.User
}
func (me *TestHelper) initBasic() *TestHelper {
// create users once and cache them because password hashing is slow
initBasicOnce.Do(func() {
me.SystemAdminUser = me.createUser()
me.App.UpdateUserRoles(me.SystemAdminUser.Id, model.SYSTEM_USER_ROLE_ID+" "+model.SYSTEM_ADMIN_ROLE_ID, false)
me.SystemAdminUser, _ = me.App.GetUser(me.SystemAdminUser.Id)
userCache.SystemAdminUser = me.SystemAdminUser.DeepCopy()
me.BasicUser = me.createUser()
me.BasicUser, _ = me.App.GetUser(me.BasicUser.Id)
userCache.BasicUser = me.BasicUser.DeepCopy()
me.BasicUser2 = me.createUser()
me.BasicUser2, _ = me.App.GetUser(me.BasicUser2.Id)
userCache.BasicUser2 = me.BasicUser2.DeepCopy()
})
// restore cached users
me.SystemAdminUser = userCache.SystemAdminUser.DeepCopy()
me.BasicUser = userCache.BasicUser.DeepCopy()
me.BasicUser2 = userCache.BasicUser2.DeepCopy()
mainHelper.GetSQLSupplier().GetMaster().Insert(me.SystemAdminUser, me.BasicUser, me.BasicUser2)
me.BasicTeam = me.createTeam()
me.linkUserToTeam(me.BasicUser, me.BasicTeam)
me.linkUserToTeam(me.BasicUser2, me.BasicTeam)
me.BasicChannel = me.CreateChannel(me.BasicTeam)
me.BasicPost = me.createPost(me.BasicChannel)
return me
}
func (me *TestHelper) createTeam() *model.Team {
id := model.NewId()
team := &model.Team{
DisplayName: "dn_" + id,
Name: "name" + id,
Email: "success+" + id + "@simulator.amazonses.com",
Type: model.TEAM_OPEN,
}
utils.DisableDebugLogForTest()
var err *model.AppError
if team, err = me.App.CreateTeam(team); err != nil {
mlog.Error(err.Error())
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
return team
}
func (me *TestHelper) createUser() *model.User {
return me.createUserOrGuest(false)
}
func (me *TestHelper) createGuest() *model.User {
return me.createUserOrGuest(true)
}
func (me *TestHelper) createUserOrGuest(guest bool) *model.User {
id := model.NewId()
user := &model.User{
Email: "success+" + id + "@simulator.amazonses.com",
Username: "un_" + id,
Nickname: "nn_" + id,
Password: "Password1",
EmailVerified: true,
}
utils.DisableDebugLogForTest()
var err *model.AppError
if guest {
if user, err = me.App.CreateGuest(user); err != nil {
mlog.Error(err.Error())
time.Sleep(time.Second)
panic(err)
}
} else {
if user, err = me.App.CreateUser(user); err != nil {
mlog.Error(err.Error())
time.Sleep(time.Second)
panic(err)
}
}
utils.EnableDebugLogForTest()
return user
}
func (me *TestHelper) CreateChannel(team *model.Team) *model.Channel {
return me.createChannel(team, model.CHANNEL_OPEN)
}
func (me *TestHelper) createPrivateChannel(team *model.Team) *model.Channel {
return me.createChannel(team, model.CHANNEL_PRIVATE)
}
func (me *TestHelper) createChannel(team *model.Team, channelType string) *model.Channel {
id := model.NewId()
channel := &model.Channel{
DisplayName: "dn_" + id,
Name: "name_" + id,
Type: channelType,
TeamId: team.Id,
CreatorId: me.BasicUser.Id,
}
utils.DisableDebugLogForTest()
var err *model.AppError
if channel, err = me.App.CreateChannel(channel, true); err != nil {
mlog.Error(err.Error())
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
return channel
}
func (me *TestHelper) createChannelWithAnotherUser(team *model.Team, channelType, userId string) *model.Channel {
id := model.NewId()
channel := &model.Channel{
DisplayName: "dn_" + id,
Name: "name_" + id,
Type: channelType,
TeamId: team.Id,
CreatorId: userId,
}
utils.DisableDebugLogForTest()
var err *model.AppError
if channel, err = me.App.CreateChannel(channel, true); err != nil {
mlog.Error(err.Error())
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
return channel
}
func (me *TestHelper) createDmChannel(user *model.User) *model.Channel {
utils.DisableDebugLogForTest()
var err *model.AppError
var channel *model.Channel
if channel, err = me.App.GetOrCreateDirectChannel(me.BasicUser.Id, user.Id); err != nil {
mlog.Error(err.Error())
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
return channel
}
func (me *TestHelper) createGroupChannel(user1 *model.User, user2 *model.User) *model.Channel {
utils.DisableDebugLogForTest()
var err *model.AppError
var channel *model.Channel
if channel, err = me.App.CreateGroupChannel([]string{me.BasicUser.Id, user1.Id, user2.Id}, me.BasicUser.Id); err != nil {
mlog.Error(err.Error())
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
return channel
}
func (me *TestHelper) createPost(channel *model.Channel) *model.Post {
id := model.NewId()
post := &model.Post{
UserId: me.BasicUser.Id,
ChannelId: channel.Id,
Message: "message_" + id,
CreateAt: model.GetMillis() - 10000,
}
utils.DisableDebugLogForTest()
var err *model.AppError
if post, err = me.App.CreatePost(post, channel, false, true); err != nil {
mlog.Error(err.Error())
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
return post
}
func (me *TestHelper) linkUserToTeam(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest()
err := me.App.JoinUserToTeam(team, user, "")
if err != nil {
mlog.Error(err.Error())
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
}
func (me *TestHelper) addUserToChannel(user *model.User, channel *model.Channel) *model.ChannelMember {
utils.DisableDebugLogForTest()
member, err := me.App.AddUserToChannel(user, channel)
if err != nil {
mlog.Error(err.Error())
time.Sleep(time.Second)
panic(err)
}
utils.EnableDebugLogForTest()
return member
}
func (me *TestHelper) shutdownApp() {
done := make(chan bool)
go func() {
me.Server.Shutdown()
close(done)
}()
select {
case <-done:
case <-time.After(30 * time.Second):
// panic instead of fatal to terminate all tests in this package, otherwise the
// still running App could spuriously fail subsequent tests.
panic("failed to shutdown App within 30 seconds")
}
}
func (me *TestHelper) tearDown() {
if me.IncludeCacheLayer {
// Clean all the caches
me.App.Srv().InvalidateAllCaches()
}
me.shutdownApp()
if me.tempWorkspace != "" {
os.RemoveAll(me.tempWorkspace)
}
}
func (me *TestHelper) removePermissionFromRole(permission string, roleName string) {
utils.DisableDebugLogForTest()
role, err1 := me.App.GetRoleByName(roleName)
if err1 != nil {
utils.EnableDebugLogForTest()
panic(err1)
}
var newPermissions []string
for _, p := range role.Permissions {
if p != permission {
newPermissions = append(newPermissions, p)
}
}
if strings.Join(role.Permissions, " ") == strings.Join(newPermissions, " ") {
utils.EnableDebugLogForTest()
return
}
role.Permissions = newPermissions
_, err2 := me.App.UpdateRole(role)
if err2 != nil {
utils.EnableDebugLogForTest()
panic(err2)
}
utils.EnableDebugLogForTest()
}
func (me *TestHelper) addPermissionToRole(permission string, roleName string) {
utils.DisableDebugLogForTest()
role, err1 := me.App.GetRoleByName(roleName)
if err1 != nil {
utils.EnableDebugLogForTest()
panic(err1)
}
for _, existingPermission := range role.Permissions {
if existingPermission == permission {
utils.EnableDebugLogForTest()
return
}
}
role.Permissions = append(role.Permissions, permission)
_, err2 := me.App.UpdateRole(role)
if err2 != nil {
utils.EnableDebugLogForTest()
panic(err2)
}
utils.EnableDebugLogForTest()
}

24
app/slashcommands/main_test.go Обычный файл
Просмотреть файл

@@ -0,0 +1,24 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package slashcommands
import (
"testing"
"github.com/mattermost/mattermost-server/v5/testlib"
)
var mainHelper *testlib.MainHelper
func TestMain(m *testing.M) {
var options = testlib.HelperOptions{
EnableStore: true,
EnableResources: true,
}
mainHelper = testlib.NewMainHelperWithOptions(&options)
defer mainHelper.Close()
mainHelper.Main(m)
}

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

@@ -8,6 +8,9 @@ import (
"github.com/mattermost/mattermost-server/v5/cmd/mattermost/commands"
// Import and register app layer slash commands
_ "github.com/mattermost/mattermost-server/v5/app/slashcommands"
// Plugins
_ "github.com/mattermost/mattermost-server/v5/model/gitlab"

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

@@ -13,6 +13,7 @@ import (
"github.com/mattermost/mattermost-server/v5/api4"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/app/slashcommands"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils"
@@ -93,7 +94,7 @@ func manualTest(c *web.Context, w http.ResponseWriter, r *http.Request) {
user := &model.User{
Email: "success+" + model.NewId() + "simulator.amazonses.com",
Nickname: username[0],
Password: app.USER_PASSWORD}
Password: slashcommands.USER_PASSWORD}
user, resp := client.CreateUser(user)
if resp.Error != nil {
@@ -107,7 +108,7 @@ func manualTest(c *web.Context, w http.ResponseWriter, r *http.Request) {
userID = user.Id
// Login as user to generate auth token
_, resp = client.LoginById(user.Id, app.USER_PASSWORD)
_, resp = client.LoginById(user.Id, slashcommands.USER_PASSWORD)
if resp.Error != nil {
c.Err = resp.Error
return