github.com/adacta-ru/mattermost-server/v6@v6.0.0/app/plugin_api_tests/test_search_teams_plugin/main.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package main 5 6 import ( 7 "fmt" 8 9 "github.com/adacta-ru/mattermost-server/v6/app/plugin_api_tests" 10 "github.com/adacta-ru/mattermost-server/v6/model" 11 "github.com/adacta-ru/mattermost-server/v6/plugin" 12 ) 13 14 type MyPlugin struct { 15 plugin.MattermostPlugin 16 configuration plugin_api_tests.BasicConfig 17 } 18 19 func (p *MyPlugin) OnConfigurationChange() error { 20 if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil { 21 return err 22 } 23 return nil 24 } 25 26 func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) { 27 teams, err := p.API.SearchTeams(p.configuration.BasicTeamName) 28 if err != nil { 29 return nil, "search failed: " + err.Message 30 } 31 if len(teams) != 1 { 32 return nil, fmt.Sprintf("search failed, wrong number of teams: %v", len(teams)) 33 } 34 35 teams, err = p.API.SearchTeams(p.configuration.BasicTeamDisplayName) 36 if err != nil { 37 return nil, "search failed: " + err.Message 38 } 39 if len(teams) != 1 { 40 return nil, fmt.Sprintf("search failed, wrong number of teams: %v", len(teams)) 41 } 42 43 teams, err = p.API.SearchTeams(p.configuration.BasicTeamName[:3]) 44 45 if err != nil { 46 return nil, "search failed: " + err.Message 47 } 48 if len(teams) != 1 { 49 return nil, fmt.Sprintf("search failed, wrong number of teams: %v", len(teams)) 50 } 51 52 teams, err = p.API.SearchTeams("not found") 53 if err != nil { 54 return nil, "search failed: " + err.Message 55 } 56 if len(teams) != 0 { 57 return nil, fmt.Sprintf("search failed, wrong number of teams: %v", len(teams)) 58 } 59 return nil, "OK" 60 } 61 62 func main() { 63 plugin.ClientMain(&MyPlugin{}) 64 }