коммит произвёл
GitHub
родитель
8ef7f78d8d
Коммит
532f2882d1
@@ -671,22 +671,8 @@ func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError
|
||||
func (a *App) createCommand(cmd *model.Command) (*model.Command, *model.AppError) {
|
||||
cmd.Trigger = strings.ToLower(cmd.Trigger)
|
||||
|
||||
teamCmds, err := a.Srv().Store().Command().GetByTeam(cmd.TeamId)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("CreateCommand", "app.command.createcommand.internal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
for _, existingCommand := range teamCmds {
|
||||
if cmd.Trigger == existingCommand.Trigger {
|
||||
return nil, model.NewAppError("CreateCommand", "api.command.duplicate_trigger.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
for _, builtInProvider := range commandProviders {
|
||||
builtInCommand := builtInProvider.GetCommand(a, i18n.T)
|
||||
if builtInCommand != nil && cmd.Trigger == builtInCommand.Trigger {
|
||||
return nil, model.NewAppError("CreateCommand", "api.command.duplicate_trigger.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
if appErr := a.validateCommandTriggerUniqueness(cmd.TeamId, cmd.Trigger, ""); appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
command, nErr := a.Srv().Store().Command().Save(cmd)
|
||||
@@ -703,6 +689,30 @@ func (a *App) createCommand(cmd *model.Command) (*model.Command, *model.AppError
|
||||
return command, nil
|
||||
}
|
||||
|
||||
func (a *App) validateCommandTriggerUniqueness(teamID, trigger, excludeCommandID string) *model.AppError {
|
||||
trigger = strings.ToLower(trigger)
|
||||
|
||||
for _, builtInProvider := range commandProviders {
|
||||
builtInCommand := builtInProvider.GetCommand(a, i18n.T)
|
||||
if builtInCommand != nil && trigger == strings.ToLower(builtInCommand.Trigger) {
|
||||
return model.NewAppError("validateCommandTriggerUniqueness", "api.command.duplicate_trigger.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
teamCmds, err := a.Srv().Store().Command().GetByTeam(teamID)
|
||||
if err != nil {
|
||||
return model.NewAppError("validateCommandTriggerUniqueness", "app.command.validatecommandtriggeruniqueness.internal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
for _, existingCommand := range teamCmds {
|
||||
if existingCommand.Id != excludeCommandID && trigger == strings.ToLower(existingCommand.Trigger) {
|
||||
return model.NewAppError("validateCommandTriggerUniqueness", "api.command.duplicate_trigger.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) GetCommand(commandID string) (*model.Command, *model.AppError) {
|
||||
if !*a.Config().ServiceSettings.EnableCommands {
|
||||
return nil, model.NewAppError("GetCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
@@ -736,6 +746,10 @@ func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command,
|
||||
updatedCmd.PluginId = oldCmd.PluginId
|
||||
updatedCmd.TeamId = oldCmd.TeamId
|
||||
|
||||
if appErr := a.validateCommandTriggerUniqueness(updatedCmd.TeamId, updatedCmd.Trigger, updatedCmd.Id); appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
command, err := a.Srv().Store().Command().Update(updatedCmd)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
@@ -754,6 +768,10 @@ func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command,
|
||||
}
|
||||
|
||||
func (a *App) MoveCommand(team *model.Team, command *model.Command) *model.AppError {
|
||||
if appErr := a.validateCommandTriggerUniqueness(team.Id, command.Trigger, command.Id); appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
command.TeamId = team.Id
|
||||
|
||||
_, err := a.Srv().Store().Command().Update(command)
|
||||
|
||||
Ссылка в новой задаче
Block a user