Skip to content

Commit

Permalink
Hide welcome page privacy statement on cloud instances (#129198)
Browse files Browse the repository at this point in the history
* Add new hidePrivacyStatement flag to Telemetry

* Remove hidePrivacyStatement from asciidocs
  • Loading branch information
gsoldevila authored Apr 12, 2022
1 parent 6366f37 commit 7849d9e
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ kibana_vars=(
status.v6ApiFormat
telemetry.allowChangingOptInStatus
telemetry.enabled
telemetry.hidePrivacyStatement
telemetry.optIn
telemetry.sendUsageTo
telemetry.sendUsageFrom
Expand Down
60 changes: 60 additions & 0 deletions src/plugins/telemetry/public/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { TelemetryPlugin } from './plugin';
import { coreMock } from '../../../core/public/mocks';
import { homePluginMock } from '../../home/public/mocks';
import { screenshotModePluginMock } from '../../screenshot_mode/public/mocks';
import { HomePublicPluginSetup } from '../../home/public';
import { ScreenshotModePluginSetup } from '../../screenshot_mode/public';

let screenshotMode: ScreenshotModePluginSetup;
let home: HomePublicPluginSetup;

describe('TelemetryPlugin', () => {
beforeEach(() => {
screenshotMode = screenshotModePluginMock.createSetupContract();
home = homePluginMock.createSetupContract();
});

describe('setup', () => {
describe('when home is provided', () => {
describe('and hidePrivacyStatement is false (default)', () => {
it('registers the telemetry notice renderer and onRendered handlers', () => {
const initializerContext = coreMock.createPluginInitializerContext();

new TelemetryPlugin(initializerContext).setup(coreMock.createSetup(), {
screenshotMode,
home,
});

expect(home.welcomeScreen.registerTelemetryNoticeRenderer).toHaveBeenCalledWith(
expect.any(Function)
);
expect(home.welcomeScreen.registerOnRendered).toHaveBeenCalledWith(expect.any(Function));
});
});

describe('and hidePrivacyStatement is true', () => {
it('does not register the telemetry notice renderer and onRendered handlers', () => {
const initializerContext = coreMock.createPluginInitializerContext({
hidePrivacyStatement: true,
});

new TelemetryPlugin(initializerContext).setup(coreMock.createSetup(), {
screenshotMode,
home,
});

expect(home.welcomeScreen.registerTelemetryNoticeRenderer).not.toBeCalled();
expect(home.welcomeScreen.registerOnRendered).not.toBeCalled();
});
});
});
});
});
4 changes: 3 additions & 1 deletion src/plugins/telemetry/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export interface TelemetryPluginConfig {
telemetryNotifyUserAboutOptInDefault?: boolean;
/** Does the user have enough privileges to change the settings? **/
userCanChangeSettings?: boolean;
/** Should we hide the privacy statement notice? Useful on some environments, e.g. Cloud */
hidePrivacyStatement?: boolean;
}

function getTelemetryConstants(docLinks: DocLinksStart): TelemetryConstants {
Expand Down Expand Up @@ -155,7 +157,7 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
await this.refreshConfig();
});

if (home) {
if (home && !this.config.hidePrivacyStatement) {
home.welcomeScreen.registerOnRendered(() => {
if (this.telemetryService?.userCanChangeSettings) {
this.telemetryNotifications?.setOptedInNoticeSeen();
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/telemetry/public/services/telemetry_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,19 @@ describe('TelemetryService', () => {
});

describe('getUserShouldSeeOptInNotice', () => {
it('should return false if the telemetry notice is hidden by config', () => {
const telemetryService = mockTelemetryService({
config: {
userCanChangeSettings: true,
telemetryNotifyUserAboutOptInDefault: true,
hidePrivacyStatement: true,
},
});
expect(telemetryService.config.userCanChangeSettings).toBe(true);
expect(telemetryService.userCanChangeSettings).toBe(true);
expect(telemetryService.getUserShouldSeeOptInNotice()).toBe(false);
});

it('returns whether the user can update the telemetry config (has SavedObjects access)', () => {
const telemetryService = mockTelemetryService({
config: { userCanChangeSettings: undefined },
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/telemetry/public/services/telemetry_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ export class TelemetryService {
*/
public getUserShouldSeeOptInNotice(): boolean {
return (
(this.config.telemetryNotifyUserAboutOptInDefault && this.config.userCanChangeSettings) ??
(!this.config.hidePrivacyStatement &&
this.config.telemetryNotifyUserAboutOptInDefault &&
this.config.userCanChangeSettings) ??
false
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/telemetry/server/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const clusterEnvSchema: [Type<'prod'>, Type<'staging'>] = [
const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
allowChangingOptInStatus: schema.boolean({ defaultValue: true }),
hidePrivacyStatement: schema.boolean({ defaultValue: false }),
optIn: schema.conditional(
schema.siblingRef('allowChangingOptInStatus'),
schema.literal(false),
Expand Down Expand Up @@ -50,5 +51,6 @@ export const config: PluginConfigDescriptor<TelemetryConfigType> = {
optIn: true,
sendUsageFrom: true,
sendUsageTo: true,
hidePrivacyStatement: true,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'telemetry.allowChangingOptInStatus (boolean)',
'telemetry.banner (boolean)',
'telemetry.enabled (boolean)',
'telemetry.hidePrivacyStatement (boolean)',
'telemetry.optIn (any)',
'telemetry.sendUsageFrom (alternatives)',
'telemetry.sendUsageTo (any)',
Expand Down

0 comments on commit 7849d9e

Please sign in to comment.