mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Storage: add global resources/system (#53000)
Co-authored-by: nmarrs <nathanielmarrs@gmail.com>
This commit is contained in:
parent
27709adac3
commit
08dabfaffc
@ -13,7 +13,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@ -284,13 +283,10 @@ func (s *standardStorageService) getConfig(c *models.ReqContext) response.Respon
|
||||
orgId := c.OrgId
|
||||
t := s.tree
|
||||
t.assureOrgIsInitialized(orgId)
|
||||
for _, f := range t.rootsByOrgId[ac.GlobalOrgID] {
|
||||
roots = append(roots, f.Meta())
|
||||
}
|
||||
if orgId != ac.GlobalOrgID {
|
||||
for _, f := range t.rootsByOrgId[orgId] {
|
||||
roots = append(roots, f.Meta())
|
||||
}
|
||||
|
||||
storages := t.getStorages(orgId)
|
||||
for _, s := range storages {
|
||||
roots = append(roots, s.Meta())
|
||||
}
|
||||
return response.JSON(200, roots)
|
||||
}
|
||||
|
@ -40,8 +40,8 @@ const brandingStorage = "branding"
|
||||
const SystemBrandingStorage = "system/" + brandingStorage
|
||||
|
||||
var (
|
||||
SystemBrandingReader = &models.SignedInUser{OrgId: 1}
|
||||
SystemBrandingAdmin = &models.SignedInUser{OrgId: 1}
|
||||
SystemBrandingReader = &models.SignedInUser{OrgId: ac.GlobalOrgID}
|
||||
SystemBrandingAdmin = &models.SignedInUser{OrgId: ac.GlobalOrgID}
|
||||
)
|
||||
|
||||
const MAX_UPLOAD_SIZE = 1 * 1024 * 1024 // 3MB
|
||||
@ -179,6 +179,8 @@ func ProvideService(
|
||||
return storages
|
||||
}
|
||||
|
||||
globalRoots = append(globalRoots, initializeOrgStorages(ac.GlobalOrgID)...)
|
||||
|
||||
authService := newStaticStorageAuthService(func(ctx context.Context, user *models.SignedInUser, storageName string) map[string]filestorage.PathFilter {
|
||||
// Public is OK to read regardless of user settings
|
||||
if storageName == RootPublicStatic {
|
||||
|
@ -89,15 +89,40 @@ func (t *nestedTree) GetFile(ctx context.Context, orgId int64, path string) (*fi
|
||||
return store.Get(ctx, path)
|
||||
}
|
||||
|
||||
func (t *nestedTree) getStorages(orgId int64) []storageRuntime {
|
||||
globalStorages := make([]storageRuntime, 0)
|
||||
globalStorages = append(globalStorages, t.rootsByOrgId[ac.GlobalOrgID]...)
|
||||
|
||||
if orgId == ac.GlobalOrgID {
|
||||
return globalStorages
|
||||
}
|
||||
|
||||
orgPrefixes := make(map[string]bool)
|
||||
storages := make([]storageRuntime, 0)
|
||||
|
||||
for _, s := range t.rootsByOrgId[orgId] {
|
||||
storages = append(storages, s)
|
||||
orgPrefixes[s.Meta().Config.Prefix] = true
|
||||
}
|
||||
|
||||
for _, s := range globalStorages {
|
||||
// prefer org-specific storage over global with the same prefix
|
||||
if ok := orgPrefixes[s.Meta().Config.Prefix]; !ok {
|
||||
storages = append(storages, s)
|
||||
}
|
||||
}
|
||||
|
||||
return storages
|
||||
}
|
||||
|
||||
func (t *nestedTree) ListFolder(ctx context.Context, orgId int64, path string, accessFilter filestorage.PathFilter) (*StorageListFrame, error) {
|
||||
if path == "" || path == "/" {
|
||||
t.assureOrgIsInitialized(orgId)
|
||||
|
||||
idx := 0
|
||||
count := len(t.rootsByOrgId[ac.GlobalOrgID])
|
||||
if orgId != ac.GlobalOrgID {
|
||||
count += len(t.rootsByOrgId[orgId])
|
||||
}
|
||||
|
||||
storages := t.getStorages(orgId)
|
||||
count := len(storages)
|
||||
|
||||
names := data.NewFieldFromFieldType(data.FieldTypeString, count)
|
||||
title := data.NewFieldFromFieldType(data.FieldTypeString, count)
|
||||
@ -107,7 +132,7 @@ func (t *nestedTree) ListFolder(ctx context.Context, orgId int64, path string, a
|
||||
names.Name = nameListFrameField
|
||||
descr.Name = descriptionListFrameField
|
||||
mtype.Name = mediaTypeListFrameField
|
||||
for _, f := range t.rootsByOrgId[ac.GlobalOrgID] {
|
||||
for _, f := range storages {
|
||||
meta := f.Meta()
|
||||
names.Set(idx, meta.Config.Prefix)
|
||||
title.Set(idx, meta.Config.Name)
|
||||
@ -115,16 +140,6 @@ func (t *nestedTree) ListFolder(ctx context.Context, orgId int64, path string, a
|
||||
mtype.Set(idx, "directory")
|
||||
idx++
|
||||
}
|
||||
if orgId != ac.GlobalOrgID {
|
||||
for _, f := range t.rootsByOrgId[orgId] {
|
||||
meta := f.Meta()
|
||||
names.Set(idx, meta.Config.Prefix)
|
||||
title.Set(idx, meta.Config.Name)
|
||||
descr.Set(idx, meta.Config.Description)
|
||||
mtype.Set(idx, "directory")
|
||||
idx++
|
||||
}
|
||||
}
|
||||
|
||||
frame := data.NewFrame("", names, title, descr, mtype)
|
||||
frame.SetMeta(&data.FrameMeta{
|
||||
|
Loading…
Reference in New Issue
Block a user