mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Gh 24291 api meesage unclear when parameters are incorrect (#26457)
Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
parent
1806ba2cc7
commit
9fee0393c3
@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/audit"
|
||||
@ -89,6 +90,16 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if channel.TeamId == "" {
|
||||
c.SetInvalidParamWithDetails("team_id", i18n.T("api.channel.create_channel.missing_team_id.error"))
|
||||
return
|
||||
}
|
||||
|
||||
if channel.DisplayName == "" {
|
||||
c.SetInvalidParamWithDetails("display_name", i18n.T("api.channel.create_channel.missing_display_name.error"))
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := c.MakeAuditRecord("createChannel", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
audit.AddEventParameterAuditable(auditRec, "channel", channel)
|
||||
|
@ -57,6 +57,7 @@ func TestCreateCategoryForTeamForUser(t *testing.T) {
|
||||
TeamId: th.BasicTeam.Id,
|
||||
Type: model.ChannelTypeOpen,
|
||||
Name: "testchannel",
|
||||
DisplayName: "testchannel",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -329,6 +330,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
TeamId: th.BasicTeam.Id,
|
||||
Type: model.ChannelTypeOpen,
|
||||
Name: "testchannel",
|
||||
DisplayName: "testchannel",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -494,6 +496,7 @@ func TestUpdateCategoriesForTeamForUser(t *testing.T) {
|
||||
TeamId: th.BasicTeam.Id,
|
||||
Type: model.ChannelTypeOpen,
|
||||
Name: "testchannel",
|
||||
DisplayName: "testchannel",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -144,6 +144,22 @@ func TestCreateChannel(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, *groupConstrainedChannel.GroupConstrained, *rchannel.GroupConstrained, "GroupConstrained flags do not match")
|
||||
|
||||
t.Run("Test create channel with missing team id", func(t *testing.T) {
|
||||
channel := &model.Channel{DisplayName: "Test API Name", Name: GenerateTestChannelName(), Type: model.ChannelTypeOpen, TeamId: ""}
|
||||
|
||||
_, resp, err := client.CreateChannel(context.Background(), channel)
|
||||
CheckErrorID(t, err, "api.context.invalid_body_param.app_error")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("Test create channel with missing display name", func(t *testing.T) {
|
||||
channel := &model.Channel{DisplayName: "", Name: GenerateTestChannelName(), Type: model.ChannelTypeOpen, TeamId: team.Id}
|
||||
|
||||
_, resp, err := client.CreateChannel(context.Background(), channel)
|
||||
CheckErrorID(t, err, "api.context.invalid_body_param.app_error")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpdateChannel(t *testing.T) {
|
||||
|
@ -307,6 +307,14 @@
|
||||
"id": "api.channel.create_channel.max_channel_limit.app_error",
|
||||
"translation": "Unable to create more than {{.MaxChannelsPerTeam}} channels for current team."
|
||||
},
|
||||
{
|
||||
"id": "api.channel.create_channel.missing_display_name.error",
|
||||
"translation": "Missing display_name in request body"
|
||||
},
|
||||
{
|
||||
"id": "api.channel.create_channel.missing_team_id.error",
|
||||
"translation": "Missing team_id in request body"
|
||||
},
|
||||
{
|
||||
"id": "api.channel.create_default_channels.off_topic",
|
||||
"translation": "Off-Topic"
|
||||
|
Loading…
Reference in New Issue
Block a user