MM-39058 - invite people to join team and channels (#19849)

* MM-39058-invite-to-team-from-add-channel

* fix tests by validating the memberInvite is not nil

* fix i18n texts

* fix lint problem

* fix translation lines

* fix the data structure

* modify api4-team_local file to match with the expected structure

* fix unit tests, fix translation tests

* remove go routine cause not necesary

* add unit test for invite to team and channel

* remove unnecessary validation

* allow both data structures, simple string array and object with memberInvite struct

* fix texts

* fix linter

* fix problems with graceful invites workflow

* handle error while parsing body

* fix unit tests

* take the address just once

* rename channels to channelIds

* fix unit tests

* add tests and fix local channels invite support

Co-authored-by: Pablo Velez Vidal <pablo.velez@mattermost.com>
Этот коммит содержится в:
Pablo Andrés Vélez Vidal
2022-04-08 12:20:44 -05:00
коммит произвёл GitHub
родитель 0e4b0b6939
Коммит 4b354685e9
16 изменённых файлов: 517 добавлений и 52 удалений

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

@@ -2638,6 +2638,30 @@ func (c *Client4) InviteGuestsToTeam(teamId string, userEmails []string, channel
// InviteUsersToTeam invite users by email to the team.
func (c *Client4) InviteUsersToTeamGracefully(teamId string, userEmails []string) ([]*EmailInviteWithError, *Response, error) {
r, err := c.DoAPIPost(c.teamRoute(teamId)+"/invite/email?graceful="+c.boolString(true), ArrayToJSON(userEmails))
if err != nil {
return nil, BuildResponse(r), err
}
defer closeBody(r)
var list []*EmailInviteWithError
if jsonErr := json.NewDecoder(r.Body).Decode(&list); jsonErr != nil {
return nil, nil, NewAppError("InviteUsersToTeamGracefully", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
}
return list, BuildResponse(r), nil
}
// InviteUsersToTeam invite users by email to the team.
func (c *Client4) InviteUsersToTeamAndChannelsGracefully(teamId string, userEmails []string, channelIds []string, message string) ([]*EmailInviteWithError, *Response, error) {
memberInvite := MemberInvite{
Emails: userEmails,
ChannelIds: channelIds,
Message: message,
}
buf, err := json.Marshal(memberInvite)
if err != nil {
return nil, nil, NewAppError("InviteMembersToTeamAndChannels", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
}
r, err := c.DoAPIPostBytes(c.teamRoute(teamId)+"/invite/email?graceful="+c.boolString(true), buf)
if err != nil {
return nil, BuildResponse(r), err
}