* MM-14139: Creating permissions for invite/promote/demote guests (#10778)

* MM-14139: Creating permissions for invite/promote/demote guests

* Fixing tests

* Adding invite guest api endpoint (#10792)

* Adding invite guest api endpoint

* Adding i18n

* Adding some tests

* WIP

* Migrating Token.Extra info to bigger size (2048)

* Fixing tests

* Adding client function for invite guests

* Adding send guests invites tests

* Renaming file from guest to guest_invite

* Adding Promote/Demote users from/to guest endpoints (#10791)

* Adding Promote/Demote users from/to guest endpoints

* Adding i18n translations

* Adding the client functions

* Using getQueryBuilder function

* Addressing PR review comments

* Adding default channels to users on promte from guest (#10851)

* Adding default channels to users on promte from guest

* Addressing PR review comments

* Fixing merge problems

* Sending websockets events on promote/demote (#11403)

* Sending websockets events on promote/demote

* Fixing merge problems

* Fixing govet shadowing problem

* Fixing feature branch tests

* Avoiding leaking users data through websockets for guest accounts (#11489)

* Avoiding leaking users data through websockets for guest accounts

* Adding tests and fixing code error

* Fixing i18n

* Allow to enable/disable guests and other extra config settings (#11481)

* Allow to enable/disable guests and other extra config settings

* Fixing tests and moving license and config validation to api level

* Update api4/role_test.go

Co-Authored-By: George Goldberg <george@gberg.me>

* Update api4/role_test.go

Co-Authored-By: George Goldberg <george@gberg.me>

* Fixing typo

* fixing tests

* Managing correctly the guest channel leave behavior (#11578)

* MM-15134: Removing guests from teams or system on leave channels if needed

* WIP

* No deactivating the guest user when leave the last team

* Adding a couple of tests

* Fixing shadow variables

* Fixing tests

* fixing tests

* fixing shadow variables

* Adding guest counts for channel stats (#11646)

* Adding guest counts for channel stats

* Adding tests

* Fixing tests

* Fixing guest domain restrictions (#11660)

* Adding needed migration for the database

* Fixing migration
Этот коммит содержится в:
Jesús Espino
2019-07-22 22:13:39 +02:00
коммит произвёл GitHub
родитель fdde7c8287
Коммит fe8a0f6485
48 изменённых файлов: 2630 добавлений и 133 удалений

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

@@ -5,9 +5,9 @@ package app
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/model"
)
@@ -34,53 +34,114 @@ func TestLeaveProviderDoCommand(t *testing.T) {
CreatorId: th.BasicUser.Id,
}, false)
defaultChannel, err := th.App.GetChannelByName(model.DEFAULT_CHANNEL, th.BasicTeam.Id, false)
require.Nil(t, err)
guest := th.CreateGuest()
th.App.AddUserToTeam(th.BasicTeam.Id, th.BasicUser.Id, th.BasicUser.Id)
th.App.AddUserToChannel(th.BasicUser, publicChannel)
th.App.AddUserToChannel(th.BasicUser, privateChannel)
th.App.AddUserToTeam(th.BasicTeam.Id, guest.Id, guest.Id)
th.App.AddUserToChannel(guest, publicChannel)
th.App.AddUserToChannel(guest, defaultChannel)
args := &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
}
t.Run("Should error when no Channel ID in args", func(t *testing.T) {
args := &model.CommandArgs{
UserId: th.BasicUser.Id,
T: func(s string, args ...interface{}) string { return s },
}
actual := lp.DoCommand(th.App, args, "")
assert.Equal(t, "api.command_leave.fail.app_error", actual.Text)
assert.Equal(t, model.COMMAND_RESPONSE_TYPE_EPHEMERAL, actual.ResponseType)
})
// Should error when no Channel ID in args
actual := lp.DoCommand(th.App, args, "")
assert.Equal(t, "api.command_leave.fail.app_error", actual.Text)
assert.Equal(t, model.COMMAND_RESPONSE_TYPE_EPHEMERAL, actual.ResponseType)
t.Run("Should error when no Team ID in args", func(t *testing.T) {
args := &model.CommandArgs{
UserId: th.BasicUser.Id,
ChannelId: publicChannel.Id,
T: func(s string, args ...interface{}) string { return s },
}
actual := lp.DoCommand(th.App, args, "")
assert.Equal(t, "api.command_leave.fail.app_error", actual.Text)
assert.Equal(t, model.COMMAND_RESPONSE_TYPE_EPHEMERAL, actual.ResponseType)
})
// Should error when no Team ID in args
args.ChannelId = publicChannel.Id
actual = lp.DoCommand(th.App, args, "")
assert.Equal(t, "api.command_leave.fail.app_error", actual.Text)
assert.Equal(t, model.COMMAND_RESPONSE_TYPE_EPHEMERAL, actual.ResponseType)
t.Run("Leave a public channel", func(t *testing.T) {
args := &model.CommandArgs{
UserId: th.BasicUser.Id,
ChannelId: publicChannel.Id,
T: func(s string, args ...interface{}) string { return s },
TeamId: th.BasicTeam.Id,
SiteURL: "http://localhost:8065",
}
actual := lp.DoCommand(th.App, args, "")
assert.Equal(t, "", actual.Text)
assert.Equal(t, args.SiteURL+"/"+th.BasicTeam.Name+"/channels/"+model.DEFAULT_CHANNEL, actual.GotoLocation)
assert.Equal(t, "", actual.ResponseType)
// Leave a public channel
siteURL := "http://localhost:8065"
args.TeamId = th.BasicTeam.Id
args.SiteURL = siteURL
actual = lp.DoCommand(th.App, args, "")
assert.Equal(t, "", actual.Text)
assert.Equal(t, siteURL+"/"+th.BasicTeam.Name+"/channels/"+model.DEFAULT_CHANNEL, actual.GotoLocation)
assert.Equal(t, "", actual.ResponseType)
_, err = th.App.GetChannelMember(publicChannel.Id, th.BasicUser.Id)
assert.NotNil(t, err)
assert.NotNil(t, err.Id, "store.sql_channel.get_member.missing.app_error")
})
time.Sleep(100 * time.Millisecond)
t.Run("Leave a private channel", func(t *testing.T) {
args := &model.CommandArgs{
UserId: th.BasicUser.Id,
ChannelId: privateChannel.Id,
T: func(s string, args ...interface{}) string { return s },
TeamId: th.BasicTeam.Id,
SiteURL: "http://localhost:8065",
}
actual := lp.DoCommand(th.App, args, "")
assert.Equal(t, "", actual.Text)
})
member, err := th.App.GetChannelMember(publicChannel.Id, th.BasicUser.Id)
if member == nil {
t.Errorf("Expected member object, got nil")
}
t.Run("Should not leave a default channel", func(t *testing.T) {
args := &model.CommandArgs{
UserId: th.BasicUser.Id,
ChannelId: defaultChannel.Id,
T: func(s string, args ...interface{}) string { return s },
TeamId: th.BasicTeam.Id,
SiteURL: "http://localhost:8065",
}
actual := lp.DoCommand(th.App, args, "")
assert.Equal(t, "api.channel.leave.default.app_error", actual.Text)
})
if err != nil {
t.Errorf("Expected nil object, got %s", err)
}
t.Run("Should allow to leave a default channel if user is guest", func(t *testing.T) {
args := &model.CommandArgs{
UserId: guest.Id,
ChannelId: defaultChannel.Id,
T: func(s string, args ...interface{}) string { return s },
TeamId: th.BasicTeam.Id,
SiteURL: "http://localhost:8065",
}
actual := lp.DoCommand(th.App, args, "")
assert.Equal(t, "", actual.Text)
assert.Equal(t, args.SiteURL+"/"+th.BasicTeam.Name+"/channels/"+publicChannel.Name, actual.GotoLocation)
assert.Equal(t, "", actual.ResponseType)
// Leave a private channel
args.ChannelId = privateChannel.Id
actual = lp.DoCommand(th.App, args, "")
assert.Equal(t, "", actual.Text)
_, err = th.App.GetChannelMember(defaultChannel.Id, guest.Id)
assert.NotNil(t, err)
assert.NotNil(t, err.Id, "store.sql_channel.get_member.missing.app_error")
})
// Should not leave a default channel
defaultChannel, _ := th.App.GetChannelByName(model.DEFAULT_CHANNEL, th.BasicTeam.Id, false)
args.ChannelId = defaultChannel.Id
actual = lp.DoCommand(th.App, args, "")
assert.Equal(t, "api.channel.leave.default.app_error", actual.Text)
t.Run("Should redirect to the team if is the last channel", func(t *testing.T) {
args := &model.CommandArgs{
UserId: guest.Id,
ChannelId: publicChannel.Id,
T: func(s string, args ...interface{}) string { return s },
TeamId: th.BasicTeam.Id,
SiteURL: "http://localhost:8065",
}
actual := lp.DoCommand(th.App, args, "")
assert.Equal(t, "", actual.Text)
assert.Equal(t, args.SiteURL+"/", actual.GotoLocation)
assert.Equal(t, "", actual.ResponseType)
_, err = th.App.GetChannelMember(publicChannel.Id, guest.Id)
assert.NotNil(t, err)
assert.NotNil(t, err.Id, "store.sql_channel.get_member.missing.app_error")
})
}