Skip to content

Commit

Permalink
Add back in legacy /viz /search and /dashboard routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Griffith committed May 31, 2020
1 parent 69148d3 commit 6f7bd72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/reporting/server/routes/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { LevelLogger as Logger } from '../lib';
import { registerGenerateFromJobParams } from './generate_from_jobparams';
import { registerGenerateCsvFromSavedObject } from './generate_from_savedobject';
import { registerGenerateCsvFromSavedObjectImmediate } from './generate_from_savedobject_immediate';
import { registerLegacy } from './legacy';
import { HandlerFunction } from './types';

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

registerGenerateFromJobParams(reporting, handler, handleError);
registerLegacy(reporting, handler, handleError, logger); // 7.x only

// Register beta panel-action download-related API's
if (config.get('csv', 'enablePanelActionDownload')) {
Expand Down
53 changes: 27 additions & 26 deletions x-pack/legacy/plugins/reporting/server/routes/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,64 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Legacy } from 'kibana';
import { schema } from '@kbn/config-schema';
import querystring from 'querystring';
import { authorizedUserPreRoutingFactory } from './lib/authorized_user_pre_routing';
import { API_BASE_URL } from '../../common/constants';
import { ReportingSetupDeps, ServerFacade } from '../types';
import {
getRouteConfigFactoryReportingPre,
GetRouteConfigFactoryFn,
} from './lib/route_config_factories';
import { HandlerErrorFunction, HandlerFunction } from './types';
import { ReportingCore } from '../core';
import { LevelLogger } from '../lib';

const getStaticFeatureConfig = (getRouteConfig: GetRouteConfigFactoryFn, featureId: string) =>
getRouteConfig(() => featureId);

const BASE_GENERATE = `${API_BASE_URL}/generate`;

export function registerLegacy(
reporting: ReportingCore,
server: ServerFacade,
plugins: ReportingSetupDeps,
handler: HandlerFunction,
handleError: HandlerErrorFunction,
logger: LevelLogger
) {
const config = reporting.getConfig();
const getRouteConfig = getRouteConfigFactoryReportingPre(config, plugins, logger);
const { router } = reporting.getPluginSetupDeps();
const userHandler = authorizedUserPreRoutingFactory(reporting);

function createLegacyPdfRoute({ path, objectType }: { path: string; objectType: string }) {
const exportTypeId = 'printablePdf';
server.route({
path,
method: 'POST',
options: getStaticFeatureConfig(getRouteConfig, exportTypeId),
handler: async (request: Legacy.Request, h: Legacy.ResponseToolkit) => {
const message = `The following URL is deprecated and will stop working in the next major version: ${request.url.path}`;

router.post(
{
path,
validate: {
params: schema.object({
savedObjectId: schema.string({ minLength: 3 }),
}),
query: schema.any(),
},
},

userHandler(async (user, context, req, res) => {
const message = `The following URL is deprecated and will stop working in the next major version: ${req.url.path}`;
logger.warn(message, ['deprecation']);

try {
const savedObjectId = request.params.savedId;
const queryString = querystring.stringify(request.query);
const { savedObjectId }: { savedObjectId: string } = req.params as any;
const queryString = querystring.stringify(req.query as any);

return await handler(
user,
exportTypeId,
{
objectType,
savedObjectId,
queryString,
},
request,
h
context,
req,
res
);
} catch (err) {
throw handleError(exportTypeId, err);
throw handleError(res, err);
}
},
});
})
);
}

createLegacyPdfRoute({
Expand Down

0 comments on commit 6f7bd72

Please sign in to comment.