mirror of
				https://github.com/grafana/grafana.git
				synced 2025-02-25 18:55:37 -06:00 
			
		
		
		
	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:
		@@ -890,6 +890,16 @@ max_annotations_to_keep =
 | 
				
			|||||||
# Enable the Explore section
 | 
					# Enable the Explore section
 | 
				
			||||||
enabled = true
 | 
					enabled = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#################################### Help #############################
 | 
				
			||||||
 | 
					[help]
 | 
				
			||||||
 | 
					# Enable the Help section
 | 
				
			||||||
 | 
					enabled = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#################################### Profile #############################
 | 
				
			||||||
 | 
					[profile]
 | 
				
			||||||
 | 
					# Enable the Profile section
 | 
				
			||||||
 | 
					enabled = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#################################### Query History #############################
 | 
					#################################### Query History #############################
 | 
				
			||||||
[query_history]
 | 
					[query_history]
 | 
				
			||||||
# Enable the Query history
 | 
					# Enable the Query history
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -872,6 +872,16 @@
 | 
				
			|||||||
# Enable the Explore section
 | 
					# Enable the Explore section
 | 
				
			||||||
;enabled = true
 | 
					;enabled = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#################################### Help #############################
 | 
				
			||||||
 | 
					[help]
 | 
				
			||||||
 | 
					# Enable the Help section
 | 
				
			||||||
 | 
					;enabled = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#################################### Profile #############################
 | 
				
			||||||
 | 
					[profile]
 | 
				
			||||||
 | 
					# Enable the Profile section
 | 
				
			||||||
 | 
					;enabled = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#################################### Query History #############################
 | 
					#################################### Query History #############################
 | 
				
			||||||
[query_history]
 | 
					[query_history]
 | 
				
			||||||
