[v10.2.x] Plugins: Don't auto prepend app sub url to plugin asset paths (#82146)
Plugins: Don't auto prepend app sub url to plugin asset paths (#81658)
* don't prepend app sub url to paths
* simplify logo path
* fix(plugins): dynamically prepend appSubUrl for System module resolving to work
* fix(sandbox): support dynamic appSuburl prepend when loading plugin module.js
* fix tests
* update test name
* fix tests
* update fe + add some tests
* refactor(plugins): move wrangleurl to utils, rename to resolveModulePath, update usage
* chore: fix a typo
* test(plugins): add missing name to utils test
* reset test flag
---------
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
(cherry picked from commit 99feb928cf)
Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
This commit is contained in:
co-authored by
Will Browne
parent
147e7b0613
commit
dfb6c28197
@@ -47,12 +47,12 @@ func DefaultService(cfg *config.Cfg) *Service {
|
||||
func (s *Service) Base(n PluginInfo) (string, error) {
|
||||
if n.class == plugins.ClassCore {
|
||||
baseDir := getBaseDir(n.dir)
|
||||
return path.Join("/", s.cfg.GrafanaAppSubURL, "/public/app/plugins", string(n.pluginJSON.Type), baseDir), nil
|
||||
return path.Join("public/app/plugins", string(n.pluginJSON.Type), baseDir), nil
|
||||
}
|
||||
if s.cdn.PluginSupported(n.pluginJSON.ID) {
|
||||
return s.cdn.AssetURL(n.pluginJSON.ID, n.pluginJSON.Info.Version, "")
|
||||
}
|
||||
return path.Join("/", s.cfg.GrafanaAppSubURL, "/public/plugins", n.pluginJSON.ID), nil
|
||||
return path.Join("public/plugins", n.pluginJSON.ID), nil
|
||||
}
|
||||
|
||||
// Module returns the module.js path for the specified plugin.
|
||||
@@ -70,7 +70,7 @@ func (s *Service) Module(n PluginInfo) (string, error) {
|
||||
if s.cdn.PluginSupported(n.pluginJSON.ID) {
|
||||
return s.cdn.AssetURL(n.pluginJSON.ID, n.pluginJSON.Info.Version, "module.js")
|
||||
}
|
||||
return path.Join("/", s.cfg.GrafanaAppSubURL, "/public/plugins", n.pluginJSON.ID, "module.js"), nil
|
||||
return path.Join("public/plugins", n.pluginJSON.ID, "module.js"), nil
|
||||
}
|
||||
|
||||
// RelativeURL returns the relative URL for an arbitrary plugin asset.
|
||||
@@ -101,7 +101,7 @@ func (s *Service) RelativeURL(n PluginInfo, pathStr string) (string, error) {
|
||||
|
||||
// DefaultLogoPath returns the default logo path for the specified plugin type.
|
||||
func (s *Service) DefaultLogoPath(pluginType plugins.Type) string {
|
||||
return path.Join("/", s.cfg.GrafanaAppSubURL, fmt.Sprintf("/public/img/icn-%s.svg", string(pluginType)))
|
||||
return path.Join("public/img", fmt.Sprintf("icn-%s.svg", string(pluginType)))
|
||||
}
|
||||
|
||||
func getBaseDir(pluginDir string) string {
|
||||
|
||||
@@ -69,11 +69,11 @@ func TestService(t *testing.T) {
|
||||
|
||||
base, err = svc.Base(NewPluginInfo(jsonData["two"], plugins.ClassExternal, extPath("two")))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "/public/plugins/two", base)
|
||||
require.Equal(t, "public/plugins/two", base)
|
||||
|
||||
base, err = svc.Base(NewPluginInfo(jsonData["table-old"], plugins.ClassCore, tableOldFS))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "/public/app/plugins/table-old", base)
|
||||
require.Equal(t, "public/app/plugins/table-old", base)
|
||||
})
|
||||
|
||||
t.Run("Module", func(t *testing.T) {
|
||||
@@ -86,7 +86,7 @@ func TestService(t *testing.T) {
|
||||
|
||||
module, err = svc.Module(NewPluginInfo(jsonData["two"], plugins.ClassExternal, extPath("two")))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "/public/plugins/two/module.js", module)
|
||||
require.Equal(t, "public/plugins/two/module.js", module)
|
||||
|
||||
module, err = svc.Module(NewPluginInfo(jsonData["table-old"], plugins.ClassCore, tableOldFS))
|
||||
require.NoError(t, err)
|
||||
@@ -116,16 +116,16 @@ func TestService(t *testing.T) {
|
||||
|
||||
u, err = svc.RelativeURL(NewPluginInfo(pluginsMap["two"].JSONData, plugins.ClassExternal, extPath("two")), "path/to/file.txt")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "/public/plugins/two/path/to/file.txt", u)
|
||||
require.Equal(t, "public/plugins/two/path/to/file.txt", u)
|
||||
|
||||
u, err = svc.RelativeURL(NewPluginInfo(pluginsMap["two"].JSONData, plugins.ClassExternal, extPath("two")), "default")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "/public/plugins/two/default", u)
|
||||
require.Equal(t, "public/plugins/two/default", u)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("With App Sub URL", func(t *testing.T) {
|
||||
t.Run("App Sub URL has no effect on the path", func(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
appSubURL string
|
||||
}{
|
||||
@@ -151,15 +151,15 @@ func TestService(t *testing.T) {
|
||||
|
||||
base, err := svc.Base(NewPluginInfo(p, plugins.ClassExternal, fs))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "/grafana/public/plugins/test-datasource", base)
|
||||
require.Equal(t, "public/plugins/test-datasource", base)
|
||||
|
||||
mod, err := svc.Module(NewPluginInfo(p, plugins.ClassExternal, fs))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "/grafana/public/plugins/test-datasource/module.js", mod)
|
||||
require.Equal(t, "public/plugins/test-datasource/module.js", mod)
|
||||
|
||||
base, err = svc.Base(NewPluginInfo(p, plugins.ClassCore, fs))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "/grafana/public/app/plugins/test-datasource", base)
|
||||
require.Equal(t, "public/app/plugins/test-datasource", base)
|
||||
|
||||
mod, err = svc.Module(NewPluginInfo(p, plugins.ClassCore, fs))
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user