snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
This commit is contained in:
46
server/channels/app/plugin_api_tests/basic_config.go
Normal file
46
server/channels/app/plugin_api_tests/basic_config.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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.Pointer:
|
||||
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,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
)
|
||||
|
||||
type TestPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func (p *TestPlugin) OnActivate() error {
|
||||
fmt.Println("activated")
|
||||
return nil
|
||||
}
|
||||
|
||||
// This acts like a template as the content of this file gets passed to
|
||||
// fmt.Sprintf to inject additional logic based on the test case.
|
||||
func (p *TestPlugin) ConfigurationWillBeSaved(newCfg *model.Config) (*model.Config, error) {
|
||||
%s
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&TestPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// 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/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
_, err = conn.Write([]byte("HTTP/1.1 200\n\nOK"))
|
||||
if err != nil {
|
||||
mlog.Error("Failed to write to connection", mlog.Err(err))
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = conn.Close()
|
||||
if err != nil {
|
||||
mlog.Error("Failed to close connection", mlog.Err(err))
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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,68 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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) {
|
||||
// Test API.LoadPluginConfiguration
|
||||
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"
|
||||
}
|
||||
|
||||
// Test API.GetPluginConfig
|
||||
pc := p.API.GetPluginConfig()
|
||||
if pc == nil {
|
||||
return nil, "GetPluginConfig returned nil"
|
||||
}
|
||||
if pc["mystringsetting"] != "str" {
|
||||
return nil, fmt.Sprintf("MyStringSetting has invalid value: %v", pc["mystringsetting"])
|
||||
}
|
||||
if pc["MyIntSetting"] != float64(32) {
|
||||
return nil, fmt.Sprintf("MyIntSetting has invalid value: %v", pc["MyIntSetting"])
|
||||
}
|
||||
if pc["myBoolsetting"] != true {
|
||||
return nil, fmt.Sprintf("MyBoolSetting has invalid value: %v", pc["myBoolsetting"])
|
||||
}
|
||||
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// 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/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
)
|
||||
|
||||
type Plugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func (p *Plugin) ServeMetrics(_ *plugin.Context, w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/subpath" {
|
||||
_, err := w.Write([]byte("METRICS SUBPATH"))
|
||||
if err != nil {
|
||||
mlog.Error("Failed to write response", mlog.Err(err))
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
_, err := w.Write([]byte("METRICS"))
|
||||
if err != nil {
|
||||
mlog.Error("Failed to write response", mlog.Err(err))
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&Plugin{})
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
)
|
||||
|
||||
type Plugin struct {
|
||||
plugin.MattermostPlugin
|
||||
addrCh chan string
|
||||
}
|
||||
|
||||
func (p *Plugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
return nil, <-p.addrCh
|
||||
}
|
||||
|
||||
func (p *Plugin) WebSocketMessageHasBeenPosted(connID, userID string, req *model.WebSocketRequest) {
|
||||
p.addrCh <- req.Data[model.WebSocketRemoteAddr].(string)
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&Plugin{
|
||||
addrCh: make(chan string, 1),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
)
|
||||
|
||||
type Plugin struct {
|
||||
plugin.MattermostPlugin
|
||||
sessionCh chan string
|
||||
}
|
||||
|
||||
func (p *Plugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
return nil, <-p.sessionCh
|
||||
}
|
||||
|
||||
func (p *Plugin) WebSocketMessageHasBeenPosted(connID, userID string, req *model.WebSocketRequest) {
|
||||
p.sessionCh <- req.Session.Id
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&Plugin{
|
||||
sessionCh: make(chan string, 1),
|
||||
})
|
||||
}
|
||||
138
server/channels/app/plugin_api_tests/test_bots_plugin/main.go
Normal file
138
server/channels/app/plugin_api_tests/test_bots_plugin/main.go
Normal file
@@ -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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/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"
|
||||
}
|
||||
69
server/channels/app/plugin_api_tests/test_db_driver/main.go
Normal file
69
server/channels/app/plugin_api_tests/test_db_driver/main.go
Normal file
@@ -0,0 +1,69 @@
|
||||
// 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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/public/shared/driver"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/plugin_api_tests"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/storetest"
|
||||
)
|
||||
|
||||
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) {
|
||||
rctx := request.TestContext(p.t)
|
||||
settings := p.API.GetUnsanitizedConfig().SqlSettings
|
||||
settings.Trace = new(false)
|
||||
store, err := sqlstore.New(settings, rctx.Logger(), nil, sqlstore.DisableMorphLogging())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
store.GetMaster().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, rctx, store, wrapper)
|
||||
storetest.TestUserStore(p.t, rctx, store, wrapper)
|
||||
storetest.TestTeamStore(p.t, rctx, store)
|
||||
storetest.TestChannelStore(p.t, rctx, store, wrapper)
|
||||
storetest.TestBotStore(p.t, rctx, store, wrapper)
|
||||
|
||||
store.GetMaster().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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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,44 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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,44 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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
Normal file
84
server/channels/app/plugin_api_tests/test_kv/main.go
Normal file
@@ -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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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 range model.KeyValueKeyMaxRunes {
|
||||
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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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{})
|
||||
}
|
||||
@@ -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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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,46 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/plugin_api_tests"
|
||||
"github.com/mattermost/mattermost/server/v8/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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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,70 @@
|
||||
// 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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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,99 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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) expectUserAuth(userID string, expectedUserAuth *model.UserAuth) error {
|
||||
user, err := p.API.GetUser(userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if user.AuthService != expectedUserAuth.AuthService {
|
||||
return fmt.Errorf("expected '%s' got '%s'", expectedUserAuth.AuthService, user.AuthService)
|
||||
}
|
||||
if user.AuthData == nil && expectedUserAuth.AuthData != nil {
|
||||
return fmt.Errorf("expected '%s' got nil", *expectedUserAuth.AuthData)
|
||||
} else if user.AuthData != nil && expectedUserAuth.AuthData == nil {
|
||||
return fmt.Errorf("expected nil got '%s'", *user.AuthData)
|
||||
} else if user.AuthData != nil && expectedUserAuth.AuthData != nil && *user.AuthData != *expectedUserAuth.AuthData {
|
||||
return fmt.Errorf("expected '%s' got '%s'", *expectedUserAuth.AuthData, *user.AuthData)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||
// BasicUser2 should remain unchanged throughout
|
||||
user, appErr := p.API.GetUser(p.configuration.BasicUser2Id)
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error()
|
||||
}
|
||||
expectedUser2Auth := &model.UserAuth{
|
||||
AuthService: user.AuthService,
|
||||
AuthData: user.AuthData,
|
||||
}
|
||||
|
||||
// Update BasicUser to SAML
|
||||
expectedUserAuth := &model.UserAuth{
|
||||
AuthService: model.UserAuthServiceSaml,
|
||||
AuthData: new("saml_auth_data"),
|
||||
}
|
||||
_, appErr = p.API.UpdateUserAuth(p.configuration.BasicUserID, expectedUserAuth)
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error()
|
||||
}
|
||||
|
||||
err := p.expectUserAuth(p.configuration.BasicUserID, expectedUserAuth)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
err = p.expectUserAuth(p.configuration.BasicUser2Id, expectedUser2Auth)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
|
||||
// Update BasicUser to LDAP
|
||||
expectedUserAuth = &model.UserAuth{
|
||||
AuthService: model.UserAuthServiceLdap,
|
||||
AuthData: new("ldap_auth_data"),
|
||||
}
|
||||
_, appErr = p.API.UpdateUserAuth(p.configuration.BasicUserID, expectedUserAuth)
|
||||
if appErr != nil {
|
||||
return nil, appErr.Error()
|
||||
}
|
||||
|
||||
err = p.expectUserAuth(p.configuration.BasicUserID, expectedUserAuth)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
err = p.expectUserAuth(p.configuration.BasicUser2Id, expectedUser2Auth)
|
||||
if err != nil {
|
||||
return nil, err.Error()
|
||||
}
|
||||
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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) {
|
||||
if p.API.HasPermissionTo(p.configuration.BasicUserID, model.PermissionManageSystem) {
|
||||
return nil, "basic user should not yet be a system admin"
|
||||
}
|
||||
|
||||
if _, appErr := p.API.UpdateUserRoles(p.configuration.BasicUserID, model.SystemAdminRoleId+" "+model.SystemUserRoleId); appErr != nil {
|
||||
return nil, fmt.Sprintf("failed to update user roles: %s", appErr)
|
||||
}
|
||||
|
||||
if !p.API.HasPermissionTo(p.configuration.BasicUserID, model.PermissionManageSystem) {
|
||||
return nil, "basic user should be a system admin"
|
||||
}
|
||||
|
||||
if _, appErr := p.API.UpdateUserRoles(p.configuration.BasicUserID, model.SystemUserRoleId); appErr != nil {
|
||||
return nil, fmt.Sprintf("failed to update user roles: %s", appErr)
|
||||
}
|
||||
|
||||
if p.API.HasPermissionTo(p.configuration.BasicUserID, model.PermissionManageSystem) {
|
||||
return nil, "basic user should no longer be a system admin"
|
||||
}
|
||||
|
||||
return nil, "OK"
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/v8/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{})
|
||||
}
|
||||
Reference in New Issue
Block a user