Footer: Display Grafana edition (#21717)
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
co-authored by
Torkel Ödegaard
parent
84ef0ebb17
commit
3fabbbff4d
@@ -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",
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user