From 2bf64b54c236945727a2d93afb57b1665d1daa7a Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Wed, 12 Jul 2017 14:13:25 +0100 Subject: PLT-7025: Fix Slack Import API. (#6905) --- api4/team.go | 8 ++++---- api4/team_test.go | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'api4') diff --git a/api4/team.go b/api4/team.go index 1cbd89481..98a672d93 100644 --- a/api4/team.go +++ b/api4/team.go @@ -5,7 +5,7 @@ package api4 import ( "bytes" - "io" + "encoding/base64" "net/http" "strconv" @@ -657,12 +657,12 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) { } } - w.Header().Set("Content-Disposition", "attachment; filename=MattermostImportLog.txt") - w.Header().Set("Content-Type", "application/octet-stream") + data := map[string]string{} + data["results"] = base64.StdEncoding.EncodeToString([]byte(log.Bytes())) if c.Err != nil { w.WriteHeader(c.Err.StatusCode) } - io.Copy(w, bytes.NewReader(log.Bytes())) + w.Write([]byte(model.MapToJson(data))) } func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) { diff --git a/api4/team_test.go b/api4/team_test.go index b517f67fe..440b2feb2 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -15,6 +15,7 @@ import ( "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" + "encoding/base64" ) func TestCreateTeam(t *testing.T) { @@ -1345,7 +1346,12 @@ func TestImportTeam(t *testing.T) { fileResp, resp := th.SystemAdminClient.ImportTeam(data, binary.Size(data), "slack", "Fake_Team_Import.zip", th.BasicTeam.Id) CheckNoError(t, resp) - fileReturned := fmt.Sprintf("%s", fileResp) + fileData, err := base64.StdEncoding.DecodeString(fileResp["results"]) + if err != nil { + t.Fatal("failed to decode base64 results data") + } + + fileReturned := fmt.Sprintf("%s", fileData) if !strings.Contains(fileReturned, "darth.vader@stardeath.com") { t.Log(fileReturned) t.Fatal("failed to report the user was imported") -- cgit v1.2.3-1-g7c22