mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-2
This commit is contained in:
@@ -14,8 +14,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
)
|
||||
|
||||
var UsedApiV3 *int32 = new(int32)
|
||||
@@ -210,7 +208,7 @@ func getCookie(name string, resp *http.Response) *http.Cookie {
|
||||
// Must is a convenience function used for testing.
|
||||
func (c *Client) Must(result *Result, err *AppError) *Result {
|
||||
if err != nil {
|
||||
l4g.Close()
|
||||
|
||||
time.Sleep(time.Second)
|
||||
panic(err)
|
||||
}
|
||||
@@ -221,7 +219,7 @@ func (c *Client) Must(result *Result, err *AppError) *Result {
|
||||
// MustGeneric is a convenience function used for testing.
|
||||
func (c *Client) MustGeneric(result interface{}, err *AppError) interface{} {
|
||||
if err != nil {
|
||||
l4g.Close()
|
||||
|
||||
time.Sleep(time.Second)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
116
model/client4.go
116
model/client4.go
@@ -1459,6 +1459,69 @@ func (c *Client4) GetTeamInviteInfo(inviteId string) (*Team, *Response) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetTeamIcon sets team icon of the team
|
||||
func (c *Client4) SetTeamIcon(teamId string, data []byte) (bool, *Response) {
|
||||
|
||||
body := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(body)
|
||||
|
||||
if part, err := writer.CreateFormFile("image", "teamIcon.png"); err != nil {
|
||||
return false, &Response{Error: NewAppError("SetTeamIcon", "model.client.set_team_icon.no_file.app_error", nil, err.Error(), http.StatusBadRequest)}
|
||||
} else if _, err = io.Copy(part, bytes.NewBuffer(data)); err != nil {
|
||||
return false, &Response{Error: NewAppError("SetTeamIcon", "model.client.set_team_icon.no_file.app_error", nil, err.Error(), http.StatusBadRequest)}
|
||||
}
|
||||
|
||||
if err := writer.Close(); err != nil {
|
||||
return false, &Response{Error: NewAppError("SetTeamIcon", "model.client.set_team_icon.writer.app_error", nil, err.Error(), http.StatusBadRequest)}
|
||||
}
|
||||
|
||||
rq, _ := http.NewRequest("POST", c.ApiUrl+c.GetTeamRoute(teamId)+"/image", bytes.NewReader(body.Bytes()))
|
||||
rq.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
rq.Close = true
|
||||
|
||||
if len(c.AuthToken) > 0 {
|
||||
rq.Header.Set(HEADER_AUTH, c.AuthType+" "+c.AuthToken)
|
||||
}
|
||||
|
||||
if rp, err := c.HttpClient.Do(rq); err != nil || rp == nil {
|
||||
// set to http.StatusForbidden(403)
|
||||
return false, &Response{StatusCode: http.StatusForbidden, Error: NewAppError(c.GetTeamRoute(teamId)+"/image", "model.client.connecting.app_error", nil, err.Error(), 403)}
|
||||
} else {
|
||||
defer closeBody(rp)
|
||||
|
||||
if rp.StatusCode >= 300 {
|
||||
return false, BuildErrorResponse(rp, AppErrorFromJson(rp.Body))
|
||||
} else {
|
||||
return CheckStatusOK(rp), BuildResponse(rp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetTeamIcon gets the team icon of the team
|
||||
func (c *Client4) GetTeamIcon(teamId, etag string) ([]byte, *Response) {
|
||||
if r, err := c.DoApiGet(c.GetTeamRoute(teamId)+"/image", etag); err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
|
||||
if data, err := ioutil.ReadAll(r.Body); err != nil {
|
||||
return nil, BuildErrorResponse(r, NewAppError("GetTeamIcon", "model.client.get_team_icon.app_error", nil, err.Error(), r.StatusCode))
|
||||
} else {
|
||||
return data, BuildResponse(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveTeamIcon updates LastTeamIconUpdate to 0 which indicates team icon is removed.
|
||||
func (c *Client4) RemoveTeamIcon(teamId string) (bool, *Response) {
|
||||
if r, err := c.DoApiDelete(c.GetTeamRoute(teamId) + "/image"); err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
// Channel Section
|
||||
|
||||
// CreateChannel creates a channel based on the provided channel struct.
|
||||
@@ -3442,56 +3505,3 @@ func (c *Client4) DeactivatePlugin(id string) (bool, *Response) {
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
// SetTeamIcon sets team icon of the team
|
||||
func (c *Client4) SetTeamIcon(teamId string, data []byte) (bool, *Response) {
|
||||
|
||||
body := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(body)
|
||||
|
||||
if part, err := writer.CreateFormFile("image", "teamIcon.png"); err != nil {
|
||||
return false, &Response{Error: NewAppError("SetTeamIcon", "model.client.set_team_icon.no_file.app_error", nil, err.Error(), http.StatusBadRequest)}
|
||||
} else if _, err = io.Copy(part, bytes.NewBuffer(data)); err != nil {
|
||||
return false, &Response{Error: NewAppError("SetTeamIcon", "model.client.set_team_icon.no_file.app_error", nil, err.Error(), http.StatusBadRequest)}
|
||||
}
|
||||
|
||||
if err := writer.Close(); err != nil {
|
||||
return false, &Response{Error: NewAppError("SetTeamIcon", "model.client.set_team_icon.writer.app_error", nil, err.Error(), http.StatusBadRequest)}
|
||||
}
|
||||
|
||||
rq, _ := http.NewRequest("POST", c.ApiUrl+c.GetTeamRoute(teamId)+"/image", bytes.NewReader(body.Bytes()))
|
||||
rq.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
rq.Close = true
|
||||
|
||||
if len(c.AuthToken) > 0 {
|
||||
rq.Header.Set(HEADER_AUTH, c.AuthType+" "+c.AuthToken)
|
||||
}
|
||||
|
||||
if rp, err := c.HttpClient.Do(rq); err != nil || rp == nil {
|
||||
// set to http.StatusForbidden(403)
|
||||
return false, &Response{StatusCode: http.StatusForbidden, Error: NewAppError(c.GetTeamRoute(teamId)+"/image", "model.client.connecting.app_error", nil, err.Error(), 403)}
|
||||
} else {
|
||||
defer closeBody(rp)
|
||||
|
||||
if rp.StatusCode >= 300 {
|
||||
return false, BuildErrorResponse(rp, AppErrorFromJson(rp.Body))
|
||||
} else {
|
||||
return CheckStatusOK(rp), BuildResponse(rp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetTeamIcon gets the team icon of the team
|
||||
func (c *Client4) GetTeamIcon(teamId, etag string) ([]byte, *Response) {
|
||||
if r, err := c.DoApiGet(c.GetTeamRoute(teamId)+"/image", etag); err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
|
||||
if data, err := ioutil.ReadAll(r.Body); err != nil {
|
||||
return nil, BuildErrorResponse(r, NewAppError("GetTeamIcon", "model.client.get_team_icon.app_error", nil, err.Error(), r.StatusCode))
|
||||
} else {
|
||||
return data, BuildResponse(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,9 +585,10 @@ func (s *SqlSettings) SetDefaults() {
|
||||
type LogSettings struct {
|
||||
EnableConsole bool
|
||||
ConsoleLevel string
|
||||
ConsoleJson *bool
|
||||
EnableFile bool
|
||||
FileLevel string
|
||||
FileFormat string
|
||||
FileJson *bool
|
||||
FileLocation string
|
||||
EnableWebhookDebugging bool
|
||||
EnableDiagnostics *bool
|
||||
@@ -597,6 +598,14 @@ func (s *LogSettings) SetDefaults() {
|
||||
if s.EnableDiagnostics == nil {
|
||||
s.EnableDiagnostics = NewBool(true)
|
||||
}
|
||||
|
||||
if s.ConsoleJson == nil {
|
||||
s.ConsoleJson = NewBool(true)
|
||||
}
|
||||
|
||||
if s.FileJson == nil {
|
||||
s.FileJson = NewBool(true)
|
||||
}
|
||||
}
|
||||
|
||||
type PasswordSettings struct {
|
||||
|
||||
Reference in New Issue
Block a user