Fixing permissions issue when deleting slash commands (#4414)
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
b0f38f8a84
Коммит
420bc367fa
@@ -415,7 +415,7 @@ func deleteCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
if c.TeamId != result.Data.(*model.Command).TeamId || (c.Session.UserId != result.Data.(*model.Command).CreatorId && HasPermissionToCurrentTeamContext(c, model.PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS)) {
|
||||
if c.TeamId != result.Data.(*model.Command).TeamId || (c.Session.UserId != result.Data.(*model.Command).CreatorId && !HasPermissionToCurrentTeamContext(c, model.PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS)) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.Err = model.NewLocAppError("deleteCommand", "api.command.delete.app_error", nil, "user_id="+c.Session.UserId)
|
||||
return
|
||||
|
||||
@@ -146,14 +146,17 @@ func TestRegenToken(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteCommand(t *testing.T) {
|
||||
th := Setup().InitSystemAdmin()
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
Client := th.SystemAdminClient
|
||||
|
||||
enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
|
||||
onlyAdminIntegration := *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
|
||||
defer func() {
|
||||
utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
|
||||
*utils.Cfg.ServiceSettings.EnableCommands = enableCommands
|
||||
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = onlyAdminIntegration
|
||||
}()
|
||||
*utils.Cfg.ServiceSettings.EnableCommands = true
|
||||
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
|
||||
|
||||
cmd := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST, Trigger: "trigger"}
|
||||
cmd = Client.Must(Client.CreateCommand(cmd)).Data.(*model.Command)
|
||||
@@ -169,6 +172,20 @@ func TestDeleteCommand(t *testing.T) {
|
||||
if len(cmds) != 0 {
|
||||
t.Fatal("delete didn't work properly")
|
||||
}
|
||||
|
||||
cmd2 := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST, Trigger: "trigger2"}
|
||||
cmd2 = Client.Must(Client.CreateCommand(cmd2)).Data.(*model.Command)
|
||||
|
||||
data2 := make(map[string]string)
|
||||
data2["id"] = cmd2.Id
|
||||
if _, err := th.BasicClient.DeleteCommand(data2); err == nil {
|
||||
t.Fatal("Should have errored. Your not allowed to delete other's commands")
|
||||
}
|
||||
|
||||
cmds2 := Client.Must(Client.ListTeamCommands()).Data.([]*model.Command)
|
||||
if len(cmds2) != 1 {
|
||||
t.Fatal("Client was able to delete command without permission.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTestCommand(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user