Adding loc to new command backend
Этот коммит содержится в:
@@ -4,6 +4,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -16,14 +17,15 @@ import (
|
||||
)
|
||||
|
||||
type CommandProvider interface {
|
||||
GetCommand() *model.Command
|
||||
GetTrigger() string
|
||||
GetCommand(c *Context) *model.Command
|
||||
DoCommand(c *Context, channelId string, message string) *model.CommandResponse
|
||||
}
|
||||
|
||||
var commandProviders = make(map[string]CommandProvider)
|
||||
|
||||
func RegisterCommandProvider(newProvider CommandProvider) {
|
||||
commandProviders[newProvider.GetCommand().Trigger] = newProvider
|
||||
commandProviders[newProvider.GetTrigger()] = newProvider
|
||||
}
|
||||
|
||||
func GetCommandProvidersProvider(name string) CommandProvider {
|
||||
@@ -56,7 +58,7 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
commands := make([]*model.Command, 0, 32)
|
||||
seen := make(map[string]bool)
|
||||
for _, value := range commandProviders {
|
||||
cpy := *value.GetCommand()
|
||||
cpy := *value.GetCommand(c)
|
||||
if cpy.AutoComplete && !seen[cpy.Id] {
|
||||
cpy.Sanatize()
|
||||
seen[cpy.Trigger] = true
|
||||
@@ -87,7 +89,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
channelId := strings.TrimSpace(props["channelId"])
|
||||
|
||||
if len(command) <= 1 || strings.Index(command, "/") != 0 {
|
||||
c.Err = model.NewLocAppError("executeCommand", "api.command.check_command.start.app_error", nil, "")
|
||||
c.Err = model.NewLocAppError("executeCommand", "api.command.execute_command.start.app_error", nil, "")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -147,7 +149,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
teamCmds := result.Data.([]*model.Command)
|
||||
for _, cmd := range teamCmds {
|
||||
if trigger == cmd.Trigger {
|
||||
l4g.Debug("Executing cmd=" + trigger + " userId=" + c.Session.UserId)
|
||||
l4g.Debug(fmt.Sprintf(utils.T("api.command.execute_command.debug"), trigger, c.Session.UserId))
|
||||
|
||||
p := url.Values{}
|
||||
p.Set("token", cmd.Token)
|
||||
@@ -178,18 +180,18 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if resp, err := client.Do(req); err != nil {
|
||||
c.Err = model.NewAppError("command", "Command with a trigger of '"+trigger+"' failed", err.Error())
|
||||
c.Err = model.NewLocAppError("command", "api.command.execute_command.failed.app_error", map[string]interface{}{"Trigger": trigger}, err.Error())
|
||||
} else {
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
response := model.CommandResponseFromJson(resp.Body)
|
||||
if response == nil {
|
||||
c.Err = model.NewAppError("command", "Command with a trigger of '"+trigger+"' returned an empty response", "")
|
||||
c.Err = model.NewLocAppError("command", "api.command.execute_command.failed_empty.app_error", map[string]interface{}{"Trigger": trigger}, "")
|
||||
} else {
|
||||
handleResponse(c, w, response, channelId)
|
||||
}
|
||||
} else {
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
c.Err = model.NewAppError("command", "Command with a trigger of '"+trigger+"' returned response "+resp.Status, string(body))
|
||||
c.Err = model.NewLocAppError("command", "api.command.execute_command.failed_resp.app_error", map[string]interface{}{"Trigger": trigger, "Status": resp.Status}, string(body))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +202,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
c.Err = model.NewAppError("command", "Command with a trigger of '"+trigger+"' not found", "")
|
||||
c.Err = model.NewLocAppError("command", "api.command.execute_command.not_found.app_error", map[string]interface{}{"Trigger": trigger}, "")
|
||||
}
|
||||
|
||||
func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandResponse, channelId string) {
|
||||
@@ -209,14 +211,14 @@ func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandRe
|
||||
post.ChannelId = channelId
|
||||
post.Message = response.Text
|
||||
if _, err := CreatePost(c, post, true); err != nil {
|
||||
c.Err = model.NewAppError("command", "An error while saving the command response to the channel", "")
|
||||
c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
|
||||
}
|
||||
} else if response.ResponseType == model.COMMAND_RESPONSE_TYPE_EPHEMERAL {
|
||||
post := &model.Post{}
|
||||
post.ChannelId = channelId
|
||||
post.Message = "TODO_EPHEMERAL: " + response.Text
|
||||
if _, err := CreatePost(c, post, true); err != nil {
|
||||
c.Err = model.NewAppError("command", "An error while saving the command response to the channel", "")
|
||||
c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,14 +227,14 @@ func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandRe
|
||||
|
||||
func createCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCommands {
|
||||
c.Err = model.NewAppError("createCommand", "Commands have been disabled by the system admin.", "")
|
||||
c.Err = model.NewLocAppError("createCommand", "api.command.disabled.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusNotImplemented
|
||||
return
|
||||
}
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations {
|
||||
if !(c.IsSystemAdmin() || c.IsTeamAdmin()) {
|
||||
c.Err = model.NewAppError("createCommand", "Integrations have been limited to admins only.", "")
|
||||
c.Err = model.NewLocAppError("createCommand", "api.command.admin_only.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return
|
||||
}
|
||||
@@ -262,14 +264,14 @@ func createCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func listTeamCommands(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCommands {
|
||||
c.Err = model.NewAppError("createCommand", "Commands have been disabled by the system admin.", "")
|
||||
c.Err = model.NewLocAppError("listTeamCommands", "api.command.disabled.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusNotImplemented
|
||||
return
|
||||
}
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations {
|
||||
if !(c.IsSystemAdmin() || c.IsTeamAdmin()) {
|
||||
c.Err = model.NewAppError("createCommand", "Integrations have been limited to admins only.", "")
|
||||
c.Err = model.NewLocAppError("listTeamCommands", "api.command.admin_only.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return
|
||||
}
|
||||
@@ -286,14 +288,14 @@ func listTeamCommands(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCommands {
|
||||
c.Err = model.NewAppError("createCommand", "Commands have been disabled by the system admin.", "")
|
||||
c.Err = model.NewLocAppError("regenCommandToken", "api.command.disabled.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusNotImplemented
|
||||
return
|
||||
}
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations {
|
||||
if !(c.IsSystemAdmin() || c.IsTeamAdmin()) {
|
||||
c.Err = model.NewAppError("createCommand", "Integrations have been limited to admins only.", "")
|
||||
c.Err = model.NewLocAppError("regenCommandToken", "api.command.admin_only.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return
|
||||
}
|
||||
@@ -318,7 +320,7 @@ func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if c.Session.TeamId != cmd.TeamId && c.Session.UserId != cmd.CreatorId && !c.IsTeamAdmin() {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.Err = model.NewAppError("regenToken", "Inappropriate permissions to regenerate command token", "user_id="+c.Session.UserId)
|
||||
c.Err = model.NewLocAppError("regenToken", "api.command.regen.app_error", nil, "user_id="+c.Session.UserId)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -335,14 +337,14 @@ func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func deleteCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCommands {
|
||||
c.Err = model.NewAppError("createCommand", "Commands have been disabled by the system admin.", "")
|
||||
c.Err = model.NewLocAppError("deleteCommand", "api.command.disabled.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusNotImplemented
|
||||
return
|
||||
}
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations {
|
||||
if !(c.IsSystemAdmin() || c.IsTeamAdmin()) {
|
||||
c.Err = model.NewAppError("createCommand", "Integrations have been limited to admins only.", "")
|
||||
c.Err = model.NewLocAppError("deleteCommand", "api.command.admin_only.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return
|
||||
}
|
||||
@@ -364,7 +366,7 @@ func deleteCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
if c.Session.TeamId != result.Data.(*model.Command).TeamId && c.Session.UserId != result.Data.(*model.Command).CreatorId && !c.IsTeamAdmin() {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.Err = model.NewAppError("deleteCommand", "Inappropriate permissions to delete command", "user_id="+c.Session.UserId)
|
||||
c.Err = model.NewLocAppError("deleteCommand", "api.command.delete.app_error", nil, "user_id="+c.Session.UserId)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,17 +17,25 @@ var echoSem chan bool
|
||||
type EchoProvider struct {
|
||||
}
|
||||
|
||||
const (
|
||||
CMD_ECHO = "echo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterCommandProvider(&EchoProvider{})
|
||||
}
|
||||
|
||||
func (me *EchoProvider) GetCommand() *model.Command {
|
||||
func (me *EchoProvider) GetTrigger() string {
|
||||
return CMD_ECHO
|
||||
}
|
||||
|
||||
func (me *EchoProvider) GetCommand(c *Context) *model.Command {
|
||||
return &model.Command{
|
||||
Trigger: "echo",
|
||||
Trigger: CMD_ECHO,
|
||||
AutoComplete: true,
|
||||
AutoCompleteDesc: "Echo back text from your account",
|
||||
AutoCompleteHint: "\"message\" [delay in seconds]",
|
||||
DisplayName: "echo",
|
||||
AutoCompleteDesc: c.T("api.command_echo.desc"),
|
||||
AutoCompleteHint: c.T("api.command_echo.hint"),
|
||||
DisplayName: c.T("api.command_echo.name"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +59,7 @@ func (me *EchoProvider) DoCommand(c *Context, channelId string, message string)
|
||||
}
|
||||
|
||||
if delay > 10000 {
|
||||
return &model.CommandResponse{Text: "Delays must be under 10000 seconds", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
return &model.CommandResponse{Text: c.T("api.command_echo.delay.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
if echoSem == nil {
|
||||
@@ -60,7 +68,7 @@ func (me *EchoProvider) DoCommand(c *Context, channelId string, message string)
|
||||
}
|
||||
|
||||
if len(echoSem) >= maxThreads {
|
||||
return &model.CommandResponse{Text: "High volume of echo request, cannot process request", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
return &model.CommandResponse{Text: c.T("api.command_echo.high_volume.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
echoSem <- true
|
||||
@@ -73,7 +81,7 @@ func (me *EchoProvider) DoCommand(c *Context, channelId string, message string)
|
||||
time.Sleep(time.Duration(delay) * time.Second)
|
||||
|
||||
if _, err := CreatePost(c, post, true); err != nil {
|
||||
l4g.Error("Unable to create /echo post, err=%v", err)
|
||||
l4g.Error(c.T("api.command_echo.create.app_error"), err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
@@ -10,23 +10,31 @@ import (
|
||||
type JoinProvider struct {
|
||||
}
|
||||
|
||||
const (
|
||||
CMD_JOIN = "join"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterCommandProvider(&JoinProvider{})
|
||||
}
|
||||
|
||||
func (me *JoinProvider) GetCommand() *model.Command {
|
||||
func (me *JoinProvider) GetTrigger() string {
|
||||
return CMD_JOIN
|
||||
}
|
||||
|
||||
func (me *JoinProvider) GetCommand(c *Context) *model.Command {
|
||||
return &model.Command{
|
||||
Trigger: "join",
|
||||
Trigger: CMD_JOIN,
|
||||
AutoComplete: true,
|
||||
AutoCompleteDesc: "Join the open channel",
|
||||
AutoCompleteHint: "[channel-name]",
|
||||
DisplayName: "join",
|
||||
AutoCompleteDesc: c.T("api.command_join.desc"),
|
||||
AutoCompleteHint: c.T("api.command_join.hint"),
|
||||
DisplayName: c.T("api.command_join.name"),
|
||||
}
|
||||
}
|
||||
|
||||
func (me *JoinProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
|
||||
if result := <-Srv.Store.Channel().GetMoreChannels(c.Session.TeamId, c.Session.UserId); result.Err != nil {
|
||||
return &model.CommandResponse{Text: "An error occured while listing channels.", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
return &model.CommandResponse{Text: c.T("api.command_join.list.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
} else {
|
||||
channels := result.Data.(*model.ChannelList)
|
||||
|
||||
@@ -35,20 +43,20 @@ func (me *JoinProvider) DoCommand(c *Context, channelId string, message string)
|
||||
if v.Name == message {
|
||||
|
||||
if v.Type == model.CHANNEL_DIRECT {
|
||||
return &model.CommandResponse{Text: "An error occured while joining the channel.", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
return &model.CommandResponse{Text: c.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
JoinChannel(c, v.Id, "")
|
||||
|
||||
if c.Err != nil {
|
||||
c.Err = nil
|
||||
return &model.CommandResponse{Text: "An error occured while joining the channel.", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
return &model.CommandResponse{Text: c.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
return &model.CommandResponse{GotoLocation: c.GetTeamURL() + "/channels/" + v.Name, Text: "Joined channel.", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
return &model.CommandResponse{GotoLocation: c.GetTeamURL() + "/channels/" + v.Name, Text: c.T("api.command_join.success"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: "We couldn't find the channel"}
|
||||
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_join.missing.app_error")}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@ var usage = `Mattermost load testing commands to help configure the system
|
||||
|
||||
`
|
||||
|
||||
const (
|
||||
CMD_LOADTEST = "loadtest"
|
||||
)
|
||||
|
||||
type LoadTestProvider struct {
|
||||
}
|
||||
|
||||
@@ -61,9 +65,13 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func (me *LoadTestProvider) GetCommand() *model.Command {
|
||||
func (me *LoadTestProvider) GetTrigger() string {
|
||||
return CMD_LOADTEST
|
||||
}
|
||||
|
||||
func (me *LoadTestProvider) GetCommand(c *Context) *model.Command {
|
||||
return &model.Command{
|
||||
Trigger: "loadtest",
|
||||
Trigger: CMD_LOADTEST,
|
||||
AutoComplete: false,
|
||||
AutoCompleteDesc: "Debug Load Testing",
|
||||
AutoCompleteHint: "help",
|
||||
@@ -73,10 +81,10 @@ func (me *LoadTestProvider) GetCommand() *model.Command {
|
||||
|
||||
func (me *LoadTestProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
|
||||
|
||||
// This command is only available when EnableTesting is true
|
||||
// if !utils.Cfg.ServiceSettings.EnableTesting {
|
||||
// return &model.CommandResponse{}
|
||||
// }
|
||||
//This command is only available when EnableTesting is true
|
||||
if !utils.Cfg.ServiceSettings.EnableTesting {
|
||||
return &model.CommandResponse{}
|
||||
}
|
||||
|
||||
if strings.HasPrefix(message, "setup") {
|
||||
return me.SetupCommand(c, channelId, message)
|
||||
|
||||
@@ -10,20 +10,28 @@ import (
|
||||
type LogoutProvider struct {
|
||||
}
|
||||
|
||||
const (
|
||||
CMD_LOGOUT = "logout"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterCommandProvider(&LogoutProvider{})
|
||||
}
|
||||
|
||||
func (me *LogoutProvider) GetCommand() *model.Command {
|
||||
func (me *LogoutProvider) GetTrigger() string {
|
||||
return CMD_LOGOUT
|
||||
}
|
||||
|
||||
func (me *LogoutProvider) GetCommand(c *Context) *model.Command {
|
||||
return &model.Command{
|
||||
Trigger: "logout",
|
||||
Trigger: CMD_LOGOUT,
|
||||
AutoComplete: true,
|
||||
AutoCompleteDesc: "Logout",
|
||||
AutoCompleteDesc: c.T("api.command_logout.desc"),
|
||||
AutoCompleteHint: "",
|
||||
DisplayName: "logout",
|
||||
DisplayName: c.T("api.command_logout.name"),
|
||||
}
|
||||
}
|
||||
|
||||
func (me *LogoutProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
|
||||
return &model.CommandResponse{GotoLocation: "/logout", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: "Logging out..."}
|
||||
return &model.CommandResponse{GotoLocation: "/logout", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_logout.success_message")}
|
||||
}
|
||||
|
||||
@@ -10,17 +10,25 @@ import (
|
||||
type MeProvider struct {
|
||||
}
|
||||
|
||||
const (
|
||||
CMD_ME = "me"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterCommandProvider(&MeProvider{})
|
||||
}
|
||||
|
||||
func (me *MeProvider) GetCommand() *model.Command {
|
||||
func (me *MeProvider) GetTrigger() string {
|
||||
return CMD_ME
|
||||
}
|
||||
|
||||
func (me *MeProvider) GetCommand(c *Context) *model.Command {
|
||||
return &model.Command{
|
||||
Trigger: "me",
|
||||
Trigger: CMD_ME,
|
||||
AutoComplete: true,
|
||||
AutoCompleteDesc: "Do an action",
|
||||
AutoCompleteHint: "[message]",
|
||||
DisplayName: "me",
|
||||
AutoCompleteDesc: c.T("api.command_me.desc"),
|
||||
AutoCompleteHint: c.T("api.command_me.hint"),
|
||||
DisplayName: c.T("api.command_me.name"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,17 +10,25 @@ import (
|
||||
type ShrugProvider struct {
|
||||
}
|
||||
|
||||
const (
|
||||
CMD_SHRUG = "shrug"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterCommandProvider(&ShrugProvider{})
|
||||
}
|
||||
|
||||
func (me *ShrugProvider) GetCommand() *model.Command {
|
||||
func (me *ShrugProvider) GetTrigger() string {
|
||||
return CMD_SHRUG
|
||||
}
|
||||
|
||||
func (me *ShrugProvider) GetCommand(c *Context) *model.Command {
|
||||
return &model.Command{
|
||||
Trigger: "shrug",
|
||||
Trigger: CMD_SHRUG,
|
||||
AutoComplete: true,
|
||||
AutoCompleteDesc: `Adds ¯\_(ツ)_/¯ to your message`,
|
||||
AutoCompleteHint: "[message]",
|
||||
DisplayName: "shrug",
|
||||
AutoCompleteDesc: c.T("api.command_shrug.desc"),
|
||||
AutoCompleteHint: c.T("api.command_shrug.hint"),
|
||||
DisplayName: c.T("api.command_shrug.name"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations {
|
||||
if !(c.IsSystemAdmin() || c.IsTeamAdmin()) {
|
||||
c.Err = model.NewAppError("createCommand", "Integrations have been limited to admins only.", "")
|
||||
c.Err = model.NewLocAppError("createIncomingHook", "api.command.admin_only.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return
|
||||
}
|
||||
@@ -89,7 +89,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations {
|
||||
if !(c.IsSystemAdmin() || c.IsTeamAdmin()) {
|
||||
c.Err = model.NewAppError("createCommand", "Integrations have been limited to admins only.", "")
|
||||
c.Err = model.NewLocAppError("deleteIncomingHook", "api.command.admin_only.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return
|
||||
}
|
||||
@@ -134,7 +134,7 @@ func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations {
|
||||
if !(c.IsSystemAdmin() || c.IsTeamAdmin()) {
|
||||
c.Err = model.NewAppError("createCommand", "Integrations have been limited to admins only.", "")
|
||||
c.Err = model.NewLocAppError("getIncomingHooks", "api.command.admin_only.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return
|
||||
}
|
||||
@@ -158,7 +158,7 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations {
|
||||
if !(c.IsSystemAdmin() || c.IsTeamAdmin()) {
|
||||
c.Err = model.NewAppError("createCommand", "Integrations have been limited to admins only.", "")
|
||||
c.Err = model.NewLocAppError("createOutgoingHook", "api.command.admin_only.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return
|
||||
}
|
||||
@@ -222,7 +222,7 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations {
|
||||
if !(c.IsSystemAdmin() || c.IsTeamAdmin()) {
|
||||
c.Err = model.NewAppError("createCommand", "Integrations have been limited to admins only.", "")
|
||||
c.Err = model.NewLocAppError("getOutgoingHooks", "api.command.admin_only.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return
|
||||
}
|
||||
@@ -246,7 +246,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations {
|
||||
if !(c.IsSystemAdmin() || c.IsTeamAdmin()) {
|
||||
c.Err = model.NewAppError("createCommand", "Integrations have been limited to admins only.", "")
|
||||
c.Err = model.NewLocAppError("deleteOutgoingHook", "api.command.admin_only.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return
|
||||
}
|
||||
@@ -291,7 +291,7 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations {
|
||||
if !(c.IsSystemAdmin() || c.IsTeamAdmin()) {
|
||||
c.Err = model.NewAppError("createCommand", "Integrations have been limited to admins only.", "")
|
||||
c.Err = model.NewLocAppError("regenOutgoingHookToken", "api.command.admin_only.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusForbidden
|
||||
return
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user