Skip to content

Commit

Permalink
Adds license checks for basic to our csv panel action
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Griffith committed Mar 13, 2020
1 parent 5d0f89e commit d3d668c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
9 changes: 1 addition & 8 deletions x-pack/legacy/plugins/reporting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { resolve } from 'path';
import { PLUGIN_ID, UI_SETTINGS_CUSTOM_PDF_LOGO } from './common/constants';
import { config as reportingConfig } from './config';
import { legacyInit } from './server/legacy';
import { ReportingConfigOptions, ReportingPluginSpecOptions } from './types';
import { ReportingPluginSpecOptions } from './types';

const kbToBase64Length = (kb: number) => {
return Math.floor((kb * 1024 * 8) / 6);
Expand All @@ -25,13 +25,6 @@ export const reporting = (kibana: any) => {
config: reportingConfig,

uiExports: {
injectDefaultVars(server: Legacy.Server, options?: ReportingConfigOptions) {
const config = server.config();
return {
reportingPollConfig: options ? options.poll : {},
enablePanelActionDownload: config.get('xpack.reporting.csv.enablePanelActionDownload'),
};
},
uiSettingDefaults: {
[UI_SETTINGS_CUSTOM_PDF_LOGO]: {
name: i18n.translate('xpack.reporting.pdfFooterImageLabel', {
Expand Down
16 changes: 0 additions & 16 deletions x-pack/legacy/plugins/reporting/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ export type Job = EventEmitter & {
};
};

export interface ReportingConfigOptions {
browser: BrowserConfig;
poll: {
jobCompletionNotifier: {
interval: number;
intervalErrorMultiplier: number;
};
jobsRefresh: {
interval: number;
intervalErrorMultiplier: number;
};
};
queue: QueueConfig;
capture: CaptureConfig;
}

export interface NetworkPolicyRule {
allow: boolean;
protocol: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import dateMath from '@elastic/datemath';
import { i18n } from '@kbn/i18n';
import moment from 'moment-timezone';
import { LicensingPluginSetup } from '../../../licensing/public';
import { checkLicense } from '../lib/license_check';

import { CoreSetup } from '../../../../../src/core/public';
import { Action, IncompatibleActionError } from '../../../../../src/plugins/ui_actions/public';
Expand All @@ -15,7 +17,7 @@ import {
IEmbeddable,
} from '../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public';

// @TODO: These will probably relocate at some point, and will need to be fixed
// @TODO: These import paths will need to be updated once discovery moves to non-legacy dir
import { SEARCH_EMBEDDABLE_TYPE } from '../../../../../src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/constants';
import { ISearchEmbeddable } from '../../../../../src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/types';

Expand All @@ -35,11 +37,18 @@ export class GetCsvReportPanelAction implements Action<ActionContext> {
private isDownloading: boolean;
public readonly type = '';
public readonly id = CSV_REPORTING_ACTION;
private canDownloadCSV: boolean = false;
private core: CoreSetup;

constructor(core: CoreSetup) {
constructor(core: CoreSetup, license$: LicensingPluginSetup['license$']) {
this.isDownloading = false;
this.core = core;

license$.subscribe(license => {
const results = license.check('reporting', 'basic');
const { showLinks } = checkLicense(results);
this.canDownloadCSV = showLinks;
});
}

public getIconType() {
Expand All @@ -66,6 +75,10 @@ export class GetCsvReportPanelAction implements Action<ActionContext> {
}

public isCompatible = async (context: ActionContext) => {
if (!this.canDownloadCSV) {
return false;
}

const { embeddable } = context;

return embeddable.getInput().viewMode !== ViewMode.EDIT && embeddable.type === 'search';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/reporting/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class ReportingPublicPlugin implements Plugin<any, any> {
const { license$ } = licensing;

const apiClient = new ReportingAPIClient(http);
const action = new GetCsvReportPanelAction(core);
const action = new GetCsvReportPanelAction(core, license$);

home.featureCatalogue.register({
id: 'reporting',
Expand Down

0 comments on commit d3d668c

Please sign in to comment.