PLT-7025: Fix Slack Import API. (#6905)
Этот коммит содержится в:
коммит произвёл
Saturnino Abril
родитель
e975b84a12
Коммит
2bf64b54c2
@@ -5,7 +5,7 @@ package api4
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"encoding/base64"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -657,12 +657,12 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Disposition", "attachment; filename=MattermostImportLog.txt")
|
data := map[string]string{}
|
||||||
w.Header().Set("Content-Type", "application/octet-stream")
|
data["results"] = base64.StdEncoding.EncodeToString([]byte(log.Bytes()))
|
||||||
if c.Err != nil {
|
if c.Err != nil {
|
||||||
w.WriteHeader(c.Err.StatusCode)
|
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) {
|
func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/mattermost/platform/app"
|
"github.com/mattermost/platform/app"
|
||||||
"github.com/mattermost/platform/model"
|
"github.com/mattermost/platform/model"
|
||||||
"github.com/mattermost/platform/utils"
|
"github.com/mattermost/platform/utils"
|
||||||
|
"encoding/base64"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateTeam(t *testing.T) {
|
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)
|
fileResp, resp := th.SystemAdminClient.ImportTeam(data, binary.Size(data), "slack", "Fake_Team_Import.zip", th.BasicTeam.Id)
|
||||||
CheckNoError(t, resp)
|
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") {
|
if !strings.Contains(fileReturned, "darth.vader@stardeath.com") {
|
||||||
t.Log(fileReturned)
|
t.Log(fileReturned)
|
||||||
t.Fatal("failed to report the user was imported")
|
t.Fatal("failed to report the user was imported")
|
||||||
|
|||||||
@@ -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, _ := http.NewRequest("POST", c.ApiUrl+url, bytes.NewReader(data))
|
||||||
rq.Header.Set("Content-Type", contentType)
|
rq.Header.Set("Content-Type", contentType)
|
||||||
rq.Close = true
|
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)}
|
return nil, &Response{Error: NewAppError(url, "model.client.connecting.app_error", nil, err.Error(), 0)}
|
||||||
} else if rp.StatusCode >= 300 {
|
} else if rp.StatusCode >= 300 {
|
||||||
return nil, &Response{StatusCode: rp.StatusCode, Error: AppErrorFromJson(rp.Body)}
|
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 {
|
} else {
|
||||||
defer closeBody(rp)
|
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.
|
// 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{}
|
body := &bytes.Buffer{}
|
||||||
writer := multipart.NewWriter(body)
|
writer := multipart.NewWriter(body)
|
||||||
|
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ class TeamImportTab extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
onImportFailure(e, err, res) {
|
onImportFailure() {
|
||||||
this.setState({status: 'fail', link: 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(res.text)});
|
this.setState({status: 'fail'});
|
||||||
}
|
}
|
||||||
|
|
||||||
onImportSuccess(data, res) {
|
onImportSuccess(data) {
|
||||||
this.setState({status: 'done', link: 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(res.text)});
|
this.setState({status: 'done', link: 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(atob(data.results))});
|
||||||
}
|
}
|
||||||
|
|
||||||
doImportSlack(file) {
|
doImportSlack(file) {
|
||||||
|
|||||||
@@ -1107,7 +1107,7 @@ export function isDirectChannelForUser(otherUserId, channel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function importSlack(file, success, error) {
|
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() {
|
export function windowWidth() {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user