PLT-7025: Fix Slack Import API. (#6905)

This commit is contained in:
George Goldberg
2017-07-12 22:13:25 +09:00
committed by Saturnino Abril
parent e975b84a12
commit 2bf64b54c2
5 changed files with 19 additions and 15 deletions
+4 -4
View File
@@ -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) {
+7 -1
View File
@@ -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")
+3 -5
View File
@@ -352,7 +352,7 @@ func (c *Client4) DoEmojiUploadFile(url string, data []byte, contentType string)
}
}
func (c *Client4) DoUploadImportTeam(url string, data []byte, contentType string) ([]byte, *Response) {
func (c *Client4) DoUploadImportTeam(url string, data []byte, contentType string) (map[string]string, *Response) {
rq, _ := http.NewRequest("POST", c.ApiUrl+url, bytes.NewReader(data))
rq.Header.Set("Content-Type", contentType)
rq.Close = true
@@ -365,11 +365,9 @@ func (c *Client4) DoUploadImportTeam(url string, data []byte, contentType string
return nil, &Response{Error: NewAppError(url, "model.client.connecting.app_error", nil, err.Error(), 0)}
} else if rp.StatusCode >= 300 {
return nil, &Response{StatusCode: rp.StatusCode, Error: AppErrorFromJson(rp.Body)}
} else if data, err := ioutil.ReadAll(rp.Body); err != nil {
return nil, &Response{StatusCode: rp.StatusCode, Error: NewAppError("UploadImportTeam", "model.client.read_file.app_error", nil, err.Error(), rp.StatusCode)}
} else {
defer closeBody(rp)
return data, BuildResponse(rp)
return MapFromJson(rp.Body), BuildResponse(rp)
}
}
@@ -1210,7 +1208,7 @@ func (c *Client4) GetTeamUnread(teamId, userId string) (*TeamUnread, *Response)
}
// ImportTeam will import an exported team from other app into a existing team.
func (c *Client4) ImportTeam(data []byte, filesize int, importFrom, filename, teamId string) ([]byte, *Response) {
func (c *Client4) ImportTeam(data []byte, filesize int, importFrom, filename, teamId string) (map[string]string, *Response) {
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
+4 -4
View File
@@ -29,12 +29,12 @@ class TeamImportTab extends React.Component {
};
}
onImportFailure(e, err, res) {
this.setState({status: 'fail', link: 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(res.text)});
onImportFailure() {
this.setState({status: 'fail'});
}
onImportSuccess(data, res) {
this.setState({status: 'done', link: 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(res.text)});
onImportSuccess(data) {
this.setState({status: 'done', link: 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(atob(data.results))});
}
doImportSlack(file) {
+1 -1
View File
@@ -1107,7 +1107,7 @@ export function isDirectChannelForUser(otherUserId, channel) {
}
export function importSlack(file, success, error) {
Client4.importTeam(file, 'slack').then(success).catch(error);
Client4.importTeam(TeamStore.getCurrent().id, file, 'slack').then(success).catch(error);
}
export function windowWidth() {