Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide welcome page privacy statement on cloud instances #129198

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/settings/telemetry-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ See our https://www.elastic.co/legal/privacy-statement[Privacy Statement] to lea
============
When `false`, <<telemetry-optIn, `telemetry.optIn`>> must be `true`. To disable telemetry and not allow users to change that parameter, use <<telemetry-enabled, `telemetry.enabled`>>.
============

[[telemetry-hidePrivacyStatement]] `telemetry.hidePrivacyStatement`::
Set to `true` to prevent from showing the privacy statement notice. Defaults to `false`.
3 changes: 3 additions & 0 deletions docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,9 @@ To enable telemetry and prevent users from disabling it,
set <<telemetry-allowChangingOptInStatus, `telemetry.allowChangingOptInStatus`>> to `false` and <<settings-telemetry-optIn, `telemetry.optIn`>> to `true`.
*Default: `true`*

|[[settings-telemetry-hidePrivacyStatement]] `telemetry.hidePrivacyStatement`::
| Set to `true` to prevent from showing the privacy statement notice. Defaults to `false`.
gsoldevila marked this conversation as resolved.
Show resolved Hide resolved

| `telemetry.enabled`
| Reporting your cluster statistics helps
us improve your user experience. Your data is never shared with anyone. Set to
Expand Down
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
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,
},
};