MM-62500 - Apply Delete check on commands (#29896)
* apply delete check on commands, add tests * combine tests --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1f34d784dd
Коммит
f2af360401
@@ -335,6 +335,11 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if channel.DeleteAt != 0 {
|
||||||
|
c.Err = model.NewAppError("createPost", "api.command.execute_command.deleted.error", nil, "", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if channel.Type != model.ChannelTypeDirect && channel.Type != model.ChannelTypeGroup {
|
if channel.Type != model.ChannelTypeDirect && channel.Type != model.ChannelTypeGroup {
|
||||||
// if this isn't a DM or GM, the team id is implicitly taken from the channel so that slash commands created on
|
// if this isn't a DM or GM, the team id is implicitly taken from the channel so that slash commands created on
|
||||||
// some other team can't be run against this one
|
// some other team can't be run against this one
|
||||||
|
|||||||
@@ -1140,4 +1140,21 @@ func TestExecuteCommandReadOnly(t *testing.T) {
|
|||||||
_, resp, err = client.ExecuteCommandWithTeam(context.Background(), th.BasicChannel.Id, th.BasicChannel.TeamId, "/postcommand")
|
_, resp, err = client.ExecuteCommandWithTeam(context.Background(), th.BasicChannel.Id, th.BasicChannel.TeamId, "/postcommand")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
|
|
||||||
|
// Confirm that the command works when the channel is not read only - use different channel
|
||||||
|
_, resp, err = client.ExecuteCommandWithTeam(context.Background(), th.BasicChannel2.Id, th.BasicChannel2.TeamId, "/postcommand")
|
||||||
|
require.NoError(t, err)
|
||||||
|
CheckOKStatus(t, resp)
|
||||||
|
|
||||||
|
appErr = th.App.DeleteChannel(
|
||||||
|
th.Context,
|
||||||
|
th.BasicChannel2,
|
||||||
|
th.SystemAdminUser.Id,
|
||||||
|
)
|
||||||
|
require.Nil(t, appErr, "failed to delete channel")
|
||||||
|
|
||||||
|
// Confirm that the command fails when the channel is archived
|
||||||
|
_, resp, err = client.ExecuteCommandWithTeam(context.Background(), th.BasicChannel2.Id, th.BasicChannel2.TeamId, "/postcommand")
|
||||||
|
require.Error(t, err)
|
||||||
|
CheckBadRequestStatus(t, resp)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -603,6 +603,10 @@
|
|||||||
"id": "api.command.execute_command.create_post_failed.app_error",
|
"id": "api.command.execute_command.create_post_failed.app_error",
|
||||||
"translation": "Command '{{.Trigger}}' failed to post response. Please contact your System Administrator."
|
"translation": "Command '{{.Trigger}}' failed to post response. Please contact your System Administrator."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.command.execute_command.deleted.error",
|
||||||
|
"translation": "Can not run command in deleted channel."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.command.execute_command.failed.app_error",
|
"id": "api.command.execute_command.failed.app_error",
|
||||||
"translation": "Command with a trigger of '{{.Trigger}}' failed."
|
"translation": "Command with a trigger of '{{.Trigger}}' failed."
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user