MM-20977 - Inviting multiple users with valid/allowed and inva… (#13779)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
682a1d5d15
Коммит
4b39d8487b
46
api4/team.go
46
api4/team.go
@@ -945,6 +945,8 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
graceful := r.URL.Query().Get("graceful") != ""
|
||||
|
||||
c.RequireTeamId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
@@ -967,16 +969,26 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := c.App.InviteNewUsersToTeam(emailList, c.Params.TeamId, c.App.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
if graceful {
|
||||
invitesWithError, err := c.App.InviteNewUsersToTeamGracefully(emailList, c.Params.TeamId, c.App.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
// in graceful mode we return both the succesful ones and the failed ones
|
||||
w.Write([]byte(model.EmailInviteWithErrorToJson(invitesWithError)))
|
||||
} else {
|
||||
err := c.App.InviteNewUsersToTeam(emailList, c.Params.TeamId, c.App.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
graceful := r.URL.Query().Get("graceful") != ""
|
||||
if c.App.License() == nil {
|
||||
c.Err = model.NewAppError("Api4.InviteGuestsToChannels", "api.team.invate_guests_to_channels.license.error", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
@@ -1002,14 +1014,22 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
err := c.App.InviteGuestsToChannels(c.Params.TeamId, guestsInvite, c.App.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
if graceful {
|
||||
invitesWithError, err := c.App.InviteGuestsToChannelsGracefully(c.Params.TeamId, guestsInvite, c.App.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
// in graceful mode we return both the succesful ones and the failed ones
|
||||
w.Write([]byte(model.EmailInviteWithErrorToJson(invitesWithError)))
|
||||
} else {
|
||||
err := c.App.InviteGuestsToChannels(c.Params.TeamId, guestsInvite, c.App.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func getInviteInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -2343,6 +2343,13 @@ func TestInviteUsersToTeam(t *testing.T) {
|
||||
|
||||
require.Equalf(t, err.Where, "InviteNewUsersToTeam", "%v, Got wrong error message!", err)
|
||||
require.Equalf(t, err.Id, "api.team.invite_members.invalid_email.app_error", "%v, Got wrong error message!", err)
|
||||
|
||||
res, err := th.App.InviteNewUsersToTeamGracefully(emailList, th.BasicTeam.Id, th.BasicUser.Id)
|
||||
|
||||
require.Nil(t, err)
|
||||
require.Len(t, res, 2)
|
||||
require.NotNil(t, res[0].Error)
|
||||
require.NotNil(t, res[1].Error)
|
||||
})
|
||||
|
||||
t.Run("override restricted domains", func(t *testing.T) {
|
||||
@@ -2363,6 +2370,12 @@ func TestInviteUsersToTeam(t *testing.T) {
|
||||
|
||||
err = th.App.InviteNewUsersToTeam([]string{"test@invalid.com"}, th.BasicTeam.Id, th.BasicUser.Id)
|
||||
require.NotNilf(t, err, "%v, Should not invite user", err)
|
||||
|
||||
res, err := th.App.InviteNewUsersToTeamGracefully([]string{"test@invalid.com", "test@common.com"}, th.BasicTeam.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, res, 2)
|
||||
require.NotNil(t, res[0].Error)
|
||||
require.Nil(t, res[1].Error)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2457,6 +2470,12 @@ func TestInviteGuestsToTeam(t *testing.T) {
|
||||
err := th.App.InviteGuestsToChannels(th.BasicTeam.Id, &model.GuestsInvite{Emails: []string{"guest1@invalid.com"}, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id)
|
||||
require.NotNil(t, err, "guest user invites should be affected by the guest domain restrictions")
|
||||
|
||||
res, err := th.App.InviteGuestsToChannelsGracefully(th.BasicTeam.Id, &model.GuestsInvite{Emails: []string{"guest1@invalid.com", "guest1@guest.com"}, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, res, 2)
|
||||
require.NotNil(t, res[0].Error)
|
||||
require.Nil(t, res[1].Error)
|
||||
|
||||
err = th.App.InviteGuestsToChannels(th.BasicTeam.Id, &model.GuestsInvite{Emails: []string{"guest1@guest.com"}, Channels: []string{th.BasicChannel.Id}, Message: "test message"}, th.BasicUser.Id)
|
||||
require.Nil(t, err, "whitelisted guest user email should be allowed by the guest domain restrictions")
|
||||
})
|
||||
|
||||
Ссылка в новой задаче
Block a user