From 9586b4f631dbcc253e4c1cd6ebc1ac5c48705f96 Mon Sep 17 00:00:00 2001 From: Patrick Mueller Date: Tue, 29 Oct 2019 01:36:30 -0400 Subject: [PATCH] forces a re-prompt of telemetry opt-in when Kibana version changes resolves #49519 If a user has previously opted out of telemetry, we are making a change to re-prompt them when the version of Kibana they are running changes. Previously, once opted out, they would never get prompted again. --- src/legacy/core_plugins/telemetry/index.ts | 3 +++ .../core_plugins/telemetry/mappings.json | 3 +++ .../telemetry/server/get_telemetry_opt_in.ts | 18 +++++++++++++++--- .../telemetry/server/routes/opt_in.ts | 2 ++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/legacy/core_plugins/telemetry/index.ts b/src/legacy/core_plugins/telemetry/index.ts index 3271373449eb3..34b8ecad7b079 100644 --- a/src/legacy/core_plugins/telemetry/index.ts +++ b/src/legacy/core_plugins/telemetry/index.ts @@ -48,6 +48,9 @@ const telemetry = (kibana: any) => { // `config` is used internally and not intended to be set config: Joi.string().default(Joi.ref('$defaultConfigPath')), banner: Joi.boolean().default(true), + lastVersionChecked: Joi.string() + .allow('') + .default(''), url: Joi.when('$dev', { is: true, then: Joi.string().default( diff --git a/src/legacy/core_plugins/telemetry/mappings.json b/src/legacy/core_plugins/telemetry/mappings.json index d83f7f5967630..1245ef88f5892 100644 --- a/src/legacy/core_plugins/telemetry/mappings.json +++ b/src/legacy/core_plugins/telemetry/mappings.json @@ -3,6 +3,9 @@ "properties": { "enabled": { "type": "boolean" + }, + "lastVersionChecked": { + "type": "keyword" } } } diff --git a/src/legacy/core_plugins/telemetry/server/get_telemetry_opt_in.ts b/src/legacy/core_plugins/telemetry/server/get_telemetry_opt_in.ts index 9b365d6dd7ae5..a66bb9f24b5ff 100644 --- a/src/legacy/core_plugins/telemetry/server/get_telemetry_opt_in.ts +++ b/src/legacy/core_plugins/telemetry/server/get_telemetry_opt_in.ts @@ -17,7 +17,7 @@ * under the License. */ -export async function getTelemetryOptIn(request: any) { +export async function getTelemetryOptIn(request: any): Promise { const isRequestingApplication = request.path.startsWith('/app'); // Prevent interstitial screens (such as the space selector) from prompting for telemetry @@ -27,9 +27,9 @@ export async function getTelemetryOptIn(request: any) { const savedObjectsClient = request.getSavedObjectsClient(); + let savedObject; try { - const { attributes } = await savedObjectsClient.get('telemetry', 'telemetry'); - return attributes.enabled; + savedObject = await savedObjectsClient.get('telemetry', 'telemetry'); } catch (error) { if (savedObjectsClient.errors.isNotFoundError(error)) { return null; @@ -43,4 +43,16 @@ export async function getTelemetryOptIn(request: any) { throw error; } + + const { attributes } = savedObject; + if (attributes.enabled !== false) return attributes.enabled; + + // Additional check if they've already opted out (enabled: false) - if the + // Kibana version has changed since they opted out, set them back to the null + // state to get prompted again. + const config = request.server.config(); + const kibanaVersion = config.get('pkg.version'); + if (kibanaVersion !== attributes.lastVersionChecked) return null; + + return attributes.enabled; } diff --git a/src/legacy/core_plugins/telemetry/server/routes/opt_in.ts b/src/legacy/core_plugins/telemetry/server/routes/opt_in.ts index aabc0259f08fc..b13d51d9db216 100644 --- a/src/legacy/core_plugins/telemetry/server/routes/opt_in.ts +++ b/src/legacy/core_plugins/telemetry/server/routes/opt_in.ts @@ -36,11 +36,13 @@ export function registerOptInRoutes(core: CoreSetup) { }, handler: async (req: any, h: any) => { const savedObjectsClient = req.getSavedObjectsClient(); + const lastVersionChecked = server.config().get('pkg.version'); try { await savedObjectsClient.create( 'telemetry', { enabled: req.payload.enabled, + lastVersionChecked, }, { id: 'telemetry',