[GH-16199] add IsValid to model OpenDialogRequest (#26526)

* [GH-16199] add IsValid to model OpenDialogRequest

* [GH-16199] add IsValid to model OpenDialogRequest, revert remove of translations

* [GH-16199] fix tests after revert

* [GH-16199] add IsValid to model OpenDialogRequest

* [GH-16199] revert validation of icon url

* [GH-16199] update go sum

* [GH-16199] log warning for invalid dialog

* [GH-16199] log error for invalid dialog

* [GH-16199] log warning for invalid dialog

* [GH-16199] fix golang-ci

---------

Co-authored-by: Lukas Eipert <git@leipert.io>
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Anna Os
2024-04-30 18:27:07 +02:00
коммит произвёл GitHub
родитель b70e657271
Коммит 48b047aa0c
10 изменённых файлов: 408 добавлений и 8 удалений

Просмотреть файл

@@ -84,7 +84,7 @@ func openDialog(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if appErr := c.App.OpenInteractiveDialog(dialog); appErr != nil {
if appErr := c.App.OpenInteractiveDialog(c.AppContext, dialog); appErr != nil {
c.Err = appErr
return
}

Просмотреть файл

@@ -16,6 +16,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog"
"github.com/mattermost/mattermost/server/v8/channels/testlib"
)
type testHandler struct {
@@ -209,6 +211,53 @@ func TestOpenDialog(t *testing.T) {
require.NoError(t, err)
})
t.Run("Should pass with too long display name of elements", func(t *testing.T) {
request.Dialog.Elements = []model.DialogElement{
{
DisplayName: "Very very long Element Name",
Name: "element_name",
Type: "text",
Placeholder: "Enter a value",
},
}
buffer := &mlog.Buffer{}
err := mlog.AddWriterTarget(th.TestLogger, buffer, true, mlog.StdAll...)
require.NoError(t, err)
_, err = client.OpenInteractiveDialog(context.Background(), request)
require.NoError(t, err)
require.NoError(t, th.TestLogger.Flush())
testlib.AssertLog(t, buffer, mlog.LvlWarn.Name, "Interactive dialog is invalid")
})
t.Run("Should pass with same elements", func(t *testing.T) {
request.Dialog.Elements = []model.DialogElement{
{
DisplayName: "Element Name",
Name: "element_name",
Type: "text",
Placeholder: "Enter a value",
},
{
DisplayName: "Element Name",
Name: "element_name",
Type: "text",
Placeholder: "Enter a value",
},
}
buffer := &mlog.Buffer{}
err := mlog.AddWriterTarget(th.TestLogger, buffer, true, mlog.StdAll...)
require.NoError(t, err)
_, err = client.OpenInteractiveDialog(context.Background(), request)
require.NoError(t, err)
require.NoError(t, th.TestLogger.Flush())
testlib.AssertLog(t, buffer, mlog.LvlWarn.Name, "Interactive dialog is invalid")
})
t.Run("Should pass with nil elements slice", func(t *testing.T) {
request.Dialog.Elements = nil
_, err := client.OpenInteractiveDialog(context.Background(), request)

Просмотреть файл

@@ -967,7 +967,7 @@ type AppIface interface {
NotificationsLog() *mlog.Logger
NotifySelfHostedSignupProgress(progress string, userId string)
NotifySharedChannelUserUpdate(user *model.User)
OpenInteractiveDialog(request model.OpenDialogRequest) *model.AppError
OpenInteractiveDialog(c request.CTX, request model.OpenDialogRequest) *model.AppError
OriginChecker() func(*http.Request) bool
OutgoingOAuthConnections() einterfaces.OutgoingOAuthConnectionInterface
PatchChannel(c request.CTX, channel *model.Channel, patch *model.ChannelPatch, userID string) (*model.Channel, *model.AppError)

Просмотреть файл

@@ -453,13 +453,17 @@ func (a *App) DoLocalRequest(c request.CTX, rawURL string, body []byte) (*http.R
return a.doPluginRequest(c, "POST", rawURL, nil, body)
}
func (a *App) OpenInteractiveDialog(request model.OpenDialogRequest) *model.AppError {
func (a *App) OpenInteractiveDialog(c request.CTX, request model.OpenDialogRequest) *model.AppError {
timeout := time.Duration(*a.Config().ServiceSettings.OutgoingIntegrationRequestsTimeout) * time.Second
clientTriggerId, userID, appErr := request.DecodeAndVerifyTriggerId(a.AsymmetricSigningKey(), timeout)
if appErr != nil {
return appErr
}
if dialogErr := request.IsValid(); dialogErr != nil {
c.Logger().Warn("Interactive dialog is invalid", mlog.Err(dialogErr))
}
request.TriggerId = clientTriggerId
jsonRequest, err := json.Marshal(request)

Просмотреть файл

@@ -13181,7 +13181,7 @@ func (a *OpenTracingAppLayer) OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *mo
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) OpenInteractiveDialog(request model.OpenDialogRequest) *model.AppError {
func (a *OpenTracingAppLayer) OpenInteractiveDialog(c request.CTX, request model.OpenDialogRequest) *model.AppError {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.OpenInteractiveDialog")
@@ -13193,7 +13193,7 @@ func (a *OpenTracingAppLayer) OpenInteractiveDialog(request model.OpenDialogRequ
}()
defer span.Finish()
resultVar0 := a.app.OpenInteractiveDialog(request)
resultVar0 := a.app.OpenInteractiveDialog(c, request)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))

Просмотреть файл

@@ -849,7 +849,7 @@ func (api *PluginAPI) SetTeamIcon(teamID string, data []byte) *model.AppError {
}
func (api *PluginAPI) OpenInteractiveDialog(dialog model.OpenDialogRequest) *model.AppError {
return api.app.OpenInteractiveDialog(dialog)
return api.app.OpenInteractiveDialog(api.ctx, dialog)
}
func (api *PluginAPI) RemoveTeamIcon(teamID string) *model.AppError {