Skip to content

Commit 6f7bd72

Browse files
author
Joel Griffith
committed
Add back in legacy /viz /search and /dashboard routes
1 parent 69148d3 commit 6f7bd72

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

x-pack/legacy/plugins/reporting/server/routes/generation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { LevelLogger as Logger } from '../lib';
1313
import { registerGenerateFromJobParams } from './generate_from_jobparams';
1414
import { registerGenerateCsvFromSavedObject } from './generate_from_savedobject';
1515
import { registerGenerateCsvFromSavedObjectImmediate } from './generate_from_savedobject_immediate';
16+
import { registerLegacy } from './legacy';
1617
import { HandlerFunction } from './types';
1718

1819
const esErrors = elasticsearchErrors as Record<string, any>;
@@ -86,6 +87,7 @@ export function registerJobGenerationRoutes(reporting: ReportingCore, logger: Lo
8687
}
8788

8889
registerGenerateFromJobParams(reporting, handler, handleError);
90+
registerLegacy(reporting, handler, handleError, logger); // 7.x only
8991

9092
// Register beta panel-action download-related API's
9193
if (config.get('csv', 'enablePanelActionDownload')) {

x-pack/legacy/plugins/reporting/server/routes/legacy.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,64 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { Legacy } from 'kibana';
7+
import { schema } from '@kbn/config-schema';
88
import querystring from 'querystring';
9+
import { authorizedUserPreRoutingFactory } from './lib/authorized_user_pre_routing';
910
import { API_BASE_URL } from '../../common/constants';
10-
import { ReportingSetupDeps, ServerFacade } from '../types';
11-
import {
12-
getRouteConfigFactoryReportingPre,
13-
GetRouteConfigFactoryFn,
14-
} from './lib/route_config_factories';
1511
import { HandlerErrorFunction, HandlerFunction } from './types';
1612
import { ReportingCore } from '../core';
1713
import { LevelLogger } from '../lib';
1814

19-
const getStaticFeatureConfig = (getRouteConfig: GetRouteConfigFactoryFn, featureId: string) =>
20-
getRouteConfig(() => featureId);
21-
2215
const BASE_GENERATE = `${API_BASE_URL}/generate`;
2316

2417
export function registerLegacy(
2518
reporting: ReportingCore,
26-
server: ServerFacade,
27-
plugins: ReportingSetupDeps,
2819
handler: HandlerFunction,
2920
handleError: HandlerErrorFunction,
3021
logger: LevelLogger
3122
) {
32-
const config = reporting.getConfig();
33-
const getRouteConfig = getRouteConfigFactoryReportingPre(config, plugins, logger);
23+
const { router } = reporting.getPluginSetupDeps();
24+
const userHandler = authorizedUserPreRoutingFactory(reporting);
3425

3526
function createLegacyPdfRoute({ path, objectType }: { path: string; objectType: string }) {
3627
const exportTypeId = 'printablePdf';
37-
server.route({
38-
path,
39-
method: 'POST',
40-
options: getStaticFeatureConfig(getRouteConfig, exportTypeId),
41-
handler: async (request: Legacy.Request, h: Legacy.ResponseToolkit) => {
42-
const message = `The following URL is deprecated and will stop working in the next major version: ${request.url.path}`;
28+
29+
router.post(
30+
{
31+
path,
32+
validate: {
33+
params: schema.object({
34+
savedObjectId: schema.string({ minLength: 3 }),
35+
}),
36+
query: schema.any(),
37+
},
38+
},
39+
40+
userHandler(async (user, context, req, res) => {
41+
const message = `The following URL is deprecated and will stop working in the next major version: ${req.url.path}`;
4342
logger.warn(message, ['deprecation']);
4443

4544
try {
46-
const savedObjectId = request.params.savedId;
47-
const queryString = querystring.stringify(request.query);
45+
const { savedObjectId }: { savedObjectId: string } = req.params as any;
46+
const queryString = querystring.stringify(req.query as any);
4847

4948
return await handler(
49+
user,
5050
exportTypeId,
5151
{
5252
objectType,
5353
savedObjectId,
5454
queryString,
5555
},
56-
request,
57-
h
56+
context,
57+
req,
58+
res
5859
);
5960
} catch (err) {
60-
throw handleError(exportTypeId, err);
61+
throw handleError(res, err);
6162
}
62-
},
63-
});
63+
})
64+
);
6465
}
6566

6667
createLegacyPdfRoute({

0 commit comments

Comments
 (0)