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"
|
"strings"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost/server/public/model"
|
"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/public/shared/mlog"
|
||||||
"github.com/mattermost/mattermost/server/v8/channels/app"
|
"github.com/mattermost/mattermost/server/v8/channels/app"
|
||||||
"github.com/mattermost/mattermost/server/v8/channels/audit"
|
"github.com/mattermost/mattermost/server/v8/channels/audit"
|
||||||
@ -89,6 +90,16 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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)
|
auditRec := c.MakeAuditRecord("createChannel", audit.Fail)
|
||||||
defer c.LogAuditRec(auditRec)
|
defer c.LogAuditRec(auditRec)
|
||||||
audit.AddEventParameterAuditable(auditRec, "channel", channel)
|
audit.AddEventParameterAuditable(auditRec, "channel", channel)
|
||||||
|
@ -54,9 +54,10 @@ func TestCreateCategoryForTeamForUser(t *testing.T) {
|
|||||||
|
|
||||||
// Have another user create a channel that user isn't a part of
|
// Have another user create a channel that user isn't a part of
|
||||||
channel, _, err := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{
|
channel, _, err := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{
|
||||||
TeamId: th.BasicTeam.Id,
|
TeamId: th.BasicTeam.Id,
|
||||||
Type: model.ChannelTypeOpen,
|
Type: model.ChannelTypeOpen,
|
||||||
Name: "testchannel",
|
Name: "testchannel",
|
||||||
|
DisplayName: "testchannel",
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -326,9 +327,10 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
|||||||
|
|
||||||
// Have another user create a channel that user isn't a part of
|
// Have another user create a channel that user isn't a part of
|
||||||
channel, _, err := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{
|
channel, _, err := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{
|
||||||
TeamId: th.BasicTeam.Id,
|
TeamId: th.BasicTeam.Id,
|
||||||
Type: model.ChannelTypeOpen,
|
Type: model.ChannelTypeOpen,
|
||||||
Name: "testchannel",
|
Name: "testchannel",
|
||||||
|
DisplayName: "testchannel",
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -491,9 +493,10 @@ func TestUpdateCategoriesForTeamForUser(t *testing.T) {
|
|||||||
|
|
||||||
// Have another user create a channel that user isn't a part of
|
// Have another user create a channel that user isn't a part of
|
||||||
channel, _, err := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{
|
channel, _, err := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{
|
||||||
TeamId: th.BasicTeam.Id,
|
TeamId: th.BasicTeam.Id,
|
||||||
Type: model.ChannelTypeOpen,
|
Type: model.ChannelTypeOpen,
|
||||||
Name: "testchannel",
|
Name: "testchannel",
|
||||||
|
DisplayName: "testchannel",
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -144,6 +144,22 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, *groupConstrainedChannel.GroupConstrained, *rchannel.GroupConstrained, "GroupConstrained flags do not match")
|
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) {
|
func TestUpdateChannel(t *testing.T) {
|
||||||
|
@ -307,6 +307,14 @@
|
|||||||
"id": "api.channel.create_channel.max_channel_limit.app_error",
|
"id": "api.channel.create_channel.max_channel_limit.app_error",
|
||||||
"translation": "Unable to create more than {{.MaxChannelsPerTeam}} channels for current team."
|
"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",
|
"id": "api.channel.create_default_channels.off_topic",
|
||||||
"translation": "Off-Topic"
|
"translation": "Off-Topic"
|
||||||
|
Loading…
Reference in New Issue
Block a user