[Alerting] Fixing broken Alerts view when no Global All Kibana privilege (#88727)

* Making kibanaFeatures an optional parameter and catching error on plugin start

* Gracefully handle 404 errors when no access to features endpoint

* Adding functional test
This commit is contained in:
ymao1 2021-01-19 18:14:56 -05:00 committed by GitHub
parent e3063f6934
commit 6d1c010607
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 108 additions and 63 deletions

View file

@ -9,6 +9,7 @@ import { CoreSetup, CoreStart, Plugin as CorePlugin } from 'src/core/public';
import { i18n } from '@kbn/i18n';
import { ReactElement } from 'react';
import { FeaturesPluginStart } from '../../features/public';
import { KibanaFeature } from '../../features/common';
import { registerBuiltInActionTypes } from './application/components/builtin_action_types';
import { ActionTypeModel, AlertTypeModel } from './types';
import { TypeRegistry } from './application/type_registry';
@ -122,7 +123,17 @@ export class Plugin
];
const { renderApp } = await import('./application/app');
const kibanaFeatures = await pluginsStart.features.getFeatures();
// The `/api/features` endpoint requires the "Global All" Kibana privilege. Users with a
// subset of this privilege are not authorized to access this endpoint and will receive a 404
// error that causes the Alerting view to fail to load.
let kibanaFeatures: KibanaFeature[];
try {
kibanaFeatures = await pluginsStart.features.getFeatures();
} catch (err) {
kibanaFeatures = [];
}
return renderApp({
...coreStart,
data: pluginsStart.data,

View file

@ -11,6 +11,7 @@ import { getTestAlertData, getTestActionData } from '../../lib/get_test_data';
export default ({ getPageObjects, getService }: FtrProviderContext) => {
const testSubjects = getService('testSubjects');
const security = getService('security');
const pageObjects = getPageObjects(['common', 'triggersActionsUI', 'header']);
const log = getService('log');
const browser = getService('browser');
@ -18,6 +19,22 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const objectRemover = new ObjectRemover(supertest);
describe('Home page', function () {
describe('Loads the app with limited privileges', () => {
before(async () => {
await security.testUser.setRoles(['alerts_and_actions_role'], true);
});
after(async () => {
await security.testUser.restoreDefaults();
});
it('Loads the Alerts page', async () => {
await pageObjects.common.navigateToApp('triggersActions');
const headingText = await pageObjects.triggersActionsUI.getSectionHeadingText();
expect(headingText).to.be('Alerts and Actions');
});
});
describe('Loads the app', () => {
before(async () => {
await pageObjects.common.navigateToApp('triggersActions');
});
@ -26,7 +43,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await objectRemover.removeAll();
});
it('Loads the app', async () => {
it('Loads the Alerts page', async () => {
await log.debug('Checking for section heading to say Triggers and Actions.');
const headingText = await pageObjects.triggersActionsUI.getSectionHeadingText();
@ -95,4 +112,5 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});
});
});
});
};

View file

@ -86,6 +86,22 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
})}`,
],
},
security: {
roles: {
alerts_and_actions_role: {
kibana: [
{
feature: {
actions: ['all'],
stackAlerts: ['all'],
},
spaces: ['*'],
},
],
},
},
defaultRoles: ['superuser'],
},
};
return returnedObject;