Mono repo -> Master (#22553)
Combines the following repositories into one: https://github.com/mattermost/mattermost-server https://github.com/mattermost/mattermost-webapp https://github.com/mattermost/focalboard https://github.com/mattermost/mattermost-plugin-playbooks
Этот коммит содержится в:
47
server/channels/app/plugin_api_tests/basic_config.go
Обычный файл
47
server/channels/app/plugin_api_tests/basic_config.go
Обычный файл
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package plugin_api_tests
|
||||
|
||||
import "reflect"
|
||||
|
||||
type BasicConfig struct {
|
||||
BasicChannelID string
|
||||
BasicChannelName string
|
||||
BasicPostID string
|
||||
BasicPostMessage string
|
||||
BasicTeamDisplayName string
|
||||
BasicTeamID string
|
||||
BasicTeamName string
|
||||
BasicUser2Email string
|
||||
BasicUser2Id string
|
||||
BasicUserEmail string
|
||||
BasicUserID string
|
||||
}
|
||||
|
||||
func IsEmpty(object any) bool {
|
||||
|
||||
// get nil case out of the way
|
||||
if object == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
objValue := reflect.ValueOf(object)
|
||||
|
||||
switch objValue.Kind() {
|
||||
// collection types are empty when they have no element
|
||||
case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice:
|
||||
return objValue.Len() == 0
|
||||
// pointers are empty if nil or if the value they point to is empty
|
||||
case reflect.Ptr:
|
||||
if objValue.IsNil() {
|
||||
return true
|
||||
}
|
||||
deref := objValue.Elem().Interface()
|
||||
return IsEmpty(deref)
|
||||
// for all other types, compare against the zero value
|
||||
default:
|
||||
zero := reflect.Zero(objValue.Type())
|
||||
return reflect.DeepEqual(object, zero.Interface())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
)
|
||||
|
||||
type Plugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func (p *Plugin) ServeHTTP(_ *plugin.Context, w http.ResponseWriter, _ *http.Request) {
|
||||
hj, ok := w.(http.Hijacker)
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
conn, brw, err := hj.Hijack()
|
||||
if conn == nil || brw == nil || err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
conn.Write([]byte("HTTP/1.1 200\n\nOK"))
|
||||
conn.Close()
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&Plugin{})
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
)
|
||||
|
||||
type Plugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func (p *Plugin) ServeHTTP(_ *plugin.Context, w http.ResponseWriter, r *http.Request) {
|
||||
upgrader := websocket.Upgrader{}
|
||||
|
||||
ws, err := upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer ws.Close()
|
||||
|
||||
for {
|
||||
mt, msg, err := ws.ReadMessage()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
var req model.WebSocketRequest
|
||||
err = json.Unmarshal(msg, &req)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
resp := model.NewWebSocketResponse("OK", req.Seq, map[string]any{"action": req.Action, "value": req.Data["value"]})
|
||||
respJSON, err := resp.ToJSON()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if err = ws.WriteMessage(mt, respJSON); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&Plugin{})
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type configuration struct {
|
||||
plugin_api_tests.BasicConfig
|
||||
MyStringSetting string
|
||||
MyIntSetting int
|
||||
MyBoolSetting bool
|
||||
}
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
|
||||
configuration configuration
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
if p.configuration.MyStringSetting != "override" {
|
||||
return nil, "MyStringSetting has invalid value"
|
||||
}
|
||||
if p.configuration.MyIntSetting != 35 {
|
||||
return nil, "MyIntSetting has invalid value"
|
||||
}
|
||||
if !p.configuration.MyBoolSetting {
|
||||
return nil, "MyBoolSetting has invalid value"
|
||||
}
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type configuration struct {
|
||||
plugin_api_tests.BasicConfig
|
||||
|
||||
MyStringSetting string
|
||||
MyIntSetting int
|
||||
MyBoolSetting bool
|
||||
}
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
|
||||
configuration configuration
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
if p.configuration.MyStringSetting != "str" {
|
||||
return nil, "MyStringSetting has invalid value"
|
||||
}
|
||||
if p.configuration.MyIntSetting != 32 {
|
||||
return nil, fmt.Sprintf("MyIntSetting has invalid value %v != %v", p.configuration.MyIntSetting, 32)
|
||||
}
|
||||
if !p.configuration.MyBoolSetting {
|
||||
return nil, "MyBoolSetting has invalid value"
|
||||
}
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
138
server/channels/app/plugin_api_tests/test_bots_plugin/main.go
Обычный файл
138
server/channels/app/plugin_api_tests/test_bots_plugin/main.go
Обычный файл
@@ -0,0 +1,138 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
createdBot, appErr := p.API.CreateBot(&model.Bot{
|
||||
Username: "bot",
|
||||
Description: "a plugin bot",
|
||||
})
|
||||
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error() + "failed to create bot"
|
||||
}
|
||||
|
||||
fetchedBot, appErr := p.API.GetBot(createdBot.UserId, false)
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error() + "failed to get bot"
|
||||
}
|
||||
if fetchedBot.Description != "a plugin bot" {
|
||||
return nil, "GetBot did not return the expected bot Description"
|
||||
}
|
||||
if fetchedBot.OwnerId != "test_bots_plugin" {
|
||||
return nil, "GetBot did not return the expected bot OwnerId"
|
||||
}
|
||||
|
||||
updatedDescription := createdBot.Description + ", updated"
|
||||
patchedBot, appErr := p.API.PatchBot(createdBot.UserId, &model.BotPatch{
|
||||
Description: &updatedDescription,
|
||||
})
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error() + "failed to patch bot"
|
||||
}
|
||||
|
||||
fetchedBot, appErr = p.API.GetBot(patchedBot.UserId, false)
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error() + "failed to get bot"
|
||||
}
|
||||
|
||||
if fetchedBot.UserId != patchedBot.UserId {
|
||||
return nil, "GetBot did not return the expected bot"
|
||||
}
|
||||
if fetchedBot.Description != "a plugin bot, updated" {
|
||||
return nil, "GetBot did not return the updated bot Description"
|
||||
}
|
||||
|
||||
fetchedBots, appErr := p.API.GetBots(&model.BotGetOptions{
|
||||
Page: 0,
|
||||
PerPage: 1,
|
||||
OwnerId: "",
|
||||
IncludeDeleted: false,
|
||||
})
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error() + "failed to get bots"
|
||||
}
|
||||
|
||||
if len(fetchedBots) != 1 {
|
||||
return nil, "GetBots did not return a single bot"
|
||||
}
|
||||
|
||||
if fetchedBot.UserId != fetchedBots[0].UserId {
|
||||
return nil, "GetBots did not return the expected bot"
|
||||
}
|
||||
if _, appErr = p.API.UpdateBotActive(fetchedBot.UserId, false); appErr != nil {
|
||||
return nil, appErr.Error() + "failed to disable bot"
|
||||
}
|
||||
|
||||
_, err := p.API.EnsureBotUser(&model.Bot{
|
||||
Username: "bot2",
|
||||
Description: "another plugin bot",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err.Error() + "failed to create bot"
|
||||
}
|
||||
|
||||
// TODO: investigate why the following code panics
|
||||
/*
|
||||
if fetchedBot, err = p.API.GetBot(patchedBot.UserId, false); err == nil {
|
||||
return nil, "expected not to find disabled bot"
|
||||
}
|
||||
if _, err = p.API.UpdateBotActive(fetchedBot.UserId, true); err != nil {
|
||||
return nil, err.Error() + "failed to disable bot"
|
||||
}
|
||||
if fetchedBot, err = p.API.GetBot(patchedBot.UserId, false); err != nil {
|
||||
return nil, err.Error() + "failed to get bot after enabling"
|
||||
}
|
||||
if fetchedBot.UserId != patchedBot.UserId {
|
||||
return nil, "GetBot did not return the expected bot after enabling"
|
||||
}
|
||||
if err = p.API.PermanentDeleteBot(patchedBot.UserId); err != nil {
|
||||
return nil, err.Error() + "failed to delete bot"
|
||||
}
|
||||
|
||||
if _, err = p.API.GetBot(patchedBot.UserId, false); err == nil {
|
||||
return nil, err.Error() + "found bot after permanently deleting"
|
||||
}
|
||||
createdBotWithOverriddenCreator, err := p.API.CreateBot(&model.Bot{
|
||||
Username: "bot",
|
||||
Description: "a plugin bot",
|
||||
OwnerId: "abc123",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err.Error() + "failed to create bot with overridden creator"
|
||||
}
|
||||
if fetchedBot, err = p.API.GetBot(createdBotWithOverriddenCreator.UserId, false); err != nil {
|
||||
return nil, err.Error() + "failed to get bot"
|
||||
}
|
||||
if fetchedBot.Description != "a plugin bot" {
|
||||
return nil, "GetBot did not return the expected bot Description"
|
||||
}
|
||||
if fetchedBot.OwnerId != "abc123" {
|
||||
return nil, "GetBot did not return the expected bot OwnerId"
|
||||
}
|
||||
*/
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
)
|
||||
|
||||
type PluginUsingLogAPI struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
type Foo struct {
|
||||
bar float64
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&PluginUsingLogAPI{})
|
||||
}
|
||||
|
||||
func (p *PluginUsingLogAPI) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
p.API.LogDebug("LogDebug", "one", 1, "two", "two", "foo", Foo{bar: 3.1416})
|
||||
p.API.LogInfo("LogInfo", "one", 1, "two", "two", "foo", Foo{bar: 3.1416})
|
||||
p.API.LogWarn("LogWarn", "one", 1, "two", "two", "foo", Foo{bar: 3.1416})
|
||||
p.API.LogError("LogError", "error", errors.WithStack(errors.New("boom!")))
|
||||
return nil, "OK"
|
||||
}
|
||||
64
server/channels/app/plugin_api_tests/test_db_driver/main.go
Обычный файл
64
server/channels/app/plugin_api_tests/test_db_driver/main.go
Обычный файл
@@ -0,0 +1,64 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/store/sqlstore"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/store/storetest"
|
||||
"github.com/mattermost/mattermost-server/v6/server/platform/shared/driver"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
config plugin_api_tests.BasicConfig
|
||||
t *testing.T
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.config); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
settings := p.API.GetUnsanitizedConfig().SqlSettings
|
||||
settings.Trace = model.NewBool(false)
|
||||
store := sqlstore.New(settings, nil)
|
||||
store.GetMasterX().Close()
|
||||
|
||||
for _, isMaster := range []bool{true, false} {
|
||||
handle := sql.OpenDB(driver.NewConnector(p.Driver, isMaster))
|
||||
store.SetMasterX(handle)
|
||||
|
||||
wrapper := sqlstore.NewStoreTestWrapper(store)
|
||||
// Testing with a handful of stores
|
||||
storetest.TestPostStore(p.t, store, wrapper)
|
||||
storetest.TestUserStore(p.t, store, wrapper)
|
||||
storetest.TestTeamStore(p.t, store)
|
||||
storetest.TestChannelStore(p.t, store, wrapper)
|
||||
storetest.TestBotStore(p.t, store, wrapper)
|
||||
|
||||
store.GetMasterX().Close()
|
||||
}
|
||||
|
||||
// Use the API to instantiate the driver
|
||||
// And then run the full suite of tests.
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
// TestDBAPI is a test function which actually runs a plugin. The objective
|
||||
// is to run the storetest suite from inside a plugin.
|
||||
//
|
||||
// The test runner compiles the test code to a binary, and runs it as a normal
|
||||
// binary. But under the hood, a test runs.
|
||||
func TestDBAPI(t *testing.T) {
|
||||
plugin.ClientMain(&MyPlugin{t: t})
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
bundlePath, err := p.API.GetBundlePath()
|
||||
if err != nil {
|
||||
return nil, err.Error() + "failed get bundle path"
|
||||
} else if bundlePathFromConfig, _ := filepath.Abs(filepath.Join(*p.API.GetConfig().PluginSettings.Directory, "test_get_bundle_path_plugin")); bundlePathFromConfig != bundlePath {
|
||||
return nil, fmt.Sprintf("Invalid bundle path returned: %v vs %v", bundlePathFromConfig, bundlePath)
|
||||
}
|
||||
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
|
||||
channels, err := p.API.GetChannelsForTeamForUser(p.configuration.BasicTeamID, p.configuration.BasicUserID, false)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
if len(channels) != 3 {
|
||||
return nil, "Returned invalid number of channels"
|
||||
}
|
||||
channels, err = p.API.GetChannelsForTeamForUser("invalidid", p.configuration.BasicUserID, false)
|
||||
if err == nil {
|
||||
return nil, "Expected to get an error while retrieving channels for invalid id"
|
||||
}
|
||||
if len(channels) != 0 {
|
||||
return nil, "Returned invalid number of channels"
|
||||
}
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
dm1, err := p.API.GetDirectChannel(p.configuration.BasicUserID, p.configuration.BasicUser2Id)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
if plugin_api_tests.IsEmpty(dm1) {
|
||||
return nil, "dm1 is empty"
|
||||
}
|
||||
|
||||
dm2, err := p.API.GetDirectChannel(p.configuration.BasicUserID, p.configuration.BasicUserID)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
if plugin_api_tests.IsEmpty(dm2) {
|
||||
return nil, "dm2 is empty"
|
||||
}
|
||||
|
||||
dm3, err := p.API.GetDirectChannel(p.configuration.BasicUserID, model.NewId())
|
||||
if err == nil {
|
||||
return nil, "Expected to get error while fetching incorrect channel"
|
||||
}
|
||||
if !plugin_api_tests.IsEmpty(dm3) {
|
||||
return nil, "dm3 is NOT empty"
|
||||
}
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
status, err := p.API.GetPluginStatus("test_get_plugin_status_plugin")
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
|
||||
if status.State != model.PluginStateRunning {
|
||||
return nil, "State is not running"
|
||||
}
|
||||
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
|
||||
// check existing user first
|
||||
data, err := p.API.GetProfileImage(p.configuration.BasicUserID)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
if plugin_api_tests.IsEmpty(data) {
|
||||
return nil, "GetProfileImage return empty"
|
||||
}
|
||||
|
||||
// then unknown user
|
||||
data, err = p.API.GetProfileImage(model.NewId())
|
||||
if err == nil || data != nil {
|
||||
return nil, "GetProfileImage should've returned an error"
|
||||
}
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
84
server/channels/app/plugin_api_tests/test_kv/main.go
Обычный файл
84
server/channels/app/plugin_api_tests/test_kv/main.go
Обычный файл
@@ -0,0 +1,84 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
data := []byte("some data")
|
||||
|
||||
appErr := p.API.KVSet("some_key", data)
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error()
|
||||
}
|
||||
|
||||
rData, appErr := p.API.KVGet("some_key")
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error()
|
||||
}
|
||||
if !bytes.Equal(data, rData) {
|
||||
return nil, fmt.Sprintf("Data not equal, expected: %s, got: %s", string(data), string(rData))
|
||||
}
|
||||
|
||||
data = []byte("some other data")
|
||||
|
||||
var longKey string
|
||||
for i := 0; i < model.KeyValueKeyMaxRunes; i++ {
|
||||
longKey += "k"
|
||||
}
|
||||
|
||||
appErr = p.API.KVSet(longKey, data)
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error()
|
||||
}
|
||||
|
||||
rData, appErr = p.API.KVGet(longKey)
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error()
|
||||
}
|
||||
|
||||
if !bytes.Equal(data, rData) {
|
||||
return nil, fmt.Sprintf("Data not equal, expected: %s, got: %s", string(data), string(rData))
|
||||
}
|
||||
|
||||
longKey += "extra"
|
||||
|
||||
appErr = p.API.KVSet(longKey, data)
|
||||
if appErr == nil {
|
||||
return nil, "Should have gotten an error for a to long key"
|
||||
}
|
||||
|
||||
rData, appErr = p.API.KVGet(longKey)
|
||||
if appErr != nil {
|
||||
return nil, "Should have gotten an error for a to long key"
|
||||
}
|
||||
if rData != nil {
|
||||
return nil, "Returned data should have been nil"
|
||||
}
|
||||
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
channelMembers, err := p.API.GetChannelMembersForUser(p.configuration.BasicTeamID, p.configuration.BasicUserID, 0, 10)
|
||||
|
||||
if err != nil {
|
||||
return nil, err.Error() + "failed to get channel members"
|
||||
} else if len(channelMembers) != 3 {
|
||||
return nil, "Invalid number of channel members"
|
||||
} else if channelMembers[0].UserId != p.configuration.BasicUserID {
|
||||
return nil, "Invalid user id returned"
|
||||
}
|
||||
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
38
server/channels/app/plugin_api_tests/test_members_plugin/main.go
Обычный файл
38
server/channels/app/plugin_api_tests/test_members_plugin/main.go
Обычный файл
@@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
teamMembers, err := p.API.GetTeamMembersForUser(p.configuration.BasicUserID, 0, 10)
|
||||
if err != nil {
|
||||
return nil, err.Error() + "failed to get team members"
|
||||
} else if len(teamMembers) != 1 {
|
||||
return nil, "Invalid number of team members"
|
||||
} else if teamMembers[0].UserId != p.configuration.BasicUserID || teamMembers[0].TeamId != p.configuration.BasicTeamID {
|
||||
return nil, "Invalid user or team id returned"
|
||||
}
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
|
||||
channels, err := p.API.SearchChannels(p.configuration.BasicTeamID, p.configuration.BasicChannelName)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
if len(channels) != 1 {
|
||||
return nil, "Returned invalid number of channels"
|
||||
}
|
||||
|
||||
channels, err = p.API.SearchChannels("invalidid", p.configuration.BasicChannelName)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
if len(channels) != 0 {
|
||||
return nil, "Returned invalid number of channels"
|
||||
}
|
||||
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
teamID string
|
||||
params []*model.SearchParams
|
||||
expectedPostsLen int
|
||||
}{
|
||||
{
|
||||
"nil params",
|
||||
p.configuration.BasicTeamID,
|
||||
nil,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"empty params",
|
||||
p.configuration.BasicTeamID,
|
||||
[]*model.SearchParams{},
|
||||
0,
|
||||
},
|
||||
{
|
||||
"doesn't match any posts",
|
||||
p.configuration.BasicTeamID,
|
||||
model.ParseSearchParams("bad message", 0),
|
||||
0,
|
||||
},
|
||||
{
|
||||
"matched posts",
|
||||
p.configuration.BasicTeamID,
|
||||
model.ParseSearchParams(p.configuration.BasicPostMessage, 0),
|
||||
1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
posts, err := p.API.SearchPostsInTeam(testCase.teamID, testCase.params)
|
||||
if err != nil {
|
||||
return nil, fmt.Sprintf("%v: %v", testCase.description, err.Error())
|
||||
}
|
||||
if testCase.expectedPostsLen != len(posts) {
|
||||
return nil, fmt.Sprintf("%v: invalid number of posts: %v != %v", testCase.description, testCase.expectedPostsLen, len(posts))
|
||||
}
|
||||
}
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
teams, err := p.API.SearchTeams(p.configuration.BasicTeamName)
|
||||
if err != nil {
|
||||
return nil, "search failed: " + err.Message
|
||||
}
|
||||
if len(teams) != 1 {
|
||||
return nil, fmt.Sprintf("search failed, wrong number of teams: %v", len(teams))
|
||||
}
|
||||
|
||||
teams, err = p.API.SearchTeams(p.configuration.BasicTeamDisplayName)
|
||||
if err != nil {
|
||||
return nil, "search failed: " + err.Message
|
||||
}
|
||||
if len(teams) != 1 {
|
||||
return nil, fmt.Sprintf("search failed, wrong number of teams: %v", len(teams))
|
||||
}
|
||||
|
||||
teams, err = p.API.SearchTeams(p.configuration.BasicTeamName[:3])
|
||||
|
||||
if err != nil {
|
||||
return nil, "search failed: " + err.Message
|
||||
}
|
||||
if len(teams) != 1 {
|
||||
return nil, fmt.Sprintf("search failed, wrong number of teams: %v", len(teams))
|
||||
}
|
||||
|
||||
teams, err = p.API.SearchTeams("not found")
|
||||
if err != nil {
|
||||
return nil, "search failed: " + err.Message
|
||||
}
|
||||
if len(teams) != 0 {
|
||||
return nil, fmt.Sprintf("search failed, wrong number of teams: %v", len(teams))
|
||||
}
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
"github.com/mattermost/mattermost-server/v6/server/platform/shared/mail"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
to := p.configuration.BasicUserEmail
|
||||
subject := "testing plugin api sending email"
|
||||
body := "this is a test."
|
||||
|
||||
if err := p.API.SendMail(to, subject, body); err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
|
||||
// Check if we received the email
|
||||
var resultsMailbox mail.JSONMessageHeaderInbucket
|
||||
if errMail := mail.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = mail.GetMailBox(to)
|
||||
return err
|
||||
}); errMail != nil {
|
||||
return nil, errMail.Error()
|
||||
}
|
||||
if len(resultsMailbox) == 0 {
|
||||
return nil, fmt.Sprintf("No mailbox results. Should be %v", len(resultsMailbox))
|
||||
}
|
||||
if !strings.ContainsAny(resultsMailbox[len(resultsMailbox)-1].To[0], to) {
|
||||
return nil, "Result doesn't contain recipient"
|
||||
}
|
||||
|
||||
resultsEmail, err1 := mail.GetMessageFromMailbox(to, resultsMailbox[len(resultsMailbox)-1].ID)
|
||||
if err1 != nil {
|
||||
return nil, err1.Error()
|
||||
}
|
||||
if resultsEmail.Subject != subject {
|
||||
return nil, fmt.Sprintf("subject differs: %v vs %s", resultsEmail.Subject, subject)
|
||||
}
|
||||
if resultsEmail.Body.Text != body {
|
||||
return nil, fmt.Sprintf("body differs: %v vs %s", resultsEmail.Body.Text, body)
|
||||
}
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
firstExpiry := time.Now().Add(time.Minute)
|
||||
session := &model.Session{
|
||||
UserId: p.configuration.BasicUser2Id,
|
||||
ExpiresAt: model.GetMillisForTime(firstExpiry),
|
||||
}
|
||||
session, appErr := p.API.CreateSession(session)
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error()
|
||||
}
|
||||
|
||||
newExpiry := firstExpiry.Add(time.Minute)
|
||||
appErr = p.API.ExtendSessionExpiry(session.Id, model.GetMillisForTime(newExpiry))
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error()
|
||||
}
|
||||
|
||||
rSession, appErr := p.API.GetSession(session.Id)
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error()
|
||||
}
|
||||
if rSession.ExpiresAt != model.GetMillisForTime(firstExpiry.Add(time.Minute)) {
|
||||
return nil, fmt.Sprintf("ExpiresAt not equal, expected: %v, got: %v", model.GetMillisForTime(firstExpiry.Add(time.Minute)), rSession.ExpiresAt)
|
||||
}
|
||||
|
||||
appErr = p.API.RevokeSession(session.Id)
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error()
|
||||
}
|
||||
|
||||
rSession, appErr = p.API.GetSession(session.Id)
|
||||
if appErr == nil {
|
||||
return nil, "Session should not be found"
|
||||
}
|
||||
if rSession != nil {
|
||||
return nil, "Returned session should be nil"
|
||||
}
|
||||
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
|
||||
// Create an 128 x 128 image
|
||||
img := image.NewRGBA(image.Rect(0, 0, 128, 128))
|
||||
// Draw a red dot at (2, 3)
|
||||
img.Set(2, 3, color.RGBA{255, 0, 0, 255})
|
||||
buf := new(bytes.Buffer)
|
||||
if err := png.Encode(buf, img); err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
|
||||
dataBytes := buf.Bytes()
|
||||
|
||||
// Set the user profile image
|
||||
if err := p.API.SetProfileImage(p.configuration.BasicUserID, dataBytes); err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
|
||||
// Get the user profile image to check
|
||||
imageProfile, err := p.API.GetProfileImage(p.configuration.BasicUserID)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
if plugin_api_tests.IsEmpty(imageProfile) {
|
||||
return nil, "profile image is empty"
|
||||
}
|
||||
|
||||
colorful := color.NRGBA{255, 0, 0, 255}
|
||||
byteReader := bytes.NewReader(imageProfile)
|
||||
img2, _, err2 := image.Decode(byteReader)
|
||||
if err2 != nil {
|
||||
return nil, err2.Error()
|
||||
}
|
||||
if img2.At(2, 3) != colorful {
|
||||
return nil, fmt.Sprintf("color mismatch %v != %v", img2.At(2, 3), colorful)
|
||||
}
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
uid := p.configuration.BasicUserID
|
||||
if err := p.API.UpdateUserActive(uid, true); err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
|
||||
user, err := p.API.GetUser(uid)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
|
||||
if int64(0) != user.DeleteAt {
|
||||
return nil, "DeleteAt value is not 0"
|
||||
}
|
||||
|
||||
if err = p.API.UpdateUserActive(uid, false); err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
|
||||
user, err = p.API.GetUser(uid)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
if user == nil {
|
||||
return nil, "GetUser returned nil"
|
||||
}
|
||||
|
||||
if int64(0) == user.DeleteAt {
|
||||
return nil, "DeleteAt value is 0"
|
||||
}
|
||||
|
||||
if err = p.API.UpdateUserActive(uid, true); err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
|
||||
if err = p.API.UpdateUserActive(uid, true); err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
|
||||
user, err = p.API.GetUser(uid)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
|
||||
if int64(0) != user.DeleteAt {
|
||||
return nil, "DeleteAt value is not 0"
|
||||
}
|
||||
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||
"github.com/mattermost/mattermost-server/v6/server/channels/app/plugin_api_tests"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
configuration plugin_api_tests.BasicConfig
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnConfigurationChange() error {
|
||||
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
uid := p.configuration.BasicUserID
|
||||
|
||||
statuses := []string{model.StatusOnline, model.StatusAway, model.StatusDnd, model.StatusOffline}
|
||||
|
||||
for _, s := range statuses {
|
||||
status, err := p.API.UpdateUserStatus(uid, s)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
if status == nil {
|
||||
return nil, "Status was expected, got nil"
|
||||
}
|
||||
if s != status.Status {
|
||||
return nil, fmt.Sprintf("Invalid status returned: %v != %v", s, status.Status)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
status, err := p.API.UpdateUserStatus(uid, "notrealstatus")
|
||||
if err == nil {
|
||||
return nil, "Expected to get an error while updating invalid user status"
|
||||
}
|
||||
if status != nil {
|
||||
return nil, "Status was expected to be nil, got: " + status.Status
|
||||
}
|
||||
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
Ссылка в новой задаче
Block a user