mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[reporting] Pass along generic parameters in high-order route handler (#74892)
This commit is contained in:
parent
124bd126f8
commit
0eee111cf3
2 changed files with 7 additions and 16 deletions
|
@ -15,11 +15,6 @@ import {
|
|||
downloadJobResponseHandlerFactory,
|
||||
} from './lib/job_response_handler';
|
||||
|
||||
interface ListQuery {
|
||||
page: string;
|
||||
size: string;
|
||||
ids?: string; // optional field forbids us from extending RequestQuery
|
||||
}
|
||||
const MAIN_ENTRY = `${API_BASE_URL}/jobs`;
|
||||
|
||||
const handleUnavailable = (res: any) => {
|
||||
|
@ -52,11 +47,7 @@ export function registerJobInfoRoutes(reporting: ReportingCore) {
|
|||
const {
|
||||
management: { jobTypes = [] },
|
||||
} = await reporting.getLicenseInfo();
|
||||
const {
|
||||
page: queryPage = '0',
|
||||
size: querySize = '10',
|
||||
ids: queryIds = null,
|
||||
} = req.query as ListQuery; // NOTE: type inference is not working here. userHandler breaks it?
|
||||
const { page: queryPage = '0', size: querySize = '10', ids: queryIds = null } = req.query;
|
||||
const page = parseInt(queryPage, 10) || 0;
|
||||
const size = Math.min(100, parseInt(querySize, 10) || 10);
|
||||
const jobIds = queryIds ? queryIds.split(',') : null;
|
||||
|
@ -116,7 +107,7 @@ export function registerJobInfoRoutes(reporting: ReportingCore) {
|
|||
return handleUnavailable(res);
|
||||
}
|
||||
|
||||
const { docId } = req.params as { docId: string };
|
||||
const { docId } = req.params;
|
||||
const {
|
||||
management: { jobTypes = [] },
|
||||
} = await reporting.getLicenseInfo();
|
||||
|
@ -161,7 +152,7 @@ export function registerJobInfoRoutes(reporting: ReportingCore) {
|
|||
return res.custom({ statusCode: 503 });
|
||||
}
|
||||
|
||||
const { docId } = req.params as { docId: string };
|
||||
const { docId } = req.params;
|
||||
const {
|
||||
management: { jobTypes = [] },
|
||||
} = await reporting.getLicenseInfo();
|
||||
|
@ -213,7 +204,7 @@ export function registerJobInfoRoutes(reporting: ReportingCore) {
|
|||
return handleUnavailable(res);
|
||||
}
|
||||
|
||||
const { docId } = req.params as { docId: string };
|
||||
const { docId } = req.params;
|
||||
const {
|
||||
management: { jobTypes = [] },
|
||||
} = await reporting.getLicenseInfo();
|
||||
|
@ -239,7 +230,7 @@ export function registerJobInfoRoutes(reporting: ReportingCore) {
|
|||
return handleUnavailable(res);
|
||||
}
|
||||
|
||||
const { docId } = req.params as { docId: string };
|
||||
const { docId } = req.params;
|
||||
const {
|
||||
management: { jobTypes = [] },
|
||||
} = await reporting.getLicenseInfo();
|
||||
|
|
|
@ -12,7 +12,7 @@ import { getUserFactory } from './get_user';
|
|||
type ReportingUser = AuthenticatedUser | null;
|
||||
const superuserRole = 'superuser';
|
||||
|
||||
export type RequestHandlerUser = RequestHandler extends (...a: infer U) => infer R
|
||||
export type RequestHandlerUser<P, Q, B> = RequestHandler<P, Q, B> extends (...a: infer U) => infer R
|
||||
? (user: ReportingUser, ...a: U) => R
|
||||
: never;
|
||||
|
||||
|
@ -21,7 +21,7 @@ export const authorizedUserPreRoutingFactory = function authorizedUserPreRouting
|
|||
) {
|
||||
const setupDeps = reporting.getPluginSetupDeps();
|
||||
const getUser = getUserFactory(setupDeps.security);
|
||||
return <P, Q, B>(handler: RequestHandlerUser): RequestHandler<P, Q, B, RouteMethod> => {
|
||||
return <P, Q, B>(handler: RequestHandlerUser<P, Q, B>): RequestHandler<P, Q, B, RouteMethod> => {
|
||||
return (context, req, res) => {
|
||||
let user: ReportingUser = null;
|
||||
if (setupDeps.security && setupDeps.security.license.isEnabled()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue