mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Whitelabelling: Override version in UI from config (#84392)
* Unify how the version is shown in the UI * use versionString in dashboard help bundles * fix lint * remove comment * fix test types * make test less flakey
This commit is contained in:
@@ -35,9 +35,16 @@ type FrontendSettingsAuthDTO struct {
|
||||
}
|
||||
|
||||
type FrontendSettingsBuildInfoDTO struct {
|
||||
HideVersion bool `json:"hideVersion"`
|
||||
Version string `json:"version"`
|
||||
HideVersion bool `json:"hideVersion"`
|
||||
|
||||
// A semver-ish version string, such as "11.0.0-12345"
|
||||
Version string `json:"version"`
|
||||
|
||||
// A branded version string to show in the UI, such as "Grafana v11.0.0-12345"
|
||||
VersionString string `json:"versionString,omitempty"`
|
||||
|
||||
Commit string `json:"commit"`
|
||||
CommitShort string `json:"commitShort"`
|
||||
Buildstamp int64 `json:"buildstamp"`
|
||||
Edition string `json:"edition"`
|
||||
LatestVersion string `json:"latestVersion"`
|
||||
|
@@ -152,11 +152,15 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
|
||||
hideVersion := hs.Cfg.AnonymousHideVersion && !c.IsSignedIn
|
||||
version := setting.BuildVersion
|
||||
commit := setting.BuildCommit
|
||||
commitShort := getShortCommitHash(setting.BuildCommit, 10)
|
||||
buildstamp := setting.BuildStamp
|
||||
versionString := fmt.Sprintf(`%s v%s (%s)`, setting.ApplicationName, version, commitShort)
|
||||
|
||||
if hideVersion {
|
||||
version = ""
|
||||
versionString = setting.ApplicationName
|
||||
commit = ""
|
||||
commitShort = ""
|
||||
buildstamp = 0
|
||||
}
|
||||
|
||||
@@ -226,7 +230,9 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
|
||||
BuildInfo: dtos.FrontendSettingsBuildInfoDTO{
|
||||
HideVersion: hideVersion,
|
||||
Version: version,
|
||||
VersionString: versionString,
|
||||
Commit: commit,
|
||||
CommitShort: commitShort,
|
||||
Buildstamp: buildstamp,
|
||||
Edition: hs.License.Edition(),
|
||||
LatestVersion: hs.grafanaUpdateChecker.LatestVersion(),
|
||||
@@ -367,6 +373,13 @@ func isSupportBundlesEnabled(hs *HTTPServer) bool {
|
||||
return hs.Cfg.SectionWithEnvOverrides("support_bundles").Key("enabled").MustBool(true)
|
||||
}
|
||||
|
||||
func getShortCommitHash(commitHash string, maxLength int) string {
|
||||
if len(commitHash) > maxLength {
|
||||
return commitHash[:maxLength]
|
||||
}
|
||||
return commitHash
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) getFSDataSources(c *contextmodel.ReqContext, availablePlugins AvailablePlugins) (map[string]plugins.DataSourceDTO, error) {
|
||||
orgDataSources := make([]*datasources.DataSource, 0)
|
||||
if c.SignedInUser.GetOrgID() != 0 {
|
||||
|
@@ -161,6 +161,7 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV
|
||||
hs.HooksService.RunIndexDataHooks(&data, c)
|
||||
|
||||
data.NavTree.ApplyAdminIA()
|
||||
data.NavTree.ApplyHelpVersion(data.Settings.BuildInfo.VersionString) // RunIndexDataHooks can modify the version string
|
||||
data.NavTree.Sort()
|
||||
|
||||
return &data, nil
|
||||
|
@@ -127,6 +127,14 @@ func Sort(nodes []*NavLink) {
|
||||
}
|
||||
}
|
||||
|
||||
func (root *NavTreeRoot) ApplyHelpVersion(version string) {
|
||||
helpNode := root.FindById("help")
|
||||
|
||||
if helpNode != nil {
|
||||
helpNode.SubTitle = version
|
||||
}
|
||||
}
|
||||
|
||||
func (root *NavTreeRoot) ApplyAdminIA() {
|
||||
orgAdminNode := root.FindById(NavIDCfg)
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package navtreeimpl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
@@ -188,25 +187,11 @@ func isSupportBundlesEnabled(s *ServiceImpl) bool {
|
||||
return s.cfg.SectionWithEnvOverrides("support_bundles").Key("enabled").MustBool(true)
|
||||
}
|
||||
|
||||
// don't need to show the full commit hash in the UI
|
||||
// let's substring to 10 chars like local git does automatically
|
||||
func getShortCommitHash(commitHash string, maxLength int) string {
|
||||
if len(commitHash) > maxLength {
|
||||
return commitHash[:maxLength]
|
||||
}
|
||||
return commitHash
|
||||
}
|
||||
|
||||
func (s *ServiceImpl) addHelpLinks(treeRoot *navtree.NavTreeRoot, c *contextmodel.ReqContext) {
|
||||
if s.cfg.HelpEnabled {
|
||||
helpVersion := fmt.Sprintf(`%s v%s (%s)`, setting.ApplicationName, setting.BuildVersion, getShortCommitHash(setting.BuildCommit, 10))
|
||||
if s.cfg.AnonymousHideVersion && !c.IsSignedIn {
|
||||
helpVersion = setting.ApplicationName
|
||||
}
|
||||
|
||||
// The version subtitle is set later by NavTree.ApplyHelpVersion
|
||||
helpNode := &navtree.NavLink{
|
||||
Text: "Help",
|
||||
SubTitle: helpVersion,
|
||||
Id: "help",
|
||||
Url: "#",
|
||||
Icon: "question-circle",
|
||||
|
Reference in New Issue
Block a user