From bcb861717ea7b0fd79e48a2c40e5d4b7e722b8c1 Mon Sep 17 00:00:00 2001 From: Eli Yukelzon Date: Wed, 25 Nov 2020 09:30:44 +0200 Subject: [PATCH] MM-30918 Fix product notice check when user setting is missing (#16396) --- app/product_notices.go | 4 ++-- app/product_notices_test.go | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/product_notices.go b/app/product_notices.go index 42fc2afb69..d84c577476 100644 --- a/app/product_notices.go +++ b/app/product_notices.go @@ -19,7 +19,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/pkg/errors" - "github.com/reflog/dateconstraints" + date_constraints "github.com/reflog/dateconstraints" ) const MAX_REPEAT_VIEWINGS = 3 @@ -179,7 +179,7 @@ func validateUserConfigEntry(preferences store.PreferenceStore, userId string, k } pref, err := preferences.Get(userId, parts[0], parts[1]) if err != nil { - return false, err + return false, nil } return pref.Value == expectedValue, nil } diff --git a/app/product_notices_test.go b/app/product_notices_test.go index d483c39aae..c6984cf09c 100644 --- a/app/product_notices_test.go +++ b/app/product_notices_test.go @@ -4,15 +4,17 @@ package app import ( + "errors" "fmt" - "github.com/mattermost/mattermost-server/v5/model" - "github.com/mattermost/mattermost-server/v5/store/storetest/mocks" - "github.com/stretchr/testify/require" "net/http" "net/http/httptest" "strings" "testing" "time" + + "github.com/mattermost/mattermost-server/v5/model" + "github.com/mattermost/mattermost-server/v5/store/storetest/mocks" + "github.com/stretchr/testify/require" ) func TestNoticeValidation(t *testing.T) { @@ -37,6 +39,7 @@ func TestNoticeValidation(t *testing.T) { mockUserStore.On("Count", model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: true, ExcludeRegularUsers: false, TeamId: "", ChannelId: "", ViewRestrictions: (*model.ViewUsersRestrictions)(nil), Roles: []string(nil), ChannelRoles: []string(nil), TeamRoles: []string(nil)}).Return(int64(1), nil) mockPreferenceStore.On("Get", "test", "Stuff", "Data").Return(&model.Preference{Value: "test2"}, nil) mockPreferenceStore.On("Get", "test", "Stuff", "Data2").Return(&model.Preference{Value: "test"}, nil) + mockPreferenceStore.On("Get", "test", "Stuff", "Data3").Return(nil, errors.New("Error!")) mockPostStore.On("GetMaxPostSize").Return(65535, nil) th.App.UpdateConfig(func(cfg *model.Config) { @@ -160,6 +163,18 @@ func TestNoticeValidation(t *testing.T) { wantErr: false, wantOk: true, }, + { + name: "notice with user check for property not in database", + args: args{ + notice: &model.ProductNotice{ + Conditions: model.Conditions{ + UserConfig: map[string]interface{}{"Stuff.Data3": "stuff"}, + }, + }, + }, + wantErr: false, + wantOk: false, + }, { name: "notice with server version check", args: args{