fix: Use version instead of build number for notices (#25435)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
34ce0d00d4
Коммит
926142ca22
@@ -6,8 +6,6 @@ package app
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -29,22 +27,6 @@ const MinSecondsBetweenRepeatViewings = 60 * 60
|
|||||||
// http request cache
|
// http request cache
|
||||||
var noticesCache = utils.RequestCache{}
|
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,
|
func noticeMatchesConditions(config *model.Config, preferences store.PreferenceStore, userID string,
|
||||||
client model.NoticeClientType, clientVersion string, postCount int64, userCount int64, isSystemAdmin bool,
|
client model.NoticeClientType, clientVersion string, postCount int64, userCount int64, isSystemAdmin bool,
|
||||||
isTeamAdmin bool, isCloud bool, sku, dbName, dbVer, searchEngineName, searchEngineVer string,
|
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
|
// check if current server version is notice range
|
||||||
if !isCloud && cnd.ServerVersion != nil {
|
if !isCloud && cnd.ServerVersion != nil {
|
||||||
version := cleanupVersion(model.BuildNumber)
|
serverVersion, err := semver.NewVersion(model.CurrentVersion)
|
||||||
serverVersion, err := semver.NewVersion(version)
|
|
||||||
if err != nil {
|
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
|
return false, nil
|
||||||
}
|
}
|
||||||
for _, v := range cnd.ServerVersion {
|
for _, v := range cnd.ServerVersion {
|
||||||
|
|||||||
@@ -217,7 +217,6 @@ func TestNoticeValidation(t *testing.T) {
|
|||||||
wantErr: false,
|
wantErr: false,
|
||||||
wantOk: true,
|
wantOk: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "notice with server version check that matches a const",
|
name: "notice with server version check that matches a const",
|
||||||
args: args{
|
args: args{
|
||||||
@@ -231,77 +230,6 @@ func TestNoticeValidation(t *testing.T) {
|
|||||||
wantErr: false,
|
wantErr: false,
|
||||||
wantOk: true,
|
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",
|
name: "notice with server version check that is invalid",
|
||||||
args: args{
|
args: args{
|
||||||
@@ -565,7 +493,7 @@ func TestNoticeValidation(t *testing.T) {
|
|||||||
args: args{
|
args: args{
|
||||||
dbmsName: "mysql",
|
dbmsName: "mysql",
|
||||||
dbmsVer: "5.6",
|
dbmsVer: "5.6",
|
||||||
serverVersion: "5.32",
|
serverVersion: "5.32.1",
|
||||||
notice: &model.ProductNotice{
|
notice: &model.ProductNotice{
|
||||||
Conditions: model.Conditions{
|
Conditions: model.Conditions{
|
||||||
ServerVersion: []string{">=v5.33"},
|
ServerVersion: []string{">=v5.33"},
|
||||||
@@ -637,11 +565,12 @@ func TestNoticeValidation(t *testing.T) {
|
|||||||
if clientVersion == "" {
|
if clientVersion == "" {
|
||||||
clientVersion = "1.2.3"
|
clientVersion = "1.2.3"
|
||||||
}
|
}
|
||||||
model.BuildNumber = tt.args.serverVersion
|
|
||||||
if model.BuildNumber == "" {
|
model.CurrentVersion = tt.args.serverVersion
|
||||||
model.BuildNumber = "5.26.1"
|
if model.CurrentVersion == "" {
|
||||||
|
model.CurrentVersion = "5.26.1"
|
||||||
defer func() {
|
defer func() {
|
||||||
model.BuildNumber = ""
|
model.CurrentVersion = ""
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
if ok, err := noticeMatchesConditions(
|
if ok, err := noticeMatchesConditions(
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user