mirror of
https://github.com/grafana/grafana.git
synced 2026-08-13 06:34:55 -05:00
NavTree: Make it possible to configure where in nav tree plugins live (#55484)
* NewIA: Plugin nav config * progress * Progress * Things are working * Add monitoring node * Add alerts and incidents * added experiment with standalone page * Refactoring by adding a type for navtree root * First test working * More tests * more tests * Progress on richer config and sorting * Sort weight working * Path config * Improving logic for not including admin or cfg nodes, making it the last step so that enterprise can add admin nodes without having to worry about the section not existing * fixed index routes * removed file * Fixes * Fixing tests * Fixing more tests and adding support for weight config * Updates * Remove unused fake * More fixes * Minor tweak * Minor fix * Can now control position using sortweight even when existing items have no sortweight * Added tests for frontend standalone page logic * more tests * Remove unused fake and fixed lint issue * Moving reading settings to navtree impl package * remove nav_id setting prefix * Remove old test file * Fix trailing newline * Fixed bug with adding nil node * fixing lint issue * remove some code we have to rethink * move read settings to PrivideService and switch to util.SplitString
This commit is contained in:
@@ -2,11 +2,8 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsettings"
|
||||
)
|
||||
|
||||
type fakePluginInstaller struct {
|
||||
@@ -37,34 +34,6 @@ func (pm *fakePluginInstaller) Remove(_ context.Context, pluginID string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
type fakePluginStore struct {
|
||||
plugins.Store
|
||||
|
||||
plugins map[string]plugins.PluginDTO
|
||||
}
|
||||
|
||||
func (pr fakePluginStore) Plugin(_ context.Context, pluginID string) (plugins.PluginDTO, bool) {
|
||||
p, exists := pr.plugins[pluginID]
|
||||
|
||||
return p, exists
|
||||
}
|
||||
|
||||
func (pr fakePluginStore) Plugins(_ context.Context, pluginTypes ...plugins.Type) []plugins.PluginDTO {
|
||||
var result []plugins.PluginDTO
|
||||
if len(pluginTypes) == 0 {
|
||||
pluginTypes = plugins.PluginTypes
|
||||
}
|
||||
for _, v := range pr.plugins {
|
||||
for _, t := range pluginTypes {
|
||||
if v.Type == t {
|
||||
result = append(result, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
type fakeRendererManager struct {
|
||||
plugins.RendererManager
|
||||
}
|
||||
@@ -82,72 +51,3 @@ type fakePluginStaticRouteResolver struct {
|
||||
func (psrr *fakePluginStaticRouteResolver) Routes() []*plugins.StaticRoute {
|
||||
return psrr.routes
|
||||
}
|
||||
|
||||
type fakePluginSettings struct {
|
||||
pluginsettings.Service
|
||||
|
||||
plugins map[string]*pluginsettings.DTO
|
||||
}
|
||||
|
||||
// GetPluginSettings returns all Plugin Settings for the provided Org
|
||||
func (ps *fakePluginSettings) GetPluginSettings(_ context.Context, _ *pluginsettings.GetArgs) ([]*pluginsettings.InfoDTO, error) {
|
||||
res := []*pluginsettings.InfoDTO{}
|
||||
for _, dto := range ps.plugins {
|
||||
res = append(res, &pluginsettings.InfoDTO{
|
||||
PluginID: dto.PluginID,
|
||||
OrgID: dto.OrgID,
|
||||
Enabled: dto.Enabled,
|
||||
Pinned: dto.Pinned,
|
||||
PluginVersion: dto.PluginVersion,
|
||||
})
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// GetPluginSettingByPluginID returns a Plugin Settings by Plugin ID
|
||||
func (ps *fakePluginSettings) GetPluginSettingByPluginID(ctx context.Context, args *pluginsettings.GetByPluginIDArgs) (*pluginsettings.DTO, error) {
|
||||
if res, ok := ps.plugins[args.PluginID]; ok {
|
||||
return res, nil
|
||||
}
|
||||
return nil, models.ErrPluginSettingNotFound
|
||||
}
|
||||
|
||||
// UpdatePluginSetting updates a Plugin Setting
|
||||
func (ps *fakePluginSettings) UpdatePluginSetting(ctx context.Context, args *pluginsettings.UpdateArgs) error {
|
||||
var secureData map[string][]byte
|
||||
if args.SecureJSONData != nil {
|
||||
secureData := map[string][]byte{}
|
||||
for k, v := range args.SecureJSONData {
|
||||
secureData[k] = ([]byte)(v)
|
||||
}
|
||||
}
|
||||
// save
|
||||
ps.plugins[args.PluginID] = &pluginsettings.DTO{
|
||||
ID: int64(len(ps.plugins)),
|
||||
OrgID: args.OrgID,
|
||||
PluginID: args.PluginID,
|
||||
PluginVersion: args.PluginVersion,
|
||||
JSONData: args.JSONData,
|
||||
SecureJSONData: secureData,
|
||||
Enabled: args.Enabled,
|
||||
Pinned: args.Pinned,
|
||||
Updated: time.Now(),
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdatePluginSettingPluginVersion updates a Plugin Setting's plugin version
|
||||
func (ps *fakePluginSettings) UpdatePluginSettingPluginVersion(ctx context.Context, args *pluginsettings.UpdatePluginVersionArgs) error {
|
||||
if res, ok := ps.plugins[args.PluginID]; ok {
|
||||
res.PluginVersion = args.PluginVersion
|
||||
return nil
|
||||
}
|
||||
return models.ErrPluginSettingNotFound
|
||||
}
|
||||
|
||||
// DecryptedValues decrypts the encrypted secureJSONData of the provided plugin setting and
|
||||
// returns the decrypted values.
|
||||
func (ps *fakePluginSettings) DecryptedValues(dto *pluginsettings.DTO) map[string]string {
|
||||
// TODO: Implement
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user