Profile/Help: Expose option to disable profile section and help menu (#46308)

* Expose option to disable help menu

* Expose option to disable profile menu

* Add Profile FeatureTogglePage

* Update public/app/features/profile/FeatureTogglePage.tsx

Uptake PR wording suggestion.

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>

* Fix front end lint issue

* Fix back end lint issue

Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
This commit is contained in:
Cameron Waterman 2022-03-29 10:27:53 -05:00 committed by GitHub
parent 932f43b220
commit 8426cfe400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 148 additions and 36 deletions

View File

@ -890,6 +890,16 @@ max_annotations_to_keep =
# Enable the Explore section
enabled = true
#################################### Help #############################
[help]
# Enable the Help section
enabled = true
#################################### Profile #############################
[profile]
# Enable the Profile section
enabled = true
#################################### Query History #############################
[query_history]
# Enable the Query history

View File

@ -872,6 +872,16 @@
# Enable the Explore section
;enabled = true
#################################### Help #############################
[help]
# Enable the Help section
;enabled = true
#################################### Profile #############################
[profile]
# Enable the Profile section
;enabled = true
#################################### Query History #############################
[query_history]
# Enable the Query history

View File

@ -1345,6 +1345,22 @@ For more information about this feature, refer to [Explore]({{< relref "../explo
Enable or disable the Explore section. Default is `enabled`.
## [help]
Configures the help section.
### enabled
Enable or disable the Help section. Default is `enabled`.
## [profile]
Configures the Profile section.
### enabled
Enable or disable the Profile section. Default is `enabled`.
## [metrics]
For detailed instructions, refer to [Internal Grafana metrics]({{< relref "view-server/internal-metrics.md" >}}).

View File

@ -111,6 +111,8 @@ export interface GrafanaConfig {
alertingMinInterval: number;
authProxyEnabled: boolean;
exploreEnabled: boolean;
helpEnabled: boolean;
profileEnabled: boolean;
ldapEnabled: boolean;
sigV4AuthEnabled: boolean;
samlEnabled: boolean;

View File

@ -44,6 +44,8 @@ export class GrafanaBootConfig implements GrafanaConfig {
angularSupportEnabled = false;
authProxyEnabled = false;
exploreEnabled = false;
helpEnabled = false;
profileEnabled = false;
ldapEnabled = false;
sigV4AuthEnabled = false;
samlEnabled = false;

View File

@ -105,6 +105,8 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *models.ReqContext) (map[string]i
"verifyEmailEnabled": setting.VerifyEmailEnabled,
"sigV4AuthEnabled": setting.SigV4AuthEnabled,
"exploreEnabled": setting.ExploreEnabled,
"helpEnabled": setting.HelpEnabled,
"profileEnabled": setting.ProfileEnabled,
"queryHistoryEnabled": hs.Cfg.QueryHistoryEnabled,
"googleAnalyticsId": setting.GoogleAnalyticsId,
"rudderstackWriteKey": setting.RudderstackWriteKey,

View File

@ -221,9 +221,7 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
})
}
if c.IsSignedIn {
navTree = append(navTree, hs.getProfileNode(c))
}
navTree = hs.addProfile(navTree, c)
_, uaIsDisabledForOrg := hs.Cfg.UnifiedAlerting.DisabledOrgs[c.OrgId]
uaVisibleForOrg := hs.Cfg.UnifiedAlerting.IsEnabled() && !uaIsDisabledForOrg
@ -364,25 +362,39 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
navTree = append(navTree, serverAdminNode)
}
helpVersion := fmt.Sprintf(`%s v%s (%s)`, setting.ApplicationName, setting.BuildVersion, setting.BuildCommit)
if hs.Cfg.AnonymousHideVersion && !c.IsSignedIn {
helpVersion = setting.ApplicationName
}
navTree = append(navTree, &dtos.NavLink{
Text: "Help",
SubTitle: helpVersion,
Id: "help",
Url: "#",
Icon: "question-circle",
SortWeight: dtos.WeightHelp,
Section: dtos.NavSectionConfig,
Children: []*dtos.NavLink{},
})
navTree = hs.addHelpLinks(navTree, c)
return navTree, nil
}
func (hs *HTTPServer) addProfile(navTree []*dtos.NavLink, c *models.ReqContext) []*dtos.NavLink {
if setting.ProfileEnabled && c.IsSignedIn {
navTree = append(navTree, hs.getProfileNode(c))
}
return navTree
}
func (hs *HTTPServer) addHelpLinks(navTree []*dtos.NavLink, c *models.ReqContext) []*dtos.NavLink {
if setting.HelpEnabled {
helpVersion := fmt.Sprintf(`%s v%s (%s)`, setting.ApplicationName, setting.BuildVersion, setting.BuildCommit)
if hs.Cfg.AnonymousHideVersion && !c.IsSignedIn {
helpVersion = setting.ApplicationName
}
navTree = append(navTree, &dtos.NavLink{
Text: "Help",
SubTitle: helpVersion,
Id: "help",
Url: "#",
Icon: "question-circle",
SortWeight: dtos.WeightHelp,
Section: dtos.NavSectionConfig,
Children: []*dtos.NavLink{},
})
}
return navTree
}
func (hs *HTTPServer) buildSavedItemsNavLinks(c *models.ReqContext) ([]*dtos.NavLink, error) {
savedItemsChildNavs := []*dtos.NavLink{}

View File

@ -171,6 +171,12 @@ var (
// Explore UI
ExploreEnabled bool
// Help UI
HelpEnabled bool
// Profile UI
ProfileEnabled bool
// Grafana.NET URL
GrafanaComUrl string
@ -943,6 +949,12 @@ func (cfg *Cfg) Load(args CommandLineArgs) error {
explore := iniFile.Section("explore")
ExploreEnabled = explore.Key("enabled").MustBool(true)
help := iniFile.Section("help")
HelpEnabled = help.Key("enabled").MustBool(true)
profile := iniFile.Section("profile")
ProfileEnabled = profile.Key("enabled").MustBool(true)
queryHistory := iniFile.Section("query_history")
cfg.QueryHistoryEnabled = queryHistory.Key("enabled").MustBool(false)

View File

@ -0,0 +1,23 @@
import React from 'react';
import Page from 'app/core/components/Page/Page';
import { useNavModel } from 'app/core/hooks/useNavModel';
export default function FeatureTogglePage() {
const navModel = useNavModel('profile-settings');
return (
<Page navModel={navModel}>
<Page.Contents>
<h1>Profile is not enabled.</h1>
Enable profile in the Grafana config file.
<div>
<pre>
{`[profile]
enable = true
`}
</pre>
</div>
</Page.Contents>
</Page>
);
}

View File

@ -0,0 +1,39 @@
import { SafeDynamicImport } from 'app/core/components/DynamicImports/SafeDynamicImport';
import { config } from 'app/core/config';
import { RouteDescriptor } from 'app/core/navigation/types';
import { uniq } from 'lodash';
const profileRoutes: RouteDescriptor[] = [
{
path: '/profile',
component: SafeDynamicImport(
() => import(/* webpackChunkName: "UserProfileEditPage" */ 'app/features/profile/UserProfileEditPage')
),
},
{
path: '/profile/password',
component: SafeDynamicImport(
() => import(/* webPackChunkName: "ChangePasswordPage" */ 'app/features/profile/ChangePasswordPage')
),
},
{
path: '/profile/select-org',
component: SafeDynamicImport(
() => import(/* webpackChunkName: "SelectOrgPage" */ 'app/features/org/SelectOrgPage')
),
},
];
export function getProfileRoutes(cfg = config): RouteDescriptor[] {
if (cfg.profileEnabled) {
return profileRoutes;
}
const uniquePaths = uniq(profileRoutes.map((route) => route.path));
return uniquePaths.map((path) => ({
path,
component: SafeDynamicImport(
() => import(/* webpackChunkName: "Profile feature toggle page"*/ 'app/features/profile/FeatureTogglePage')
),
}));
}

View File

@ -12,6 +12,7 @@ import { getRoutes as getPluginCatalogRoutes } from 'app/features/plugins/admin/
import { contextSrv } from 'app/core/services/context_srv';
import { getLiveRoutes } from 'app/features/live/pages/routes';
import { getAlertingRoutes } from 'app/features/alerting/routes';
import { getProfileRoutes } from 'app/features/profile/routes';
import { ServiceAccountPage } from 'app/features/serviceaccounts/ServiceAccountPage';
export const extraRoutes: RouteDescriptor[] = [];
@ -247,24 +248,6 @@ export function getAppRoutes(): RouteDescriptor[] {
),
component: SafeDynamicImport(() => import(/* webpackChunkName: "TeamPages" */ 'app/features/teams/TeamPages')),
},
{
path: '/profile',
component: SafeDynamicImport(
() => import(/* webpackChunkName: "UserProfileEditPage" */ 'app/features/profile/UserProfileEditPage')
),
},
{
path: '/profile/password',
component: SafeDynamicImport(
() => import(/* webPackChunkName: "ChangePasswordPage" */ 'app/features/profile/ChangePasswordPage')
),
},
{
path: '/profile/select-org',
component: SafeDynamicImport(
() => import(/* webpackChunkName: "SelectOrgPage" */ 'app/features/org/SelectOrgPage')
),
},
// ADMIN
{
@ -436,6 +419,7 @@ export function getAppRoutes(): RouteDescriptor[] {
...getPluginCatalogRoutes(),
...getLiveRoutes(),
...getAlertingRoutes(),
...getProfileRoutes(),
...extraRoutes,
{
path: '/*',