MM-26057 - Add CreateCommand plugin API (#14916)

Automatic Merge
Этот коммит содержится в:
Christopher Poile
2020-07-31 11:40:15 -04:00
коммит произвёл GitHub
родитель 61cc7a8680
Коммит c5c6a5ce53
11 изменённых файлов: 763 добавлений и 18 удалений

Просмотреть файл

@@ -972,6 +972,65 @@ type API interface {
// @tag User
// Minimum server version: 5.26
PublishUserTyping(userId, channelId, parentId string) *model.AppError
// CreateCommand creates a server-owned slash command that is not handled by the plugin
// itself, and which will persist past the life of the plugin. The command will have its
// CreatorId set to "" and its PluginId set to the id of the plugin that created it.
//
// @tag SlashCommand
// Minimum server version: 5.28
CreateCommand(cmd *model.Command) (*model.Command, error)
// ListCommands returns the list of all slash commands for teamID. E.g., custom commands
// (those created through the integrations menu, the REST api, or the plugin api CreateCommand),
// plugin commands (those created with plugin api RegisterCommand), and builtin commands
// (those added internally through RegisterCommandProvider).
//
// @tag SlashCommand
// Minimum server version: 5.28
ListCommands(teamID string) ([]*model.Command, error)
// ListCustomCommands returns the list of slash commands for teamID that where created
// through the integrations menu, the REST api, or the plugin api CreateCommand.
//
// @tag SlashCommand
// Minimum server version: 5.28
ListCustomCommands(teamID string) ([]*model.Command, error)
// ListPluginCommands returns the list of slash commands for teamID that were created
// with the plugin api RegisterCommand.
//
// @tag SlashCommand
// Minimum server version: 5.28
ListPluginCommands(teamID string) ([]*model.Command, error)
// ListBuiltInCommands returns the list of slash commands that are builtin commands
// (those added internally through RegisterCommandProvider).
//
// @tag SlashCommand
// Minimum server version: 5.28
ListBuiltInCommands() ([]*model.Command, error)
// GetCommand returns the command definition based on a command id string.
//
// @tag SlashCommand
// Minimum server version: 5.28
GetCommand(commandID string) (*model.Command, error)
// UpdateCommand updates a single command (commandID) with the information provided in the
// updatedCmd model.Command struct. The following fields in the command cannot be updated:
// Id, Token, CreateAt, DeleteAt, and PluginId. If updatedCmd.TeamId is blank, it
// will be set to commandID's TeamId.
//
// @tag SlashCommand
// Minimum server version: 5.28
UpdateCommand(commandID string, updatedCmd *model.Command) (*model.Command, error)
// DeleteCommand deletes a slash command (commandID).
//
// @tag SlashCommand
// Minimum server version: 5.28
DeleteCommand(commandID string) error
}
var handshake = plugin.HandshakeConfig{

Просмотреть файл

@@ -1036,3 +1036,59 @@ func (api *apiTimerLayer) PublishUserTyping(userId, channelId, parentId string)
api.recordTime(startTime, "PublishUserTyping", _returnsA == nil)
return _returnsA
}
func (api *apiTimerLayer) CreateCommand(cmd *model.Command) (*model.Command, error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.CreateCommand(cmd)
api.recordTime(startTime, "CreateCommand", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) ListCommands(teamID string) ([]*model.Command, error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.ListCommands(teamID)
api.recordTime(startTime, "ListCommands", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) ListCustomCommands(teamID string) ([]*model.Command, error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.ListCustomCommands(teamID)
api.recordTime(startTime, "ListCustomCommands", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) ListPluginCommands(teamID string) ([]*model.Command, error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.ListPluginCommands(teamID)
api.recordTime(startTime, "ListPluginCommands", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) ListBuiltInCommands() ([]*model.Command, error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.ListBuiltInCommands()
api.recordTime(startTime, "ListBuiltInCommands", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) GetCommand(commandID string) (*model.Command, error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.GetCommand(commandID)
api.recordTime(startTime, "GetCommand", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) UpdateCommand(commandID string, updatedCmd *model.Command) (*model.Command, error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.UpdateCommand(commandID, updatedCmd)
api.recordTime(startTime, "UpdateCommand", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) DeleteCommand(commandID string) error {
startTime := timePkg.Now()
_returnsA := api.apiImpl.DeleteCommand(commandID)
api.recordTime(startTime, "DeleteCommand", _returnsA == nil)
return _returnsA
}

Просмотреть файл

@@ -4512,3 +4512,242 @@ func (s *apiRPCServer) PublishUserTyping(args *Z_PublishUserTypingArgs, returns
}
return nil
}
type Z_CreateCommandArgs struct {
A *model.Command
}
type Z_CreateCommandReturns struct {
A *model.Command
B error
}
func (g *apiRPCClient) CreateCommand(cmd *model.Command) (*model.Command, error) {
_args := &Z_CreateCommandArgs{cmd}
_returns := &Z_CreateCommandReturns{}
if err := g.client.Call("Plugin.CreateCommand", _args, _returns); err != nil {
log.Printf("RPC call to CreateCommand API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) CreateCommand(args *Z_CreateCommandArgs, returns *Z_CreateCommandReturns) error {
if hook, ok := s.impl.(interface {
CreateCommand(cmd *model.Command) (*model.Command, error)
}); ok {
returns.A, returns.B = hook.CreateCommand(args.A)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API CreateCommand called but not implemented."))
}
return nil
}
type Z_ListCommandsArgs struct {
A string
}
type Z_ListCommandsReturns struct {
A []*model.Command
B error
}
func (g *apiRPCClient) ListCommands(teamID string) ([]*model.Command, error) {
_args := &Z_ListCommandsArgs{teamID}
_returns := &Z_ListCommandsReturns{}
if err := g.client.Call("Plugin.ListCommands", _args, _returns); err != nil {
log.Printf("RPC call to ListCommands API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) ListCommands(args *Z_ListCommandsArgs, returns *Z_ListCommandsReturns) error {
if hook, ok := s.impl.(interface {
ListCommands(teamID string) ([]*model.Command, error)
}); ok {
returns.A, returns.B = hook.ListCommands(args.A)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API ListCommands called but not implemented."))
}
return nil
}
type Z_ListCustomCommandsArgs struct {
A string
}
type Z_ListCustomCommandsReturns struct {
A []*model.Command
B error
}
func (g *apiRPCClient) ListCustomCommands(teamID string) ([]*model.Command, error) {
_args := &Z_ListCustomCommandsArgs{teamID}
_returns := &Z_ListCustomCommandsReturns{}
if err := g.client.Call("Plugin.ListCustomCommands", _args, _returns); err != nil {
log.Printf("RPC call to ListCustomCommands API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) ListCustomCommands(args *Z_ListCustomCommandsArgs, returns *Z_ListCustomCommandsReturns) error {
if hook, ok := s.impl.(interface {
ListCustomCommands(teamID string) ([]*model.Command, error)
}); ok {
returns.A, returns.B = hook.ListCustomCommands(args.A)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API ListCustomCommands called but not implemented."))
}
return nil
}
type Z_ListPluginCommandsArgs struct {
A string
}
type Z_ListPluginCommandsReturns struct {
A []*model.Command
B error
}
func (g *apiRPCClient) ListPluginCommands(teamID string) ([]*model.Command, error) {
_args := &Z_ListPluginCommandsArgs{teamID}
_returns := &Z_ListPluginCommandsReturns{}
if err := g.client.Call("Plugin.ListPluginCommands", _args, _returns); err != nil {
log.Printf("RPC call to ListPluginCommands API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) ListPluginCommands(args *Z_ListPluginCommandsArgs, returns *Z_ListPluginCommandsReturns) error {
if hook, ok := s.impl.(interface {
ListPluginCommands(teamID string) ([]*model.Command, error)
}); ok {
returns.A, returns.B = hook.ListPluginCommands(args.A)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API ListPluginCommands called but not implemented."))
}
return nil
}
type Z_ListBuiltInCommandsArgs struct {
}
type Z_ListBuiltInCommandsReturns struct {
A []*model.Command
B error
}
func (g *apiRPCClient) ListBuiltInCommands() ([]*model.Command, error) {
_args := &Z_ListBuiltInCommandsArgs{}
_returns := &Z_ListBuiltInCommandsReturns{}
if err := g.client.Call("Plugin.ListBuiltInCommands", _args, _returns); err != nil {
log.Printf("RPC call to ListBuiltInCommands API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) ListBuiltInCommands(args *Z_ListBuiltInCommandsArgs, returns *Z_ListBuiltInCommandsReturns) error {
if hook, ok := s.impl.(interface {
ListBuiltInCommands() ([]*model.Command, error)
}); ok {
returns.A, returns.B = hook.ListBuiltInCommands()
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API ListBuiltInCommands called but not implemented."))
}
return nil
}
type Z_GetCommandArgs struct {
A string
}
type Z_GetCommandReturns struct {
A *model.Command
B error
}
func (g *apiRPCClient) GetCommand(commandID string) (*model.Command, error) {
_args := &Z_GetCommandArgs{commandID}
_returns := &Z_GetCommandReturns{}
if err := g.client.Call("Plugin.GetCommand", _args, _returns); err != nil {
log.Printf("RPC call to GetCommand API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) GetCommand(args *Z_GetCommandArgs, returns *Z_GetCommandReturns) error {
if hook, ok := s.impl.(interface {
GetCommand(commandID string) (*model.Command, error)
}); ok {
returns.A, returns.B = hook.GetCommand(args.A)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API GetCommand called but not implemented."))
}
return nil
}
type Z_UpdateCommandArgs struct {
A string
B *model.Command
}
type Z_UpdateCommandReturns struct {
A *model.Command
B error
}
func (g *apiRPCClient) UpdateCommand(commandID string, updatedCmd *model.Command) (*model.Command, error) {
_args := &Z_UpdateCommandArgs{commandID, updatedCmd}
_returns := &Z_UpdateCommandReturns{}
if err := g.client.Call("Plugin.UpdateCommand", _args, _returns); err != nil {
log.Printf("RPC call to UpdateCommand API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) UpdateCommand(args *Z_UpdateCommandArgs, returns *Z_UpdateCommandReturns) error {
if hook, ok := s.impl.(interface {
UpdateCommand(commandID string, updatedCmd *model.Command) (*model.Command, error)
}); ok {
returns.A, returns.B = hook.UpdateCommand(args.A, args.B)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API UpdateCommand called but not implemented."))
}
return nil
}
type Z_DeleteCommandArgs struct {
A string
}
type Z_DeleteCommandReturns struct {
A error
}
func (g *apiRPCClient) DeleteCommand(commandID string) error {
_args := &Z_DeleteCommandArgs{commandID}
_returns := &Z_DeleteCommandReturns{}
if err := g.client.Call("Plugin.DeleteCommand", _args, _returns); err != nil {
log.Printf("RPC call to DeleteCommand API failed: %s", err.Error())
}
return _returns.A
}
func (s *apiRPCServer) DeleteCommand(args *Z_DeleteCommandArgs, returns *Z_DeleteCommandReturns) error {
if hook, ok := s.impl.(interface {
DeleteCommand(commandID string) error
}); ok {
returns.A = hook.DeleteCommand(args.A)
returns.A = encodableError(returns.A)
} else {
return encodableError(fmt.Errorf("API DeleteCommand called but not implemented."))
}
return nil
}

Просмотреть файл

@@ -168,6 +168,29 @@ func (_m *API) CreateChannel(channel *model.Channel) (*model.Channel, *model.App
return r0, r1
}
// CreateCommand provides a mock function with given fields: cmd
func (_m *API) CreateCommand(cmd *model.Command) (*model.Command, error) {
ret := _m.Called(cmd)
var r0 *model.Command
if rf, ok := ret.Get(0).(func(*model.Command) *model.Command); ok {
r0 = rf(cmd)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Command)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(*model.Command) error); ok {
r1 = rf(cmd)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// CreatePost provides a mock function with given fields: post
func (_m *API) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
ret := _m.Called(post)
@@ -366,6 +389,20 @@ func (_m *API) DeleteChannelMember(channelId string, userId string) *model.AppEr
return r0
}
// DeleteCommand provides a mock function with given fields: commandID
func (_m *API) DeleteCommand(commandID string) error {
ret := _m.Called(commandID)
var r0 error
if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(commandID)
} else {
r0 = ret.Error(0)
}
return r0
}
// DeleteEphemeralPost provides a mock function with given fields: userId, postId
func (_m *API) DeleteEphemeralPost(userId string, postId string) {
_m.Called(userId, postId)
@@ -827,6 +864,29 @@ func (_m *API) GetChannelsForTeamForUser(teamId string, userId string, includeDe
return r0, r1
}
// GetCommand provides a mock function with given fields: commandID
func (_m *API) GetCommand(commandID string) (*model.Command, error) {
ret := _m.Called(commandID)
var r0 *model.Command
if rf, ok := ret.Get(0).(func(string) *model.Command); ok {
r0 = rf(commandID)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Command)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(commandID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetConfig provides a mock function with given fields:
func (_m *API) GetConfig() *model.Config {
ret := _m.Called()
@@ -2347,6 +2407,98 @@ func (_m *API) KVSetWithOptions(key string, value []byte, options model.PluginKV
return r0, r1
}
// ListBuiltInCommands provides a mock function with given fields:
func (_m *API) ListBuiltInCommands() ([]*model.Command, error) {
ret := _m.Called()
var r0 []*model.Command
if rf, ok := ret.Get(0).(func() []*model.Command); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.Command)
}
}
var r1 error
if rf, ok := ret.Get(1).(func() error); ok {
r1 = rf()
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// ListCommands provides a mock function with given fields: teamID
func (_m *API) ListCommands(teamID string) ([]*model.Command, error) {
ret := _m.Called(teamID)
var r0 []*model.Command
if rf, ok := ret.Get(0).(func(string) []*model.Command); ok {
r0 = rf(teamID)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.Command)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(teamID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// ListCustomCommands provides a mock function with given fields: teamID
func (_m *API) ListCustomCommands(teamID string) ([]*model.Command, error) {
ret := _m.Called(teamID)
var r0 []*model.Command
if rf, ok := ret.Get(0).(func(string) []*model.Command); ok {
r0 = rf(teamID)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.Command)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(teamID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// ListPluginCommands provides a mock function with given fields: teamID
func (_m *API) ListPluginCommands(teamID string) ([]*model.Command, error) {
ret := _m.Called(teamID)
var r0 []*model.Command
if rf, ok := ret.Get(0).(func(string) []*model.Command); ok {
r0 = rf(teamID)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.Command)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(teamID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// LoadPluginConfiguration provides a mock function with given fields: dest
func (_m *API) LoadPluginConfiguration(dest interface{}) error {
ret := _m.Called(dest)
@@ -2925,6 +3077,29 @@ func (_m *API) UpdateChannelMemberRoles(channelId string, userId string, newRole
return r0, r1
}
// UpdateCommand provides a mock function with given fields: commandID, updatedCmd
func (_m *API) UpdateCommand(commandID string, updatedCmd *model.Command) (*model.Command, error) {
ret := _m.Called(commandID, updatedCmd)
var r0 *model.Command
if rf, ok := ret.Get(0).(func(string, *model.Command) *model.Command); ok {
r0 = rf(commandID, updatedCmd)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Command)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(string, *model.Command) error); ok {
r1 = rf(commandID, updatedCmd)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// UpdateEphemeralPost provides a mock function with given fields: userId, post
func (_m *API) UpdateEphemeralPost(userId string, post *model.Post) *model.Post {
ret := _m.Called(userId, post)