Guest accounts feature (#11428)
* 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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fdde7c8287
Коммит
fe8a0f6485
@@ -193,6 +193,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser, _ := th.App.CreateUser(&user)
|
||||
rguest := th.CreateGuest()
|
||||
|
||||
t.Run("invalid token", func(t *testing.T) {
|
||||
if _, err := th.App.AddUserToTeamByToken(ruser.Id, "123"); err == nil {
|
||||
@@ -217,7 +218,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
TOKEN_TYPE_TEAM_INVITATION,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
)
|
||||
token.CreateAt = model.GetMillis() - TEAM_INVITATION_EXPIRY_TIME - 1
|
||||
token.CreateAt = model.GetMillis() - INVITATION_EXPIRY_TIME - 1
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
if _, err := th.App.AddUserToTeamByToken(ruser.Id, token.Token); err == nil {
|
||||
@@ -261,6 +262,49 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
||||
}
|
||||
_, err := th.App.Srv.Store.Token().GetByToken(token.Token)
|
||||
require.NotNil(t, err, "The token must be deleted after be used")
|
||||
|
||||
members, err := th.App.GetChannelMembersForUser(th.BasicTeam.Id, ruser.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, *members, 2)
|
||||
})
|
||||
|
||||
t.Run("invalid add a guest using a regular invite", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TOKEN_TYPE_TEAM_INVITATION,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id}),
|
||||
)
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
_, err := th.App.AddUserToTeamByToken(rguest.Id, token.Token)
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
|
||||
t.Run("invalid add a regular user using a guest invite", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TOKEN_TYPE_GUEST_INVITATION,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
|
||||
)
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
_, err := th.App.AddUserToTeamByToken(ruser.Id, token.Token)
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
|
||||
t.Run("valid request from guest invite", func(t *testing.T) {
|
||||
token := model.NewToken(
|
||||
TOKEN_TYPE_GUEST_INVITATION,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "channels": th.BasicChannel.Id}),
|
||||
)
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
if _, err := th.App.AddUserToTeamByToken(rguest.Id, token.Token); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should add user to the team")
|
||||
}
|
||||
_, err := th.App.Srv.Store.Token().GetByToken(token.Token)
|
||||
require.NotNil(t, err, "The token must be deleted after be used")
|
||||
|
||||
members, err := th.App.GetChannelMembersForUser(th.BasicTeam.Id, rguest.Id)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, *members, 1)
|
||||
assert.Equal(t, (*members)[0].ChannelId, th.BasicChannel.Id)
|
||||
})
|
||||
|
||||
t.Run("group-constrained team", func(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user