FS: Allow anonymous access to snapshot route (#115829)

allow anonymous access to snapshot route
This commit is contained in:
Ashley Harrison
2026-01-05 15:27:49 +00:00
committed by GitHub
parent e310d5e8ee
commit 6adc45bf30
3 changed files with 13 additions and 6 deletions
+6 -2
View File
@@ -1,5 +1,5 @@
import { Suspense, useEffect, useLayoutEffect } from 'react';
import { Navigate, useLocation } from 'react-router-dom-v5-compat';
import { Navigate, useLocation, useParams } from 'react-router-dom-v5-compat';
import { config, locationSearchToObject, navigationLogger, reportPageview } from '@grafana/runtime';
import { ErrorBoundary } from '@grafana/ui';
@@ -63,10 +63,14 @@ export function GrafanaRoute(props: Props) {
export function GrafanaRouteWrapper({ route }: Pick<Props, 'route'>) {
const location = useLocation();
const params = useParams();
const allowAnonymous =
typeof route.allowAnonymous === 'function' ? route.allowAnonymous(params) : route.allowAnonymous;
// Perform login check in the frontend now
if (isFrontendService()) {
const routeRequiresSignin = !route.allowAnonymous && !config.anonymousEnabled;
const routeRequiresSignin = !allowAnonymous && !config.anonymousEnabled;
if (routeRequiresSignin && !contextSrv.isSignedIn) {
contextSrv.setRedirectToUrl();
+2 -1
View File
@@ -1,5 +1,6 @@
import { Location } from 'history';
import { ComponentType } from 'react';
import { Params } from 'react-router-dom-v5-compat';
import { UrlQueryMap } from '@grafana/data';
@@ -25,5 +26,5 @@ export interface RouteDescriptor {
* Allow the route to be access by anonymous users.
* Currently only used when using the frontend-service.
*/
allowAnonymous?: boolean;
allowAnonymous?: boolean | ((params: Readonly<Params<string>>) => boolean);
}
+5 -3
View File
@@ -30,7 +30,7 @@ const isDevEnv = config.buildInfo.env === 'development';
export const extraRoutes: RouteDescriptor[] = [];
export function getAppRoutes(): RouteDescriptor[] {
return [
const routes: Array<RouteDescriptor | undefined | false> = [
// Based on the Grafana configuration standalone plugin pages can even override and extend existing core pages, or they can register new routes under existing ones.
// In order to make it possible we need to register them first due to how `<Switch>` is evaluating routes. (This will be unnecessary once/when we upgrade to React Router v6 and start using `<Routes>` instead.)
...getAppPluginRoutes(),
@@ -77,6 +77,7 @@ export function getAppRoutes(): RouteDescriptor[] {
},
{
path: '/dashboard/:type/:slug',
allowAnonymous: (params) => params.type === 'snapshot',
pageClass: 'page-dashboard',
routeName: DashboardRoutes.Normal,
component: SafeDynamicImport(
@@ -223,7 +224,6 @@ export function getAppRoutes(): RouteDescriptor[] {
},
{
path: '/admin/extensions',
navId: 'extensions',
roles: () =>
contextSrv.evaluatePermission([AccessControlAction.PluginsInstall, AccessControlAction.PluginsWrite]),
component:
@@ -560,7 +560,9 @@ export function getAppRoutes(): RouteDescriptor[] {
path: '/*',
component: PageNotFound,
},
].filter(isTruthy);
];
return routes.filter(isTruthy);
}
export function getSupportBundleRoutes(cfg = config): RouteDescriptor[] {