Skip to content

Commit

Permalink
[Search] Session feature controls (#85846) (#87212)
Browse files Browse the repository at this point in the history
* Use filter to bulk find

* Update x-pack/plugins/data_enhanced/server/search/session/session_service.ts

Co-authored-by: Lukas Olson <olson.lukas@gmail.com>

* Dashboard in space test

* Add warning on update failure

* fix merge

* Added functional test for sessions in space

* snapshot

* test cleanup

* sub perms

* test snapshots

* Update tests

* test

* code review

* snap

* Added discover test

* Update x-pack/plugins/data_enhanced/public/search/ui/connected_background_session_indicator/connected_background_session_indicator.tsx

Co-authored-by: Anton Dosov <dosantappdev@gmail.com>

Co-authored-by: Lukas Olson <olson.lukas@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Anton Dosov <dosantappdev@gmail.com>

Co-authored-by: Lukas Olson <olson.lukas@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Anton Dosov <dosantappdev@gmail.com>
  • Loading branch information
4 people authored Jan 5, 2021
1 parent 494bc7d commit ee0d83d
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,35 @@ test('should show indicator in case there is an active search session', async ()
await waitFor(() => getByTestId('backgroundSessionIndicator'));
});

test('should be disabled when permissions are off', async () => {
const state$ = new BehaviorSubject(SessionState.Loading);
coreStart.application.currentAppId$ = new BehaviorSubject('discover');
(coreStart.application.capabilities as any) = {
discover: {
storeSearchSession: false,
},
};
const BackgroundSessionIndicator = createConnectedBackgroundSessionIndicator({
sessionService: { ...sessionService, state$ },
application: coreStart.application,
timeFilter,
});

render(<BackgroundSessionIndicator />);

await waitFor(() => screen.getByTestId('backgroundSessionIndicator'));

expect(screen.getByTestId('backgroundSessionIndicator').querySelector('button')).toBeDisabled();
});

