From 81014b21b4dd8cc7e00faaa871426511c618b3ba Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Thu, 9 Jul 2020 11:47:36 -0700 Subject: [PATCH 1/3] Reduce visual complexity of trust prompt --- package.nls.json | 3 ++- src/client/common/utils/localize.ts | 6 +++++- .../datascience/interactive-ipynb/nativeEditor.ts | 10 +++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/package.nls.json b/package.nls.json index c3638945435e..244a4ffefc9b 100644 --- a/package.nls.json +++ b/package.nls.json @@ -32,9 +32,10 @@ "DataScience.openExportFileNo": "No", "DataScience.failedExportMessage": "Export failed.", "DataScience.exportToPDFDependencyMessage": "If you have not installed xelatex (TeX) you will need to do so before you can export to PDF, for further instructions please look [here](https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex). \r\nTo avoid installing xelatex (TeX) you might want to try exporting to HTML and using your browsers \"Print to PDF\" feature.", - "DataScience.launchNotebookTrustPrompt": "A notebook could execute harmful code when opened. Some cells & outputs have been hidden. Do you trust this notebook? (To trust all notebooks by default, click [here](command:workbench.action.openSettings?%5B%22python.dataScience.alwaysTrustNotebooks%22%5D).) [Learn more.](https://aka.ms/trusted-notebooks)", + "DataScience.launchNotebookTrustPrompt": "A notebook could execute harmful code when opened. Some outputs have been hidden. Do you trust this notebook? [Learn more.](https://aka.ms/trusted-notebooks)", "DataScience.launchNotebookTrustPrompt.yes": "Trust", "DataScience.launchNotebookTrustPrompt.no": "Do not trust", + "DataScience.launchNotebookTrustPrompt.trustAllNotebooks": "Trust all notebooks", "python.command.python.viewLanguageServerOutput.title": "Show Language Server Output", "python.command.python.selectAndRunTestMethod.title": "Run Test Method ...", "python.command.python.selectAndDebugTestMethod.title": "Debug Test Method ...", diff --git a/src/client/common/utils/localize.ts b/src/client/common/utils/localize.ts index 455069417e30..0f7629b79ed6 100644 --- a/src/client/common/utils/localize.ts +++ b/src/client/common/utils/localize.ts @@ -1024,10 +1024,14 @@ export namespace DataScience { ); export const launchNotebookTrustPrompt = localize( 'DataScience.launchNotebookTrustPrompt', - 'A notebook could execute harmful code when opened. Some cells & outputs have been hidden. Do you trust this notebook? (To trust all notebooks by default, click [here](command:workbench.action.openSettings?%5B%22python.dataScience.alwaysTrustNotebooks%22%5D).) [Learn more.](https://aka.ms/trusted-notebooks)' + 'A notebook could execute harmful code when opened. Some outputs have been hidden. Do you trust this notebook? [Learn more.](https://aka.ms/trusted-notebooks)' ); export const trustNotebook = localize('DataScience.launchNotebookTrustPrompt.yes', 'Trust'); export const doNotTrustNotebook = localize('DataScience.launchNotebookTrustPrompt.no', 'Do not trust'); + export const trustAllNotebooks = localize( + 'DataScience.launchNotebookTrustPrompt.trustAllNotebooks', + 'Trust all notebooks' + ); export const previewNotebookOnlySupportedInVSCInsiders = localize( 'DataScience.previewNotebookOnlySupportedInVSCInsiders', 'The Preview Notebook Editor is supported only in the Insiders version of Visual Studio Code.' diff --git a/src/client/datascience/interactive-ipynb/nativeEditor.ts b/src/client/datascience/interactive-ipynb/nativeEditor.ts index 9b7c7eaa7815..ab8148cabc33 100644 --- a/src/client/datascience/interactive-ipynb/nativeEditor.ts +++ b/src/client/datascience/interactive-ipynb/nativeEditor.ts @@ -85,6 +85,7 @@ import { NativeEditorSynchronizer } from './nativeEditorSynchronizer'; import type { nbformat } from '@jupyterlab/coreutils'; // tslint:disable-next-line: no-require-imports import cloneDeep = require('lodash/cloneDeep'); +import { commands } from 'vscode'; import { concatMultilineStringInput, splitMultilineString } from '../../../datascience-ui/common'; import { ServerStatus } from '../../../datascience-ui/interactive-common/mainState'; import { isTestExecution, PYTHON_LANGUAGE, UseCustomEditorApi } from '../../common/constants'; @@ -611,7 +612,11 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor { } private async launchNotebookTrustPrompt() { - const prompts = [localize.DataScience.trustNotebook(), localize.DataScience.doNotTrustNotebook()]; + const prompts = [ + localize.DataScience.trustNotebook(), + localize.DataScience.doNotTrustNotebook(), + localize.DataScience.trustAllNotebooks() + ]; const selection = await this.applicationShell.showErrorMessage( localize.DataScience.launchNotebookTrustPrompt(), ...prompts @@ -636,6 +641,9 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor { } catch (err) { traceError(err); } + } else if (selection === localize.DataScience.trustAllNotebooks()) { + // Take the user to the settings UI where they can manually turn on the alwaysTrustNotebooks setting + commands.executeCommand('workbench.action.openSettings', 'python.dataScience.alwaysTrustNotebooks'); } } From 4676e2e35a79e9172bd8f53a522a7a58b7c0a52c Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Thu, 9 Jul 2020 12:02:55 -0700 Subject: [PATCH 2/3] Remove outdated comment --- src/client/datascience/interactive-ipynb/digestStorage.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/datascience/interactive-ipynb/digestStorage.ts b/src/client/datascience/interactive-ipynb/digestStorage.ts index cb6887c81725..cba0fa78c91e 100644 --- a/src/client/datascience/interactive-ipynb/digestStorage.ts +++ b/src/client/datascience/interactive-ipynb/digestStorage.ts @@ -9,7 +9,6 @@ import { IFileSystem } from '../../common/platform/types'; import { IExtensionContext } from '../../common/types'; import { IDigestStorage } from '../types'; -// NB: still need to implement automatic culling of least recently used entries @injectable() export class DigestStorage implements IDigestStorage { public readonly key: Promise; From 2cee072946586b764525288f1078b9168b32df9a Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Thu, 9 Jul 2020 12:41:08 -0700 Subject: [PATCH 3/3] Fix hygiene --- src/client/datascience/interactive-ipynb/nativeEditor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/datascience/interactive-ipynb/nativeEditor.ts b/src/client/datascience/interactive-ipynb/nativeEditor.ts index ab8148cabc33..c40a543ad097 100644 --- a/src/client/datascience/interactive-ipynb/nativeEditor.ts +++ b/src/client/datascience/interactive-ipynb/nativeEditor.ts @@ -6,6 +6,7 @@ import * as path from 'path'; import { CancellationToken, CancellationTokenSource, + commands, Event, EventEmitter, Memento, @@ -85,7 +86,6 @@ import { NativeEditorSynchronizer } from './nativeEditorSynchronizer'; import type { nbformat } from '@jupyterlab/coreutils'; // tslint:disable-next-line: no-require-imports import cloneDeep = require('lodash/cloneDeep'); -import { commands } from 'vscode'; import { concatMultilineStringInput, splitMultilineString } from '../../../datascience-ui/common'; import { ServerStatus } from '../../../datascience-ui/interactive-common/mainState'; import { isTestExecution, PYTHON_LANGUAGE, UseCustomEditorApi } from '../../common/constants';