mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
This commit is contained in:
parent
4f9e8d6e80
commit
3d5f1c9bce
1 changed files with 0 additions and 61 deletions
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import _ from 'lodash';
|
||||
import { UICapabilities } from 'ui/capabilities';
|
||||
|
||||
export async function capabilityDecorator(
|
||||
server: Record<string, any>,
|
||||
request: Record<string, any>,
|
||||
capabilities: UICapabilities
|
||||
) {
|
||||
if (!isAuthenticatedRoute(request)) {
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
const { checkPrivilegesWithRequest, actions } = server.plugins.security.authorization;
|
||||
|
||||
const checkPrivileges = checkPrivilegesWithRequest(request);
|
||||
|
||||
const privilegedActions = getPrivilegedActions(server, actions);
|
||||
|
||||
const { spaces } = server.plugins;
|
||||
|
||||
let result;
|
||||
if (spaces) {
|
||||
result = await checkPrivileges.atSpace(spaces.getSpaceId(request), privilegedActions);
|
||||
} else {
|
||||
result = await checkPrivileges.globally(privilegedActions);
|
||||
}
|
||||
|
||||
return {
|
||||
...capabilities,
|
||||
...result.privileges,
|
||||
};
|
||||
}
|
||||
|
||||
function isAuthenticatedRoute(request: Record<string, any>) {
|
||||
const { settings } = request.route;
|
||||
return settings.auth !== false;
|
||||
}
|
||||
|
||||
function getPrivilegedActions(server: Record<string, any>, actions: Record<string, any>) {
|
||||
const uiApps = server.getAllUiApps();
|
||||
|
||||
const navLinkSpecs = server.getUiNavLinks();
|
||||
|
||||
const uiCapabilityActions = [...uiApps, ...navLinkSpecs].map(entry => `ui:${entry._id}/read`);
|
||||
|
||||
const { types } = server.savedObjects;
|
||||
|
||||
const savedObjectsActions = _.flatten(
|
||||
types.map((type: string) => [
|
||||
actions.getSavedObjectAction(type, 'read'),
|
||||
actions.getSavedObjectAction(type, 'create'),
|
||||
])
|
||||
);
|
||||
|
||||
return [...uiCapabilityActions, ...savedObjectsActions];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue