MM-61032: Add default_team_id to accept invite flow (#28841)
* add default_team_id to accept invite api * add team selector to accept invite flow UI * e2e * lint/i18n
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5a923e0b94
Коммит
fcded9559c
@@ -464,6 +464,16 @@ func remoteClusterAcceptInvite(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
if rcAcceptInvite.DefaultTeamId == "" {
|
||||
c.SetInvalidParam("remoteCluster.default_team_id")
|
||||
return
|
||||
}
|
||||
|
||||
if _, teamErr := c.App.GetTeam(rcAcceptInvite.DefaultTeamId); teamErr != nil {
|
||||
c.SetInvalidParamWithErr("remoteCluster.default_team_id", teamErr)
|
||||
return
|
||||
}
|
||||
|
||||
audit.AddEventParameter(auditRec, "name", rcAcceptInvite.Name)
|
||||
audit.AddEventParameter(auditRec, "display_name", rcAcceptInvite.DisplayName)
|
||||
|
||||
@@ -485,7 +495,7 @@ func remoteClusterAcceptInvite(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
rc, aErr := rcs.AcceptInvitation(invite, rcAcceptInvite.Name, rcAcceptInvite.DisplayName, c.AppContext.Session().UserId, url)
|
||||
rc, aErr := rcs.AcceptInvitation(invite, rcAcceptInvite.Name, rcAcceptInvite.DisplayName, c.AppContext.Session().UserId, url, rcAcceptInvite.DefaultTeamId)
|
||||
if aErr != nil {
|
||||
c.Err = model.NewAppError("remoteClusterAcceptInvite", "api.remote_cluster.accept_invitation_error", nil, "", http.StatusInternalServerError).Wrap(aErr)
|
||||
if appErr, ok := aErr.(*model.AppError); ok {
|
||||
|
||||
@@ -295,9 +295,10 @@ func TestCreateRemoteCluster(t *testing.T) {
|
||||
|
||||
func TestRemoteClusterAcceptinvite(t *testing.T) {
|
||||
rcAcceptInvite := &model.RemoteClusterAcceptInvite{
|
||||
Name: "remotecluster",
|
||||
Invite: "myinvitecode",
|
||||
Password: "mysupersecret",
|
||||
Name: "remotecluster",
|
||||
Invite: "myinvitecode",
|
||||
Password: "mysupersecret",
|
||||
DefaultTeamId: "",
|
||||
}
|
||||
|
||||
t.Run("Should not work if the remote cluster service is not enabled", func(t *testing.T) {
|
||||
@@ -313,6 +314,8 @@ func TestRemoteClusterAcceptinvite(t *testing.T) {
|
||||
th := setupForSharedChannels(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
rcAcceptInvite.DefaultTeamId = th.BasicTeam.Id
|
||||
|
||||
remoteId := model.NewId()
|
||||
invite := &model.RemoteClusterInvite{
|
||||
RemoteId: remoteId,
|
||||
@@ -335,7 +338,7 @@ func TestRemoteClusterAcceptinvite(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SiteURL = "http://localhost:8065" })
|
||||
|
||||
t.Run("should fail if the parameters are not valid", func(t *testing.T) {
|
||||
t.Run("should fail if the name parameter is not valid", func(t *testing.T) {
|
||||
rcAcceptInvite.Name = ""
|
||||
defer func() { rcAcceptInvite.Name = "remotecluster" }()
|
||||
|
||||
@@ -345,6 +348,26 @@ func TestRemoteClusterAcceptinvite(t *testing.T) {
|
||||
require.Empty(t, rc)
|
||||
})
|
||||
|
||||
t.Run("should fail if the default team parameter is empty", func(t *testing.T) {
|
||||
rcAcceptInvite.DefaultTeamId = ""
|
||||
defer func() { rcAcceptInvite.DefaultTeamId = th.BasicTeam.Id }()
|
||||
|
||||
rc, resp, err := th.SystemAdminClient.RemoteClusterAcceptInvite(context.Background(), rcAcceptInvite)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
require.Error(t, err)
|
||||
require.Empty(t, rc)
|
||||
})
|
||||
|
||||
t.Run("should fail if the default team provided doesn't exist", func(t *testing.T) {
|
||||
rcAcceptInvite.DefaultTeamId = model.NewId()
|
||||
defer func() { rcAcceptInvite.DefaultTeamId = th.BasicTeam.Id }()
|
||||
|
||||
rc, resp, err := th.SystemAdminClient.RemoteClusterAcceptInvite(context.Background(), rcAcceptInvite)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
require.Error(t, err)
|
||||
require.Empty(t, rc)
|
||||
})
|
||||
|
||||
t.Run("should fail with the correct status code if the invite returns an app error", func(t *testing.T) {
|
||||
rcAcceptInvite.Invite = "malformedinvite"
|
||||
// reset the invite after
|
||||
|
||||
@@ -190,7 +190,7 @@ func (rp *RemoteProvider) doAccept(a *app.App, args *model.CommandArgs, margs ma
|
||||
return responsef(args.T("api.command_remote.site_url_not_set"))
|
||||
}
|
||||
|
||||
rc, err := rcs.AcceptInvitation(invite, name, displayname, args.UserId, url)
|
||||
rc, err := rcs.AcceptInvitation(invite, name, displayname, args.UserId, url, "")
|
||||
if err != nil {
|
||||
return responsef(args.T("api.command_remote.accept_invitation.error", map[string]any{"Error": err.Error()}))
|
||||
}
|
||||
|
||||
@@ -12,15 +12,16 @@ import (
|
||||
)
|
||||
|
||||
// AcceptInvitation is called when accepting an invitation to connect with a remote cluster.
|
||||
func (rcs *Service) AcceptInvitation(invite *model.RemoteClusterInvite, name string, displayName, creatorId string, siteURL string) (*model.RemoteCluster, error) {
|
||||
func (rcs *Service) AcceptInvitation(invite *model.RemoteClusterInvite, name string, displayName string, creatorId string, siteURL string, defaultTeamId string) (*model.RemoteCluster, error) {
|
||||
rc := &model.RemoteCluster{
|
||||
RemoteId: invite.RemoteId,
|
||||
Name: name,
|
||||
DisplayName: displayName,
|
||||
Token: model.NewId(),
|
||||
RemoteToken: invite.Token,
|
||||
SiteURL: invite.SiteURL,
|
||||
CreatorId: creatorId,
|
||||
RemoteId: invite.RemoteId,
|
||||
Name: name,
|
||||
DisplayName: displayName,
|
||||
DefaultTeamId: defaultTeamId,
|
||||
Token: model.NewId(),
|
||||
RemoteToken: invite.Token,
|
||||
SiteURL: invite.SiteURL,
|
||||
CreatorId: creatorId,
|
||||
}
|
||||
|
||||
rcSaved, err := rcs.server.GetStore().RemoteCluster().Save(rc)
|
||||
|
||||
@@ -68,7 +68,7 @@ type RemoteClusterServiceIFace interface {
|
||||
SendMsg(ctx context.Context, msg model.RemoteClusterMsg, rc *model.RemoteCluster, f SendMsgResultFunc) error
|
||||
SendFile(ctx context.Context, us *model.UploadSession, fi *model.FileInfo, rc *model.RemoteCluster, rp ReaderProvider, f SendFileResultFunc) error
|
||||
SendProfileImage(ctx context.Context, userID string, rc *model.RemoteCluster, provider ProfileImageProvider, f SendProfileImageResultFunc) error
|
||||
AcceptInvitation(invite *model.RemoteClusterInvite, name string, displayName string, creatorId string, siteURL string) (*model.RemoteCluster, error)
|
||||
AcceptInvitation(invite *model.RemoteClusterInvite, name string, displayName string, creatorId string, siteURL string, defaultTeamId string) (*model.RemoteCluster, error)
|
||||
ReceiveIncomingMsg(rc *model.RemoteCluster, msg model.RemoteClusterMsg) Response
|
||||
ReceiveInviteConfirmation(invite model.RemoteClusterInvite) (*model.RemoteCluster, error)
|
||||
PingNow(rc *model.RemoteCluster)
|
||||
|
||||
@@ -462,10 +462,11 @@ func (rci *RemoteClusterInvite) Decrypt(encrypted []byte, password string) error
|
||||
}
|
||||
|
||||
type RemoteClusterAcceptInvite struct {
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Invite string `json:"invite"`
|
||||
Password string `json:"password"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
DefaultTeamId string `json:"default_team_id"`
|
||||
Invite string `json:"invite"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// RemoteClusterQueryFilter provides filter criteria for RemoteClusterStore.GetAll
|
||||
|
||||
Ссылка в новой задаче
Block a user