Skip to content

Commit b123bf9

Browse files
committed
FIxes
1 parent 3488313 commit b123bf9

File tree

3 files changed

+67
-47
lines changed

3 files changed

+67
-47
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import { inject, injectable } from 'inversify';
7+
import { Uri } from 'vscode';
8+
import { IExtensionSingleActivationService } from '../../activation/types';
9+
import { IApplicationShell, ICommandManager } from '../../common/application/types';
10+
import { IDisposableRegistry } from '../../common/types';
11+
import { swallowExceptions } from '../../common/utils/decorators';
12+
import { DataScience } from '../../common/utils/localize';
13+
import { noop } from '../../common/utils/misc';
14+
import { Commands } from '../constants';
15+
import { INotebookStorageProvider } from '../interactive-ipynb/notebookStorageProvider';
16+
import { INotebookEditorProvider, ITrustService } from '../types';
17+
18+
@injectable()
19+
export class TrustCommandHandler implements IExtensionSingleActivationService {
20+
constructor(
21+
@inject(ITrustService) private readonly trustService: ITrustService,
22+
@inject(INotebookEditorProvider) private readonly editorProvider: INotebookEditorProvider,
23+
@inject(INotebookStorageProvider) private readonly storageProvider: INotebookStorageProvider,
24+
@inject(ICommandManager) private readonly commandManager: ICommandManager,
25+
@inject(IApplicationShell) private readonly applicationShell: IApplicationShell,
26+
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry
27+
) {}
28+
public async activate(): Promise<void> {
29+
this.disposables.push(this.commandManager.registerCommand(Commands.TrustNotebook, this.onTrustNotebook, this));
30+
this.disposables.push(this.commandManager.registerCommand(Commands.TrustedNotebook, noop));
31+
}
32+
@swallowExceptions('Trusting notebook')
33+
private async onTrustNotebook(uri?: Uri) {
34+
uri = uri ?? this.editorProvider.activeEditor?.file;
35+
if (!uri) {
36+
return;
37+
}
38+
const model = await this.storageProvider.get(uri);
39+
if (model.isTrusted) {
40+
return;
41+
}
42+
43+
const prompts = [DataScience.trustNotebook(), DataScience.doNotTrustNotebook()];
44+
const selection = await this.applicationShell.showErrorMessage(
45+
DataScience.launchNotebookTrustPrompt(),
46+
...prompts
47+
);
48+
if (selection !== DataScience.trustNotebook() || model.isTrusted) {
49+
return;
50+
}
51+
// Update model trust
52+
model.update({
53+
source: 'user',
54+
kind: 'updateTrust',
55+
oldDirty: model.isDirty,
56+
newDirty: model.isDirty,
57+
isNotebookTrusted: true
58+
});
59+
const contents = model.getContent();
60+
await this.trustService.trustNotebook(model.file, contents);
61+
}
62+
}

src/client/datascience/notebook/notebookTrustHandler.ts

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@
44
'use strict';
55

66
import { inject, injectable } from 'inversify';
7-
import { Uri } from 'vscode';
87
import { IExtensionSingleActivationService } from '../../activation/types';
9-
import { IApplicationShell, ICommandManager, IVSCodeNotebook } from '../../common/application/types';
10-
import { traceError } from '../../common/logger';
8+
import { IVSCodeNotebook } from '../../common/application/types';
119
import { IFileSystem } from '../../common/platform/types';
1210
import { IDisposableRegistry } from '../../common/types';
13-
import { swallowExceptions } from '../../common/utils/decorators';
14-
import { DataScience } from '../../common/utils/localize';
15-
import { noop } from '../../common/utils/misc';
16-
import { Commands } from '../constants';
17-
import { INotebookStorageProvider } from '../interactive-ipynb/notebookStorageProvider';
1811
import { INotebookEditorProvider, ITrustService } from '../types';
1912
import { updateVSCNotebookAfterTrustingNotebook } from './helpers/cellUpdateHelpers';
2013
import { isJupyterNotebook } from './helpers/helpers';
@@ -25,15 +18,10 @@ export class NotebookTrustHandler implements IExtensionSingleActivationService {
2518
@inject(ITrustService) private readonly trustService: ITrustService,
2619
@inject(IVSCodeNotebook) private readonly vscNotebook: IVSCodeNotebook,
2720
@inject(INotebookEditorProvider) private readonly editorProvider: INotebookEditorProvider,
28-
@inject(INotebookStorageProvider) private readonly storageProvider: INotebookStorageProvider,
2921
@inject(IFileSystem) private readonly fs: IFileSystem,
30-
@inject(ICommandManager) private readonly commandManager: ICommandManager,
31-
@inject(IApplicationShell) private readonly applicationShell: IApplicationShell,
3222
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry
3323
) {}
3424
public async activate(): Promise<void> {
35-
this.disposables.push(this.commandManager.registerCommand(Commands.TrustNotebook, this.onTrustNotebook, this));
36-
this.disposables.push(this.commandManager.registerCommand(Commands.TrustedNotebook, noop));
3725
this.trustService.onDidSetNotebookTrust(this.onDidTrustNotebook, this, this.disposables);
3826
}
3927
private onDidTrustNotebook() {
@@ -47,34 +35,4 @@ export class NotebookTrustHandler implements IExtensionSingleActivationService {
4735
}
4836
});
4937
}
50-
@swallowExceptions('Trusting notebook')
51-
private async onTrustNotebook(uri?: Uri) {
52-
uri = uri ?? this.editorProvider.activeEditor?.file;
53-
if (!uri) {
54-
return;
55-
}
56-
const model = await this.storageProvider.get(uri);
57-
if (model.isTrusted) {
58-
return;
59-
}
60-
61-
const prompts = [DataScience.trustNotebook(), DataScience.doNotTrustNotebook()];
62-
const selection = await this.applicationShell.showErrorMessage(
63-
DataScience.launchNotebookTrustPrompt(),
64-
...prompts
65-
);
66-
if (selection !== DataScience.trustNotebook() || model.isTrusted) {
67-
return;
68-
}
69-
// Update model trust
70-
model.update({
71-
source: 'user',
72-
kind: 'updateTrust',
73-
oldDirty: model.isDirty,
74-
newDirty: model.isDirty,
75-
isNotebookTrusted: true
76-
});
77-
const contents = model.getContent();
78-
await this.trustService.trustNotebook(model.file, contents);
79-
}
8038
}

src/test/datascience/notebook/contentProvider.unit.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ suite('Data Science - NativeNotebook ContentProvider', () => {
6565
state: CellState.init
6666
}
6767
],
68-
isTrustedgetNotebookTrusted
68+
isTrusted: isNotebookTrusted
6969
};
70-
when(storageProvider.load(anything(), anything(), anything(), anything())).thenResolve(
70+
when(storageProvider.get(anything(), anything(), anything(), anything())).thenResolve(
7171
(model as unknown) as INotebookModel
7272
);
7373

@@ -143,15 +143,15 @@ suite('Data Science - NativeNotebook ContentProvider', () => {
143143
source: '# HEAD',
144144
metadata: {}
145145
},
146-
fget 'a.ipynb',
146+
file: 'a.ipynb',
147147
id: 'MyCellId2',
148148
line: 0,
149149
state: CellState.init
150150
}
151151
],
152152
isTrusted: isNotebookTrusted
153153
};
154-
when(storageProvider.load(anything(), anything(), anything(), anything())).thenResolve(
154+
when(storageProvider.get(anything(), anything(), anything(), anything())).thenResolve(
155155
(model as unknown) as INotebookModel
156156
);
157157

0 commit comments

Comments
 (0)