коммит произвёл
GitHub
родитель
61cc7a8680
Коммит
c5c6a5ce53
@@ -929,3 +929,110 @@ func (api *PluginAPI) PluginHTTP(request *http.Request) *http.Response {
|
||||
api.app.ServeInterPluginRequest(responseTransfer, request, api.id, destinationPluginId)
|
||||
return responseTransfer.GenerateResponse()
|
||||
}
|
||||
|
||||
func (api *PluginAPI) CreateCommand(cmd *model.Command) (*model.Command, error) {
|
||||
cmd.CreatorId = ""
|
||||
cmd.PluginId = api.id
|
||||
|
||||
cmd, appErr := api.app.createCommand(cmd)
|
||||
|
||||
if appErr != nil {
|
||||
return cmd, appErr
|
||||
}
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (api *PluginAPI) ListCommands(teamID string) ([]*model.Command, error) {
|
||||
ret := make([]*model.Command, 0)
|
||||
|
||||
cmds, err := api.ListPluginCommands(teamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, cmds...)
|
||||
|
||||
cmds, err = api.ListBuiltInCommands()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, cmds...)
|
||||
|
||||
cmds, err = api.ListCustomCommands(teamID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, cmds...)
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (api *PluginAPI) ListCustomCommands(teamID string) ([]*model.Command, error) {
|
||||
// Plugins are allowed to bypass the a.Config().ServiceSettings.EnableCommands setting.
|
||||
return api.app.Srv().Store.Command().GetByTeam(teamID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) ListPluginCommands(teamID string) ([]*model.Command, error) {
|
||||
commands := make([]*model.Command, 0)
|
||||
seen := make(map[string]bool)
|
||||
|
||||
for _, cmd := range api.app.PluginCommandsForTeam(teamID) {
|
||||
if !seen[cmd.Trigger] {
|
||||
seen[cmd.Trigger] = true
|
||||
commands = append(commands, cmd)
|
||||
}
|
||||
}
|
||||
|
||||
return commands, nil
|
||||
}
|
||||
|
||||
func (api *PluginAPI) ListBuiltInCommands() ([]*model.Command, error) {
|
||||
commands := make([]*model.Command, 0)
|
||||
seen := make(map[string]bool)
|
||||
|
||||
for _, value := range commandProviders {
|
||||
if cmd := value.GetCommand(api.app, utils.T); cmd != nil {
|
||||
cpy := *cmd
|
||||
if cpy.AutoComplete && !seen[cpy.Trigger] {
|
||||
cpy.Sanitize()
|
||||
seen[cpy.Trigger] = true
|
||||
commands = append(commands, &cpy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return commands, nil
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetCommand(commandID string) (*model.Command, error) {
|
||||
return api.app.Srv().Store.Command().Get(commandID)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) UpdateCommand(commandID string, updatedCmd *model.Command) (*model.Command, error) {
|
||||
oldCmd, err := api.GetCommand(commandID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
updatedCmd.Trigger = strings.ToLower(updatedCmd.Trigger)
|
||||
updatedCmd.Id = oldCmd.Id
|
||||
updatedCmd.Token = oldCmd.Token
|
||||
updatedCmd.CreateAt = oldCmd.CreateAt
|
||||
updatedCmd.UpdateAt = model.GetMillis()
|
||||
updatedCmd.DeleteAt = oldCmd.DeleteAt
|
||||
updatedCmd.PluginId = api.id
|
||||
if updatedCmd.TeamId == "" {
|
||||
updatedCmd.TeamId = oldCmd.TeamId
|
||||
}
|
||||
|
||||
return api.app.Srv().Store.Command().Update(updatedCmd)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) DeleteCommand(commandID string) error {
|
||||
err := api.app.Srv().Store.Command().Delete(commandID, model.GetMillis())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user