From 584886fa46b612d62bf765ec1a2b65b49cddf9e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 25 Feb 2021 10:00:21 +0100 Subject: [PATCH] AppPlugins: Options to disable showing config page in nav (#31354) * AppPlugins: Options to disable showing config page in nav * rename * Added autoEnabled * updated * Things are working sort of * Simplify --- docs/sources/developers/plugins/plugin.schema.json | 4 ++++ pkg/api/frontendsettings.go | 1 + pkg/api/index.go | 7 ------- pkg/api/plugins.go | 5 +++++ pkg/plugins/app_plugin.go | 3 ++- pkg/plugins/queries.go | 7 ++++--- public/app/features/plugins/PluginPage.tsx | 4 ++-- public/app/features/plugins/plugin_page_ctrl.ts | 1 + 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/docs/sources/developers/plugins/plugin.schema.json b/docs/sources/developers/plugins/plugin.schema.json index c7fb07dfd15..7be8ccebc5c 100644 --- a/docs/sources/developers/plugins/plugin.schema.json +++ b/docs/sources/developers/plugins/plugin.schema.json @@ -122,6 +122,10 @@ "hiddenQueries": { "type": "boolean" }, + "autoEnabled": { + "type": "boolean", + "description": "Set to true for app plugins that should be enabled by default in all orgs" + }, "dependencies": { "type": "object", "description": "Dependencies needed by the plugin.", diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index 6496d6bd1bf..92573ef766a 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -128,6 +128,7 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *models.ReqContext) (map[string]i if err != nil { return nil, err } + pluginsToPreload := []string{} for _, app := range enabledPlugins.Apps { if app.Preload { diff --git a/pkg/api/index.go b/pkg/api/index.go index adf939e06c9..b97ed4d0830 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -117,13 +117,6 @@ func getAppLinks(c *models.ReqContext) ([]*dtos.NavLink, error) { } } - if len(appLink.Children) > 0 && c.OrgRole == models.ROLE_ADMIN { - appLink.Children = append(appLink.Children, &dtos.NavLink{Divider: true}) - appLink.Children = append(appLink.Children, &dtos.NavLink{ - Text: "Plugin Config", Icon: "cog", Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/", - }) - } - if len(appLink.Children) > 0 { appLinks = append(appLinks, appLink) } diff --git a/pkg/api/plugins.go b/pkg/api/plugins.go index c7f5b08692b..1becc2fb953 100644 --- a/pkg/api/plugins.go +++ b/pkg/api/plugins.go @@ -169,6 +169,11 @@ func GetPluginSettingByID(c *models.ReqContext) response.Response { SignatureOrg: def.SignatureOrg, } + if app, ok := plugins.Apps[def.Id]; ok { + dto.Enabled = app.AutoEnabled + dto.Pinned = app.AutoEnabled + } + query := models.GetPluginSettingByIdQuery{PluginId: pluginID, OrgId: c.OrgId} if err := bus.Dispatch(&query); err != nil { if !errors.Is(err, models.ErrPluginSettingNotFound) { diff --git a/pkg/plugins/app_plugin.go b/pkg/plugins/app_plugin.go index 6ddd77e4419..40ef49efa73 100644 --- a/pkg/plugins/app_plugin.go +++ b/pkg/plugins/app_plugin.go @@ -15,7 +15,8 @@ import ( type AppPlugin struct { FrontendPluginBase - Routes []*AppPluginRoute `json:"routes"` + Routes []*AppPluginRoute `json:"routes"` + AutoEnabled bool `json:"autoEnabled"` FoundChildPlugins []*PluginInclude `json:"-"` Pinned bool `json:"-"` diff --git a/pkg/plugins/queries.go b/pkg/plugins/queries.go index 9dc2305fe3e..ef92b984d19 100644 --- a/pkg/plugins/queries.go +++ b/pkg/plugins/queries.go @@ -30,9 +30,10 @@ func GetPluginSettings(orgId int64) (map[string]*models.PluginSettingInfoDTO, er Enabled: true, } - // apps are disabled by default - if pluginDef.Type == PluginTypeApp { - opt.Enabled = false + // apps are disabled by default unless autoEnabled: true + if app, exists := Apps[pluginDef.Id]; exists { + opt.Enabled = app.AutoEnabled + opt.Pinned = app.AutoEnabled } // if it's included in app check app settings diff --git a/public/app/features/plugins/PluginPage.tsx b/public/app/features/plugins/PluginPage.tsx index 43835a1119a..f65169e81d7 100644 --- a/public/app/features/plugins/PluginPage.tsx +++ b/public/app/features/plugins/PluginPage.tsx @@ -400,7 +400,7 @@ function getPluginTabsNav( if (plugin.angularConfigCtrl) { pages.push({ text: 'Config', - icon: 'gicon gicon-cog', + icon: 'cog', url: `${appSubUrl}${path}?page=${PAGE_ID_CONFIG_CTRL}`, id: PAGE_ID_CONFIG_CTRL, }); @@ -426,7 +426,7 @@ function getPluginTabsNav( if (find(meta.includes, { type: PluginIncludeType.dashboard })) { pages.push({ text: 'Dashboards', - icon: 'gicon gicon-dashboard', + icon: 'apps', url: `${appSubUrl}${path}?page=${PAGE_ID_DASHBOARDS}`, id: PAGE_ID_DASHBOARDS, }); diff --git a/public/app/features/plugins/plugin_page_ctrl.ts b/public/app/features/plugins/plugin_page_ctrl.ts index a2a2c5cad34..78adc42c010 100644 --- a/public/app/features/plugins/plugin_page_ctrl.ts +++ b/public/app/features/plugins/plugin_page_ctrl.ts @@ -38,6 +38,7 @@ export class AppPageCtrl { this.navModel = this.navModelSrv.getNotFoundNav(); return; } + if (app.type !== 'app' || !app.enabled) { this.$rootScope.appEvent(AppEvents.alertError, ['Application Not Enabled']); this.navModel = this.navModelSrv.getNotFoundNav();