# Enable the Query history
 | 
					# Enable the Query history
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1345,6 +1345,22 @@ For more information about this feature, refer to [Explore]({{< relref "../explo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Enable or disable the Explore section. Default is `enabled`.
 | 
					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]
 | 
					## [metrics]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
For detailed instructions, refer to [Internal Grafana metrics]({{< relref "view-server/internal-metrics.md" >}}).
 | 
					For detailed instructions, refer to [Internal Grafana metrics]({{< relref "view-server/internal-metrics.md" >}}).
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -111,6 +111,8 @@ export interface GrafanaConfig {
 | 
				
			|||||||
  alertingMinInterval: number;
 | 
					  alertingMinInterval: number;
 | 
				
			||||||
  authProxyEnabled: boolean;
 | 
					  authProxyEnabled: boolean;
 | 
				
			||||||
  exploreEnabled: boolean;
 | 
					  exploreEnabled: boolean;
 | 
				
			||||||
 | 
					  helpEnabled: boolean;
 | 
				
			||||||
 | 
					  profileEnabled: boolean;
 | 
				
			||||||
  ldapEnabled: boolean;
 | 
					  ldapEnabled: boolean;
 | 
				
			||||||
  sigV4AuthEnabled: boolean;
 | 
					  sigV4AuthEnabled: boolean;
 | 
				
			||||||
  samlEnabled: boolean;
 | 
					  samlEnabled: boolean;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,6 +44,8 @@ export class GrafanaBootConfig implements GrafanaConfig {
 | 
				
			|||||||
  angularSupportEnabled = false;
 | 
					  angularSupportEnabled = false;
 | 
				
			||||||
  authProxyEnabled = false;
 | 
					  authProxyEnabled = false;
 | 
				
			||||||
  exploreEnabled = false;
 | 
					  exploreEnabled = false;
 | 
				
			||||||
 | 
					  helpEnabled = false;
 | 
				
			||||||
 | 
					  profileEnabled = false;
 | 
				
			||||||
  ldapEnabled = false;
 | 
					  ldapEnabled = false;
 | 
				
			||||||
  sigV4AuthEnabled = false;
 | 
					  sigV4AuthEnabled = false;
 | 
				
			||||||
  samlEnabled = false;
 | 
					  samlEnabled = false;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -105,6 +105,8 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *models.ReqContext) (map[string]i
 | 
				
			|||||||
		"verifyEmailEnabled":                  setting.VerifyEmailEnabled,
 | 
							"verifyEmailEnabled":                  setting.VerifyEmailEnabled,
 | 
				
			||||||
		"sigV4AuthEnabled":                    setting.SigV4AuthEnabled,
 | 
							"sigV4AuthEnabled":                    setting.SigV4AuthEnabled,
 | 
				
			||||||
		"exploreEnabled":                      setting.ExploreEnabled,
 | 
							"exploreEnabled":                      setting.ExploreEnabled,
 | 
				
			||||||
 | 
							"helpEnabled":                         setting.HelpEnabled,
 | 
				
			||||||
 | 
							"profileEnabled":                      setting.ProfileEnabled,
 | 
				
			||||||
		"queryHistoryEnabled":                 hs.Cfg.QueryHistoryEnabled,
 | 
							"queryHistoryEnabled":                 hs.Cfg.QueryHistoryEnabled,
 | 
				
			||||||
		"googleAnalyticsId":                   setting.GoogleAnalyticsId,
 | 
							"googleAnalyticsId":                   setting.GoogleAnalyticsId,
 | 
				
			||||||
		"rudderstackWriteKey":                 setting.RudderstackWriteKey,
 | 
							"rudderstackWriteKey":                 setting.RudderstackWriteKey,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -221,9 +221,7 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if c.IsSignedIn {
 | 
						navTree = hs.addProfile(navTree, c)
 | 
				
			||||||
		navTree = append(navTree, hs.getProfileNode(c))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_, uaIsDisabledForOrg := hs.Cfg.UnifiedAlerting.DisabledOrgs[c.OrgId]
 | 
						_, uaIsDisabledForOrg := hs.Cfg.UnifiedAlerting.DisabledOrgs[c.OrgId]
 | 
				
			||||||
	uaVisibleForOrg := hs.Cfg.UnifiedAlerting.IsEnabled() && !uaIsDisabledForOrg
 | 
						uaVisibleForOrg := hs.Cfg.UnifiedAlerting.IsEnabled() && !uaIsDisabledForOrg
 | 
				
			||||||
@@ -364,6 +362,20 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
 | 
				
			|||||||
		navTree = append(navTree, serverAdminNode)
 | 
							navTree = append(navTree, serverAdminNode)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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)
 | 
							helpVersion := fmt.Sprintf(`%s v%s (%s)`, setting.ApplicationName, setting.BuildVersion, setting.BuildCommit)
 | 
				
			||||||
		if hs.Cfg.AnonymousHideVersion && !c.IsSignedIn {
 | 
							if hs.Cfg.AnonymousHideVersion && !c.IsSignedIn {
 | 
				
			||||||
			helpVersion = setting.ApplicationName
 | 
								helpVersion = setting.ApplicationName
 | 
				
			||||||
@@ -379,8 +391,8 @@ func (hs *HTTPServer) getNavTree(c *models.ReqContext, hasEditPerm bool) ([]*dto
 | 
				
			|||||||
			Section:    dtos.NavSectionConfig,
 | 
								Section:    dtos.NavSectionConfig,
 | 
				
			||||||
			Children:   []*dtos.NavLink{},
 | 
								Children:   []*dtos.NavLink{},
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return navTree, nil
 | 
						return navTree
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (hs *HTTPServer) buildSavedItemsNavLinks(c *models.ReqContext) ([]*dtos.NavLink, error) {
 | 
					func (hs *HTTPServer) buildSavedItemsNavLinks(c *models.ReqContext) ([]*dtos.NavLink, error) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -171,6 +171,12 @@ var (
 | 
				
			|||||||
	// Explore UI
 | 
						// Explore UI
 | 
				
			||||||
	ExploreEnabled bool
 | 
						ExploreEnabled bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Help UI
 | 
				
			||||||
 | 
						HelpEnabled bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Profile UI
 | 
				
			||||||
 | 
						ProfileEnabled bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Grafana.NET URL
 | 
						// Grafana.NET URL
 | 
				
			||||||
	GrafanaComUrl string
 | 
						GrafanaComUrl string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -943,6 +949,12 @@ func (cfg *Cfg) Load(args CommandLineArgs) error {
 | 
				
			|||||||
	explore := iniFile.Section("explore")
 | 
						explore := iniFile.Section("explore")
 | 
				
			||||||
	ExploreEnabled = explore.Key("enabled").MustBool(true)
 | 
						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")
 | 
						queryHistory := iniFile.Section("query_history")
 | 
				
			||||||
	cfg.QueryHistoryEnabled = queryHistory.Key("enabled").MustBool(false)
 | 
						cfg.QueryHistoryEnabled = queryHistory.Key("enabled").MustBool(false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										23
									
								
								public/app/features/profile/FeatureTogglePage.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								public/app/features/profile/FeatureTogglePage.tsx
									
									
									
									
									
										Normal 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>
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										39
									
								
								public/app/features/profile/routes.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								public/app/features/profile/routes.tsx
									
									
									
									
									
										Normal 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')
 | 
				
			||||||
 | 
					    ),
 | 
				
			||||||
 | 
					  }));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -12,6 +12,7 @@ import { getRoutes as getPluginCatalogRoutes } from 'app/features/plugins/admin/
 | 
				
			|||||||
import { contextSrv } from 'app/core/services/context_srv';
 | 
					import { contextSrv } from 'app/core/services/context_srv';
 | 
				
			||||||
import { getLiveRoutes } from 'app/features/live/pages/routes';
 | 
					import { getLiveRoutes } from 'app/features/live/pages/routes';
 | 
				
			||||||
import { getAlertingRoutes } from 'app/features/alerting/routes';
 | 
					import { getAlertingRoutes } from 'app/features/alerting/routes';
 | 
				
			||||||
 | 
					import { getProfileRoutes } from 'app/features/profile/routes';
 | 
				
			||||||
import { ServiceAccountPage } from 'app/features/serviceaccounts/ServiceAccountPage';
 | 
					import { ServiceAccountPage } from 'app/features/serviceaccounts/ServiceAccountPage';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const extraRoutes: RouteDescriptor[] = [];
 | 
					export const extraRoutes: RouteDescriptor[] = [];
 | 
				
			||||||
@@ -247,24 +248,6 @@ export function getAppRoutes(): RouteDescriptor[] {
 | 
				
			|||||||
        ),
 | 
					        ),
 | 
				
			||||||
      component: SafeDynamicImport(() => import(/* webpackChunkName: "TeamPages" */ 'app/features/teams/TeamPages')),
 | 
					      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
 | 
					    // ADMIN
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -436,6 +419,7 @@ export function getAppRoutes(): RouteDescriptor[] {
 | 
				
			|||||||
    ...getPluginCatalogRoutes(),
 | 
					    ...getPluginCatalogRoutes(),
 | 
				
			||||||
    ...getLiveRoutes(),
 | 
					    ...getLiveRoutes(),
 | 
				
			||||||
    ...getAlertingRoutes(),
 | 
					    ...getAlertingRoutes(),
 | 
				
			||||||
 | 
					    ...getProfileRoutes(),
 | 
				
			||||||
    ...extraRoutes,
 | 
					    ...extraRoutes,
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      path: '/*',
 | 
					      path: '/*',
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user