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
@@ -2290,6 +2290,136 @@ func TestInviteUsersToTeam(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestInviteGuestsToTeam(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
guest1 := th.GenerateTestEmail()
|
||||
guest2 := th.GenerateTestEmail()
|
||||
|
||||
emailList := []string{guest1, guest2}
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
mailservice.DeleteMailBox(guest1)
|
||||
mailservice.DeleteMailBox(guest2)
|
||||
|
||||
enableEmailInvitations := *th.App.Config().ServiceSettings.EnableEmailInvitations
|
||||
restrictCreationToDomains := th.App.Config().TeamSettings.RestrictCreationToDomains
|
||||
enableGuestAccounts := *th.App.Config().GuestAccountsSettings.Enable
|
||||
defer func() {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableEmailInvitations = &enableEmailInvitations })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.RestrictCreationToDomains = restrictCreationToDomains })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GuestAccountsSettings.Enable = &enableGuestAccounts })
|
||||
}()
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = false })
|
||||
_, resp := th.SystemAdminClient.InviteGuestsToTeam(th.BasicTeam.Id, emailList, []string{th.BasicChannel.Id}, "test-message")
|
||||
assert.NotNil(t, resp.Error, "Should be disabled")
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = true })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableEmailInvitations = false })
|
||||
_, resp = th.SystemAdminClient.InviteGuestsToTeam(th.BasicTeam.Id, emailList, []string{th.BasicChannel.Id}, "test-message")
|
||||
if resp.Error == nil {
|
||||
t.Fatal("Should be disabled")
|
||||
}
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableEmailInvitations = true })
|
||||
|
||||
th.App.SetLicense(nil)
|
||||
|
||||
_, resp = th.SystemAdminClient.InviteGuestsToTeam(th.BasicTeam.Id, emailList, []string{th.BasicChannel.Id}, "test-message")
|
||||
if resp.Error == nil {
|
||||
t.Fatal("Should be disabled")
|
||||
}
|
||||
|
||||
th.App.SetLicense(model.NewTestLicense(""))
|
||||
defer th.App.SetLicense(nil)
|
||||
|
||||
okMsg, resp := th.SystemAdminClient.InviteGuestsToTeam(th.BasicTeam.Id, emailList, []string{th.BasicChannel.Id}, "test-message")
|
||||
CheckNoError(t, resp)
|
||||
if !okMsg {
|
||||
t.Fatal("should return true")
|
||||
}
|
||||
|
||||
nameFormat := *th.App.Config().TeamSettings.TeammateNameDisplay
|
||||
expectedSubject := utils.T("api.templates.invite_guest_subject",
|
||||
map[string]interface{}{"SenderName": th.SystemAdminUser.GetDisplayName(nameFormat),
|
||||
"TeamDisplayName": th.BasicTeam.DisplayName,
|
||||
"SiteName": th.App.ClientConfig()["SiteName"]})
|
||||
|
||||
//Check if the email was send to the rigth email address
|
||||
for _, email := range emailList {
|
||||
var resultsMailbox mailservice.JSONMessageHeaderInbucket
|
||||
err := mailservice.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = mailservice.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[len(resultsMailbox)-1].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := mailservice.GetMessageFromMailbox(email, resultsMailbox[len(resultsMailbox)-1].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Log(expectedSubject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictCreationToDomains = "@global.com,@common.com" })
|
||||
|
||||
t.Run("restricted domains", func(t *testing.T) {
|
||||
err := th.App.InviteGuestsToChannels(th.BasicTeam.Id, &model.GuestsInvite{Emails: emailList, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id)
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("Adding users with non-restricted domains was allowed")
|
||||
}
|
||||
if err.Where != "InviteGuestsToChannels" || err.Id != "api.team.invite_members.invalid_email.app_error" {
|
||||
t.Log(err)
|
||||
t.Fatal("Got wrong error message!")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("override restricted domains", func(t *testing.T) {
|
||||
th.BasicTeam.AllowedDomains = "invalid.com,common.com"
|
||||
if _, err := th.App.UpdateTeam(th.BasicTeam); err == nil {
|
||||
t.Fatal("Should not update the team")
|
||||
}
|
||||
|
||||
th.BasicTeam.AllowedDomains = "common.com"
|
||||
if _, err := th.App.UpdateTeam(th.BasicTeam); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should update the team")
|
||||
}
|
||||
|
||||
if err := th.App.InviteGuestsToChannels(th.BasicTeam.Id, &model.GuestsInvite{Emails: []string{"test@global.com"}, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id); err == nil || err.Where != "InviteGuestsToChannels" {
|
||||
t.Log(err)
|
||||
t.Fatal("Per team restriction should take precedence over the global restriction")
|
||||
}
|
||||
|
||||
if err := th.App.InviteGuestsToChannels(th.BasicTeam.Id, &model.GuestsInvite{Emails: []string{"test@common.com"}, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Failed to invite user which was common between team and global domain restriction")
|
||||
}
|
||||
|
||||
if err := th.App.InviteGuestsToChannels(th.BasicTeam.Id, &model.GuestsInvite{Emails: []string{"test@invalid.com"}, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id); err == nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should not invite user")
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetTeamInviteInfo(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user