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

Этот коммит содержится в:
Antonis Stamatiou
2023-11-17 14:37:09 +02:00
коммит произвёл GitHub
родитель 34ce0d00d4
Коммит 926142ca22
2 изменённых файлов: 8 добавлений и 98 удалений

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

@@ -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 {