[MM-56061] Only render where field in model.AppError when it's present (#25648)
* Only render where field in model.AppError when it's present * Remove trailing comma from permission error
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a54f927e3d
Коммит
5b6b425cfc
@@ -634,7 +634,7 @@ func verifyLinkUnlinkPermission(c *Context, syncableType model.GroupSyncableType
|
||||
switch syncableType {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), syncableID, model.PermissionManageTeam) {
|
||||
return c.App.MakePermissionError(c.AppContext.Session(), []*model.Permission{model.PermissionManageTeam})
|
||||
return model.MakePermissionError(c.AppContext.Session(), []*model.Permission{model.PermissionManageTeam})
|
||||
}
|
||||
case model.GroupSyncableTypeChannel:
|
||||
channel, err := c.App.GetChannel(c.AppContext, syncableID)
|
||||
@@ -650,7 +650,7 @@ func verifyLinkUnlinkPermission(c *Context, syncableType model.GroupSyncableType
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), syncableID, permission) {
|
||||
return c.App.MakePermissionError(c.AppContext.Session(), []*model.Permission{permission})
|
||||
return model.MakePermissionError(c.AppContext.Session(), []*model.Permission{permission})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -876,7 +876,7 @@ func getGroupsByChannelCommon(c *Context, r *http.Request) ([]byte, *model.AppEr
|
||||
permission = model.PermissionReadPublicChannelGroups
|
||||
}
|
||||
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), c.Params.ChannelId, permission) {
|
||||
return nil, c.App.MakePermissionError(c.AppContext.Session(), []*model.Permission{permission})
|
||||
return nil, model.MakePermissionError(c.AppContext.Session(), []*model.Permission{permission})
|
||||
}
|
||||
|
||||
opts := model.GroupSearchOpts{
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestNotifyAdmin(t *testing.T) {
|
||||
})
|
||||
|
||||
require.Error(t, err)
|
||||
require.Equal(t, ": Unable to save notify data.", err.Error())
|
||||
require.Equal(t, "Unable to save notify data.", err.Error())
|
||||
require.Equal(t, http.StatusInternalServerError, statusCode)
|
||||
})
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestNotifyAdmin(t *testing.T) {
|
||||
})
|
||||
|
||||
require.Error(t, err)
|
||||
require.Equal(t, ": Unable to save notify data.", err.Error())
|
||||
require.Equal(t, "Unable to save notify data.", err.Error())
|
||||
require.Equal(t, http.StatusInternalServerError, statusCode)
|
||||
})
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestNotifyAdmin(t *testing.T) {
|
||||
})
|
||||
|
||||
require.Error(t, err)
|
||||
require.Equal(t, ": Unable to save notify data.", err.Error())
|
||||
require.Equal(t, "Unable to save notify data.", err.Error())
|
||||
require.Equal(t, http.StatusInternalServerError, statusCode)
|
||||
})
|
||||
|
||||
@@ -77,7 +77,7 @@ func TestNotifyAdmin(t *testing.T) {
|
||||
})
|
||||
|
||||
require.Error(t, err)
|
||||
require.Equal(t, ": Unable to save notify data.", err.Error())
|
||||
require.Equal(t, "Unable to save notify data.", err.Error())
|
||||
require.Equal(t, http.StatusInternalServerError, statusCode)
|
||||
})
|
||||
|
||||
@@ -99,7 +99,7 @@ func TestNotifyAdmin(t *testing.T) {
|
||||
})
|
||||
require.Error(t, err)
|
||||
|
||||
require.Equal(t, ": Already notified admin", err.Error())
|
||||
require.Equal(t, "Already notified admin", err.Error())
|
||||
require.Equal(t, http.StatusForbidden, statusCode)
|
||||
})
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestTriggerNotifyAdmin(t *testing.T) {
|
||||
statusCode, err := th.SystemAdminClient.TriggerNotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{})
|
||||
|
||||
require.Error(t, err)
|
||||
require.Equal(t, ": Internal error during cloud api request.", err.Error())
|
||||
require.Equal(t, "Internal error during cloud api request.", err.Error())
|
||||
require.Equal(t, http.StatusForbidden, statusCode)
|
||||
})
|
||||
|
||||
@@ -140,7 +140,7 @@ func TestTriggerNotifyAdmin(t *testing.T) {
|
||||
statusCode, err := th.Client.TriggerNotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{})
|
||||
|
||||
require.Error(t, err)
|
||||
require.Equal(t, ": You do not have the appropriate permissions.", err.Error())
|
||||
require.Equal(t, "You do not have the appropriate permissions.", err.Error())
|
||||
require.Equal(t, http.StatusForbidden, statusCode)
|
||||
})
|
||||
|
||||
|
||||
@@ -1270,7 +1270,7 @@ func TestPatchPost(t *testing.T) {
|
||||
|
||||
t.Run("invalid requests", func(t *testing.T) {
|
||||
r, err := client.DoAPIPut(context.Background(), "/posts/"+post.Id+"/patch", "garbage")
|
||||
require.EqualError(t, err, ": Invalid or missing post in request body., invalid character 'g' looking for beginning of value")
|
||||
require.EqualError(t, err, "Invalid or missing post in request body., invalid character 'g' looking for beginning of value")
|
||||
require.Equal(t, http.StatusBadRequest, r.StatusCode, "wrong status code")
|
||||
|
||||
patch := &model.PostPatch{}
|
||||
|
||||
@@ -947,7 +947,7 @@ func requireGroupAccess(c *web.Context, groupID string) *model.AppError {
|
||||
|
||||
if group.Source == model.GroupSourceLdap {
|
||||
if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionSysconsoleReadUserManagementGroups) {
|
||||
return c.App.MakePermissionError(c.AppContext.Session(), []*model.Permission{model.PermissionSysconsoleReadUserManagementGroups})
|
||||
return model.MakePermissionError(c.AppContext.Session(), []*model.Permission{model.PermissionSysconsoleReadUserManagementGroups})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2283,7 +2283,7 @@ func TestDeleteBotUser(t *testing.T) {
|
||||
|
||||
_, err := th.Client.DeleteUser(context.Background(), bot.UserId)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, err.Error(), ": You do not have the appropriate permissions.")
|
||||
require.Equal(t, err.Error(), "You do not have the appropriate permissions.")
|
||||
}
|
||||
|
||||
func TestPermanentDeleteUser(t *testing.T) {
|
||||
@@ -2630,16 +2630,16 @@ func TestGetUsers(t *testing.T) {
|
||||
// Check role params validity
|
||||
_, _, err = client.GetUsersWithCustomQueryParameters(context.Background(), 0, 5, "in_channel=random_channel_id&channel_roles=random_role_doesnt_exist", "")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, err.Error(), ": Invalid or missing channelRoles in request body.")
|
||||
require.Equal(t, err.Error(), "Invalid or missing channelRoles in request body.")
|
||||
_, _, err = client.GetUsersWithCustomQueryParameters(context.Background(), 0, 5, "in_team=random_channel_id&team_roles=random_role_doesnt_exist", "")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, err.Error(), ": Invalid or missing teamRoles in request body.")
|
||||
require.Equal(t, err.Error(), "Invalid or missing teamRoles in request body.")
|
||||
_, _, err = client.GetUsersWithCustomQueryParameters(context.Background(), 0, 5, "roles=random_role_doesnt_exist%2Csystem_user", "")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, err.Error(), ": Invalid or missing roles in request body.")
|
||||
require.Equal(t, err.Error(), "Invalid or missing roles in request body.")
|
||||
_, _, err = client.GetUsersWithCustomQueryParameters(context.Background(), 0, 5, "role=random_role_doesnt_exist", "")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, err.Error(), ": Invalid or missing role in request body.")
|
||||
require.Equal(t, err.Error(), "Invalid or missing role in request body.")
|
||||
})
|
||||
|
||||
th.Client.Logout(context.Background())
|
||||
|
||||
Ссылка в новой задаче
Block a user