test('should be disabled during auto-refresh', async () => {
const state$ = new BehaviorSubject(SessionState.Loading);
coreStart.application.currentAppId$ = new BehaviorSubject('discover');
(coreStart.application.capabilities as any) = {
discover: {
storeSearchSession: true,
},
};
const BackgroundSessionIndicator = createConnectedBackgroundSessionIndicator({
sessionService: { ...sessionService, state$ },
application: coreStart.application,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,35 @@ export const createConnectedBackgroundSessionIndicator = ({
.getRefreshIntervalUpdate$()
.pipe(map(isAutoRefreshEnabled), distinctUntilChanged());

const getCapabilitiesByAppId = (
capabilities: ApplicationStart['capabilities'],
appId?: string
) => {
switch (appId) {
case 'dashboards':
return capabilities.dashboard;
case 'discover':
return capabilities.discover;
default:
return undefined;
}
};

return () => {
const state = useObservable(sessionService.state$.pipe(debounceTime(500)));
const autoRefreshEnabled = useObservable(isAutoRefreshEnabled$, isAutoRefreshEnabled());
const appId = useObservable(application.currentAppId$, undefined);

let disabled = false;
let disabledReasonText: string = '';

if (getCapabilitiesByAppId(application.capabilities, appId)?.storeSearchSession !== true) {
disabled = true;
disabledReasonText = i18n.translate('xpack.data.backgroundSessionIndicator.noCapability', {
defaultMessage: "You don't have permissions to send to background.",
});
}

if (autoRefreshEnabled) {
disabled = true;
disabledReasonText = i18n.translate(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 55 additions & 2 deletions x-pack/plugins/features/server/oss_features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const buildOSSFeatures = ({ savedObjectTypes, includeTimelion }: BuildOSS
app: ['discover', 'kibana'],
catalogue: ['discover'],
savedObject: {
all: ['search', 'query', 'index-pattern', 'background-session'],
all: ['search', 'query', 'index-pattern'],
read: [],
},
ui: ['show', 'save', 'saveQuery'],
Expand Down Expand Up @@ -71,6 +71,33 @@ export const buildOSSFeatures = ({ savedObjectTypes, includeTimelion }: BuildOSS
},
],
},
{
name: i18n.translate('xpack.features.ossFeatures.discoverSearchSessionsFeatureName', {
defaultMessage: 'Store Search Sessions',
}),
privilegeGroups: [
{
groupType: 'independent',
privileges: [
{
id: 'store_search_session',
name: i18n.translate(
'xpack.features.ossFeatures.discoverStoreSearchSessionsPrivilegeName',
{
defaultMessage: 'Store Search Sessions',
}
),
includeIn: 'all',
savedObject: {
all: ['background-session'],
read: [],
},
ui: ['storeSearchSession'],
},
],
},
],
},
],
},
{
Expand Down Expand Up @@ -156,7 +183,6 @@ export const buildOSSFeatures = ({ savedObjectTypes, includeTimelion }: BuildOSS
'lens',
'map',
'tag',
'background-session',
],
},
ui: ['createNew', 'show', 'showWriteControls', 'saveQuery'],
Expand Down Expand Up @@ -210,6 +236,33 @@ export const buildOSSFeatures = ({ savedObjectTypes, includeTimelion }: BuildOSS
},
],
},
{
name: i18n.translate('xpack.features.ossFeatures.dashboardSearchSessionsFeatureName', {
defaultMessage: 'Store Search Sessions',
}),
privilegeGroups: [
{
groupType: 'independent',
privileges: [
{
id: 'store_search_session',
name: i18n.translate(
'xpack.features.ossFeatures.dashboardStoreSearchSessionsPrivilegeName',
{
defaultMessage: 'Store Search Sessions',
}
),
includeIn: 'all',
savedObject: {
all: ['background-session'],
read: [],
},
ui: ['storeSearchSession'],
},
],
},
],
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function ({ getService }: FtrProviderContext) {
'minimal_all',
'minimal_read',
'url_create',
'store_search_session',
];
const trialPrivileges = await supertest
.get('/api/security/privileges')
Expand Down
18 changes: 16 additions & 2 deletions x-pack/test/api_integration/apis/security/privileges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,23 @@ export default function ({ getService }: FtrProviderContext) {
// Roles are associated with these privileges, and we shouldn't be removing them in a minor version.
const expected = {
features: {
discover: ['all', 'read', 'minimal_all', 'minimal_read', 'url_create'],
discover: [
'all',
'read',
'minimal_all',
'minimal_read',
'url_create',
'store_search_session',
],
visualize: ['all', 'read', 'minimal_all', 'minimal_read', 'url_create'],
dashboard: ['all', 'read', 'minimal_all', 'minimal_read', 'url_create'],
dashboard: [
'all',
'read',
'minimal_all',
'minimal_read',
'url_create',
'store_search_session',
],
dev_tools: ['all', 'read'],
advancedSettings: ['all', 'read'],
indexPatterns: ['all', 'read'],
Expand Down
5 changes: 4 additions & 1 deletion x-pack/test/send_search_to_background_integration/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
reportName: 'X-Pack Background Search UI (Enabled WIP Feature)',
},

testFiles: [resolve(__dirname, './tests/apps/dashboard/async_search')],
testFiles: [
resolve(__dirname, './tests/apps/dashboard/async_search'),
resolve(__dirname, './tests/apps/discover'),
],

kbnTestServer: {
...xpackFunctionalConfig.get('kbnTestServer'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
},
kibana: [
{
base: ['all'],
feature: {
dashboard: ['minimal_read', 'store_search_session'],
},
spaces: ['another-space'],
},
],
Expand All @@ -54,6 +56,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

after(async () => {
await security.role.delete('data_analyst');
await security.user.delete('analyst');

await esArchiver.unload('dashboard/session_in_space');
await PageObjects.security.forceLogout();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ loadTestFile, getService }: FtrProviderContext) {
const kibanaServer = getService('kibanaServer');
const esArchiver = getService('esArchiver');

describe('async search', function () {
this.tags('ciGroup3');

before(async () => {
await esArchiver.loadIfNeeded('logstash_functional');
await kibanaServer.uiSettings.replace({ defaultIndex: 'logstash-*' });
});

loadTestFile(require.resolve('./sessions_in_space'));
});
}
Loading

0 comments on commit ee0d83d

Please sign in to comment.