fix: Use version instead of build number for notices (#25435)

This commit is contained in:
Antonis Stamatiou 2023-11-17 14:37:09 +02:00 committed by GitHub
parent 34ce0d00d4
commit 926142ca22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 98 deletions

View File

@ -6,8 +6,6 @@ package app
import (
"net/http"
"reflect"
"regexp"
"strconv"
"strings"
"time"
@ -29,22 +27,6 @@ const MinSecondsBetweenRepeatViewings = 60 * 60
// http request cache
var noticesCache = utils.RequestCache{}
var rcStripRegexp = regexp.MustCompile(`(.*?)(-rc\d+)(.*?)`)
func cleanupVersion(originalVersion string) string {
// clean up BuildNumber to remove release- prefix, -rc suffix and a hash part of the version
version := strings.Replace(originalVersion, "release-", "", 1)
version = rcStripRegexp.ReplaceAllString(version, `$1$3`)
versionParts := strings.Split(version, ".")
var versionPartsOut []string
for _, part := range versionParts {
if _, err := strconv.ParseInt(part, 10, 16); err == nil {
versionPartsOut = append(versionPartsOut, part)
}
}
return strings.Join(versionPartsOut, ".")
}
func noticeMatchesConditions(config *model.Config, preferences store.PreferenceStore, userID string,
client model.NoticeClientType, clientVersion string, postCount int64, userCount int64, isSystemAdmin bool,
isTeamAdmin bool, isCloud bool, sku, dbName, dbVer, searchEngineName, searchEngineVer string,
@ -94,10 +76,9 @@ func noticeMatchesConditions(config *model.Config, preferences store.PreferenceS
// check if current server version is notice range
if !isCloud && cnd.ServerVersion != nil {
version := cleanupVersion(model.BuildNumber)
serverVersion, err := semver.NewVersion(version)
serverVersion, err := semver.NewVersion(model.CurrentVersion)
if err != nil {
mlog.Warn("Build number is not in semver format", mlog.String("build_number", version))
mlog.Warn("Version number is not in semver format", mlog.String("version_number", model.CurrentVersion))
return false, nil
}
for _, v := range cnd.ServerVersion {

View File

@ -217,7 +217,6 @@ func TestNoticeValidation(t *testing.T) {
wantErr: false,
wantOk: true,
},
{
name: "notice with server version check that matches a const",
args: args{
@ -231,77 +230,6 @@ func TestNoticeValidation(t *testing.T) {
wantErr: false,
wantOk: true,
},
{
name: "notice with server version check that has rc",
args: args{
serverVersion: "99.1.1-rc2",
notice: &model.ProductNotice{
Conditions: model.Conditions{
ServerVersion: []string{"> 99.0.0 < 100.2.2"},
},
},
},
wantErr: false,
wantOk: true,
},
{
name: "notice with server version check that has rc and hash",
args: args{
serverVersion: "99.1.1-rc2.abcdef",
notice: &model.ProductNotice{
Conditions: model.Conditions{
ServerVersion: []string{"> 99.0.0 < 100.2.2"},
},
},
},
wantErr: false,
wantOk: true,
},
{
name: "notice with server version check that has release and hash",
args: args{
serverVersion: "release-99.1.1.abcdef",
notice: &model.ProductNotice{
Conditions: model.Conditions{
ServerVersion: []string{"> 99.0.0 < 100.2.2"},
},
},
},
wantErr: false,
wantOk: true,
},
{
name: "notice with server version check that has cloud version",
args: args{
serverVersion: "cloud.54.abcdef",
notice: &model.ProductNotice{
Conditions: model.Conditions{
ServerVersion: []string{"> 99.0.0 < 100.2.2"},
},
},
},
wantErr: false,
wantOk: false,
},
{
name: "notice with server version check on cloud should ignore version",
args: args{
cloud: true,
serverVersion: "cloud.54.abcdef",
notice: &model.ProductNotice{
Conditions: model.Conditions{
ServerVersion: []string{"> 99.0.0 < 100.2.2"},
},
},
},
wantErr: false,
wantOk: true,
},
{
name: "notice with server version check that is invalid",
args: args{
@ -565,7 +493,7 @@ func TestNoticeValidation(t *testing.T) {
args: args{
dbmsName: "mysql",
dbmsVer: "5.6",
serverVersion: "5.32",
serverVersion: "5.32.1",
notice: &model.ProductNotice{
Conditions: model.Conditions{
ServerVersion: []string{">=v5.33"},
@ -637,11 +565,12 @@ func TestNoticeValidation(t *testing.T) {
if clientVersion == "" {
clientVersion = "1.2.3"
}
model.BuildNumber = tt.args.serverVersion
if model.BuildNumber == "" {
model.BuildNumber = "5.26.1"
model.CurrentVersion = tt.args.serverVersion
if model.CurrentVersion == "" {
model.CurrentVersion = "5.26.1"
defer func() {
model.BuildNumber = ""
model.CurrentVersion = ""
}()
}
if ok, err := noticeMatchesConditions(