Merge branch 'master' of github.com:mattermost/mattermost-server into top-dms-clean
Этот коммит содержится в:
@@ -4,7 +4,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -14,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestBundleInfoForPath(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "mm-plugin-test")
|
||||
dir, err := os.MkdirTemp("", "mm-plugin-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
|
||||
@@ -156,7 +156,6 @@ type ChannelModeratedRolesPatch struct {
|
||||
// Paginate whether to paginate the results.
|
||||
// Page page requested, if results are paginated.
|
||||
// PerPage number of results per page, if paginated.
|
||||
//
|
||||
type ChannelSearchOpts struct {
|
||||
NotAssociatedToGroup string
|
||||
ExcludeDefaultChannels bool
|
||||
|
||||
1159
model/client4.go
1159
model/client4.go
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -6,7 +6,6 @@ package model
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/utils/jsonutils"
|
||||
@@ -36,7 +35,7 @@ func CommandResponseFromHTTPBody(contentType string, body io.Reader) (*CommandRe
|
||||
if strings.TrimSpace(strings.Split(contentType, ";")[0]) == "application/json" {
|
||||
return CommandResponseFromJSON(body)
|
||||
}
|
||||
if b, err := ioutil.ReadAll(body); err == nil {
|
||||
if b, err := io.ReadAll(body); err == nil {
|
||||
return CommandResponseFromPlainText(string(b)), nil
|
||||
}
|
||||
return nil, nil
|
||||
@@ -49,7 +48,7 @@ func CommandResponseFromPlainText(text string) *CommandResponse {
|
||||
}
|
||||
|
||||
func CommandResponseFromJSON(data io.Reader) (*CommandResponse, error) {
|
||||
b, err := ioutil.ReadAll(data)
|
||||
b, err := io.ReadAll(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"encoding/base64"
|
||||
_ "image/gif"
|
||||
_ "image/png"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -76,13 +76,13 @@ func TestFileInfoIsImage(t *testing.T) {
|
||||
func TestGetInfoForFile(t *testing.T) {
|
||||
fakeFile := make([]byte, 1000)
|
||||
|
||||
pngFile, err := ioutil.ReadFile("../tests/test.png")
|
||||
pngFile, err := os.ReadFile("../tests/test.png")
|
||||
require.NoError(t, err, "Failed to load test.png")
|
||||
|
||||
// base 64 encoded version of handtinywhite.gif from http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever
|
||||
gifFile, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=")
|
||||
|
||||
animatedGifFile, err := ioutil.ReadFile("../tests/testgif.gif")
|
||||
animatedGifFile, err := os.ReadFile("../tests/testgif.gif")
|
||||
require.NoError(t, err, "Failed to load testgif.gif")
|
||||
|
||||
var ttc = []struct {
|
||||
|
||||
@@ -6,7 +6,7 @@ package model
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -108,42 +108,41 @@ type PluginSettingsSchema struct {
|
||||
//
|
||||
// Example plugin.json:
|
||||
//
|
||||
//
|
||||
// {
|
||||
// "id": "com.mycompany.myplugin",
|
||||
// "name": "My Plugin",
|
||||
// "description": "This is my plugin",
|
||||
// "homepage_url": "https://example.com",
|
||||
// "support_url": "https://example.com/support",
|
||||
// "release_notes_url": "https://example.com/releases/v0.0.1",
|
||||
// "icon_path": "assets/logo.svg",
|
||||
// "version": "0.1.0",
|
||||
// "min_server_version": "5.6.0",
|
||||
// "server": {
|
||||
// "executables": {
|
||||
// "linux-amd64": "server/dist/plugin-linux-amd64",
|
||||
// "darwin-amd64": "server/dist/plugin-darwin-amd64",
|
||||
// "windows-amd64": "server/dist/plugin-windows-amd64.exe"
|
||||
// }
|
||||
// },
|
||||
// "webapp": {
|
||||
// "bundle_path": "webapp/dist/main.js"
|
||||
// },
|
||||
// "settings_schema": {
|
||||
// "header": "Some header text",
|
||||
// "footer": "Some footer text",
|
||||
// "settings": [{
|
||||
// "key": "someKey",
|
||||
// "display_name": "Enable Extra Feature",
|
||||
// "type": "bool",
|
||||
// "help_text": "When true, an extra feature will be enabled!",
|
||||
// "default": "false"
|
||||
// }]
|
||||
// },
|
||||
// "props": {
|
||||
// "someKey": "someData"
|
||||
// }
|
||||
// }
|
||||
// {
|
||||
// "id": "com.mycompany.myplugin",
|
||||
// "name": "My Plugin",
|
||||
// "description": "This is my plugin",
|
||||
// "homepage_url": "https://example.com",
|
||||
// "support_url": "https://example.com/support",
|
||||
// "release_notes_url": "https://example.com/releases/v0.0.1",
|
||||
// "icon_path": "assets/logo.svg",
|
||||
// "version": "0.1.0",
|
||||
// "min_server_version": "5.6.0",
|
||||
// "server": {
|
||||
// "executables": {
|
||||
// "linux-amd64": "server/dist/plugin-linux-amd64",
|
||||
// "darwin-amd64": "server/dist/plugin-darwin-amd64",
|
||||
// "windows-amd64": "server/dist/plugin-windows-amd64.exe"
|
||||
// }
|
||||
// },
|
||||
// "webapp": {
|
||||
// "bundle_path": "webapp/dist/main.js"
|
||||
// },
|
||||
// "settings_schema": {
|
||||
// "header": "Some header text",
|
||||
// "footer": "Some footer text",
|
||||
// "settings": [{
|
||||
// "key": "someKey",
|
||||
// "display_name": "Enable Extra Feature",
|
||||
// "type": "bool",
|
||||
// "help_text": "When true, an extra feature will be enabled!",
|
||||
// "default": "false"
|
||||
// }]
|
||||
// },
|
||||
// "props": {
|
||||
// "someKey": "someData"
|
||||
// }
|
||||
// }
|
||||
type Manifest struct {
|
||||
// The id is a globally unique identifier that represents your plugin. Ids must be at least
|
||||
// 3 characters, at most 190 characters and must match ^[a-zA-Z0-9-_\.]+$.
|
||||
@@ -426,7 +425,7 @@ func FindManifest(dir string) (manifest *Manifest, path string, err error) {
|
||||
}
|
||||
continue
|
||||
}
|
||||
b, ioerr := ioutil.ReadAll(f)
|
||||
b, ioerr := io.ReadAll(f)
|
||||
f.Close()
|
||||
if ioerr != nil {
|
||||
return nil, path, ioerr
|
||||
|
||||
@@ -5,7 +5,6 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -244,7 +243,7 @@ func TestFindManifest(t *testing.T) {
|
||||
{"plugin.yml", `id: FOO`, false, false},
|
||||
{"plugin.yml", "bar", true, false},
|
||||
} {
|
||||
dir, err := ioutil.TempDir("", "mm-plugin-test")
|
||||
dir, err := os.MkdirTemp("", "mm-plugin-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
@@ -396,7 +395,7 @@ settings_schema:
|
||||
|
||||
func TestFindManifest_FileErrors(t *testing.T) {
|
||||
for _, tc := range []string{"plugin.yaml", "plugin.json"} {
|
||||
dir, err := ioutil.TempDir("", "mm-plugin-test")
|
||||
dir, err := os.MkdirTemp("", "mm-plugin-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
@@ -417,7 +416,7 @@ func TestFindManifest_FolderPermission(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range []string{"plugin.yaml", "plugin.json"} {
|
||||
dir, err := ioutil.TempDir("", "mm-plugin-test")
|
||||
dir, err := os.MkdirTemp("", "mm-plugin-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -369,13 +369,13 @@ func TestPost_AttachmentsEqual(t *testing.T) {
|
||||
var markdownSample, markdownSampleWithRewrittenImageURLs string
|
||||
|
||||
func init() {
|
||||
bytes, err := ioutil.ReadFile("testdata/markdown-sample.md")
|
||||
bytes, err := os.ReadFile("testdata/markdown-sample.md")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
markdownSample = string(bytes)
|
||||
|
||||
bytes, err = ioutil.ReadFile("testdata/markdown-sample-with-rewritten-image-urls.md")
|
||||
bytes, err = os.ReadFile("testdata/markdown-sample-with-rewritten-image-urls.md")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -91,23 +91,21 @@ func (o *Preference) IsValid() *AppError {
|
||||
if o.Category == PreferenceCategoryTheme {
|
||||
var unused map[string]string
|
||||
if err := json.NewDecoder(strings.NewReader(o.Value)).Decode(&unused); err != nil {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.theme.app_error", nil, "value="+o.Value, http.StatusBadRequest)
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.theme.app_error", nil, "value="+o.Value, http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var preUpdateColorPattern = regexp.MustCompile(`^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$`)
|
||||
|
||||
func (o *Preference) PreUpdate() {
|
||||
if o.Category == PreferenceCategoryTheme {
|
||||
// decode the value of theme (a map of strings to string) and eliminate any invalid values
|
||||
var props map[string]string
|
||||
if err := json.NewDecoder(strings.NewReader(o.Value)).Decode(&props); err != nil {
|
||||
// just continue, the invalid preference value should get caught by IsValid before saving
|
||||
return
|
||||
}
|
||||
|
||||
colorPattern := regexp.MustCompile(`^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$`)
|
||||
// just continue, the invalid preference value should get caught by IsValid before saving
|
||||
json.NewDecoder(strings.NewReader(o.Value)).Decode(&props)
|
||||
|
||||
// blank out any invalid theme values
|
||||
for name, value := range props {
|
||||
@@ -115,7 +113,7 @@ func (o *Preference) PreUpdate() {
|
||||
continue
|
||||
}
|
||||
|
||||
if !colorPattern.MatchString(value) {
|
||||
if !preUpdateColorPattern.MatchString(value) {
|
||||
props[name] = "#ffffff"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ func AppErrorFromJSON(data io.Reader) *AppError {
|
||||
var er AppError
|
||||
err := decoder.Decode(&er)
|
||||
if err != nil {
|
||||
return NewAppError("AppErrorFromJSON", "model.utils.decode_json.app_error", nil, "body: "+str, http.StatusInternalServerError)
|
||||
return NewAppError("AppErrorFromJSON", "model.utils.decode_json.app_error", nil, "body: "+str, http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
return &er
|
||||
}
|
||||
@@ -401,23 +401,25 @@ func MapBoolToJSON(objmap map[string]bool) string {
|
||||
|
||||
// MapFromJSON will decode the key/value pair map
|
||||
func MapFromJSON(data io.Reader) map[string]string {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap map[string]string
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
|
||||
json.NewDecoder(data).Decode(&objmap)
|
||||
if objmap == nil {
|
||||
return make(map[string]string)
|
||||
}
|
||||
|
||||
return objmap
|
||||
}
|
||||
|
||||
// MapFromJSON will decode the key/value pair map
|
||||
func MapBoolFromJSON(data io.Reader) map[string]bool {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap map[string]bool
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
|
||||
json.NewDecoder(data).Decode(&objmap)
|
||||
if objmap == nil {
|
||||
return make(map[string]bool)
|
||||
}
|
||||
|
||||
return objmap
|
||||
}
|
||||
|
||||
@@ -427,12 +429,13 @@ func ArrayToJSON(objmap []string) string {
|
||||
}
|
||||
|
||||
func ArrayFromJSON(data io.Reader) []string {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap []string
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
|
||||
json.NewDecoder(data).Decode(&objmap)
|
||||
if objmap == nil {
|
||||
return make([]string, 0)
|
||||
}
|
||||
|
||||
return objmap
|
||||
}
|
||||
|
||||
@@ -459,12 +462,13 @@ func StringInterfaceToJSON(objmap map[string]any) string {
|
||||
}
|
||||
|
||||
func StringInterfaceFromJSON(data io.Reader) map[string]any {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap map[string]any
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
|
||||
json.NewDecoder(data).Decode(&objmap)
|
||||
if objmap == nil {
|
||||
return make(map[string]any)
|
||||
}
|
||||
|
||||
return objmap
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user