Commit 3fabbbff by Emil Tullstedt Committed by GitHub

Footer: Display Grafana edition (#21717)


Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
parent 84ef0ebb
......@@ -7,6 +7,7 @@ export interface BuildInfo {
commit: string;
isEnterprise: boolean; // deprecated: use licenseInfo.hasLicense instead
env: string;
edition: string;
latestVersion: string;
hasUpdate: boolean;
}
......@@ -21,6 +22,8 @@ interface FeatureToggles {
interface LicenseInfo {
hasLicense: boolean;
expiry: number;
licenseUrl: string;
stateInfo: string;
}
export class GrafanaBootConfig {
......
......@@ -194,6 +194,7 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf
"version": setting.BuildVersion,
"commit": setting.BuildCommit,
"buildstamp": setting.BuildStamp,
"edition": hs.License.Edition(),
"latestVersion": plugins.GrafanaLatestVersion,
"hasUpdate": plugins.GrafanaHasUpdate,
"env": setting.Env,
......@@ -202,6 +203,8 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf
"licenseInfo": map[string]interface{}{
"hasLicense": hs.License.HasLicense(),
"expiry": hs.License.Expiry(),
"stateInfo": hs.License.StateInfo(),
"licenseUrl": hs.License.LicenseURL(c.SignedInUser),
},
"featureToggles": hs.Cfg.FeatureToggles,
}
......
......@@ -357,7 +357,7 @@ func (hs *HTTPServer) setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, er
Children: []*dtos.NavLink{},
})
hs.HooksService.RunIndexDataHooks(&data)
hs.HooksService.RunIndexDataHooks(&data, c)
sort.SliceStable(data.NavTree, func(i, j int) bool {
return data.NavTree[i].SortWeight < data.NavTree[j].SortWeight
......
......@@ -9,4 +9,11 @@ type Licensing interface {
// Expiry returns the unix epoch timestamp when the license expires, or 0 if no valid license is provided
Expiry() int64
// Return edition
Edition() string
LicenseURL(user *SignedInUser) string
StateInfo() string
}
......@@ -2,10 +2,11 @@ package hooks
import (
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/registry"
)
type IndexDataHook func(indexData *dtos.IndexViewData)
type IndexDataHook func(indexData *dtos.IndexViewData, req *models.ReqContext)
type HooksService struct {
indexDataHooks []IndexDataHook
......@@ -23,8 +24,8 @@ func (srv *HooksService) AddIndexDataHook(hook IndexDataHook) {
srv.indexDataHooks = append(srv.indexDataHooks, hook)
}
func (srv *HooksService) RunIndexDataHooks(indexData *dtos.IndexViewData) {
func (srv *HooksService) RunIndexDataHooks(indexData *dtos.IndexViewData, req *models.ReqContext) {
for _, hook := range srv.indexDataHooks {
hook(indexData)
hook(indexData, req)
}
}
......@@ -2,6 +2,7 @@ package licensing
import (
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/hooks"
"github.com/grafana/grafana/pkg/setting"
)
......@@ -19,14 +20,30 @@ func (*OSSLicensingService) Expiry() int64 {
return 0
}
func (*OSSLicensingService) Edition() string {
return "Open Source"
}
func (*OSSLicensingService) StateInfo() string {
return ""
}
func (l *OSSLicensingService) LicenseURL(user *models.SignedInUser) string {
if user.IsGrafanaAdmin {
return l.Cfg.AppSubUrl + "/admin/upgrading"
}
return "https://grafana.com/products/enterprise/?utm_source=grafana_footer"
}
func (l *OSSLicensingService) Init() error {
l.HooksService.AddIndexDataHook(func(indexData *dtos.IndexViewData) {
l.HooksService.AddIndexDataHook(func(indexData *dtos.IndexViewData, req *models.ReqContext) {
for _, node := range indexData.NavTree {
if node.Id == "admin" {
node.Children = append(node.Children, &dtos.NavLink{
Text: "Upgrade",
Id: "upgrading",
Url: l.Cfg.AppSubUrl + "/admin/upgrading",
Url: l.LicenseURL(req.SignedInUser),
Icon: "fa fa-fw fa-unlock-alt",
})
}
......
......@@ -36,11 +36,10 @@ const (
)
const (
DEV = "development"
PROD = "production"
TEST = "test"
APP_NAME = "Grafana"
APP_NAME_ENTERPRISE = "Grafana Enterprise"
DEV = "development"
PROD = "production"
TEST = "test"
APP_NAME = "Grafana"
)
var (
......@@ -619,9 +618,6 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
Raw = cfg.Raw
ApplicationName = APP_NAME
if IsEnterprise {
ApplicationName = APP_NAME_ENTERPRISE
}
Env, err = valueAsString(iniFile.Section(""), "app_mode", "development")
if err != nil {
......
......@@ -5,7 +5,7 @@ export interface FooterLink {
text: string;
icon?: string;
url?: string;
target: string;
target?: string;
}
export let getFooterLinks = (): FooterLink[] => {
......@@ -17,7 +17,7 @@ export let getFooterLinks = (): FooterLink[] => {
target: '_blank',
},
{
text: 'Support & Enterprise',
text: 'Support',
icon: 'fa fa-support',
url: 'https://grafana.com/products/enterprise/?utm_source=grafana_footer',
target: '_blank',
......@@ -32,15 +32,12 @@ export let getFooterLinks = (): FooterLink[] => {
};
export let getVersionLinks = (): FooterLink[] => {
const { buildInfo } = config;
const { buildInfo, licenseInfo } = config;
const links: FooterLink[] = [];
const stateInfo = licenseInfo.stateInfo ? ` (${licenseInfo.stateInfo})` : '';
const links: FooterLink[] = [
{
text: `Grafana v${buildInfo.version} (commit: ${buildInfo.commit})`,
url: 'https://grafana.com',
target: '_blank',
},
];
links.push({ text: `${buildInfo.edition}${stateInfo}`, url: licenseInfo.licenseUrl });
links.push({ text: `v${buildInfo.version} (${buildInfo.commit})` });
if (buildInfo.hasUpdate) {
links.push({
......
......@@ -180,7 +180,7 @@ exports[`ServerStats Should render table with stats 1`] = `
className="fa fa-support"
/>
Support & Enterprise
Support
</a>
</li>
<li>
......@@ -198,13 +198,22 @@ exports[`ServerStats Should render table with stats 1`] = `
</li>
<li>
<a
href="https://grafana.com"
rel="noopener"
target="_blank"
>
<i />
Grafana vv1.0 (commit: 1)
undefined
</a>
</li>
<li>
<a
rel="noopener"
target="_blank"
>
<i />
vv1.0 (1)
</a>
</li>
</ul>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment