mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-21 17:22:55 -05:00
Set notebook as trusted after executing a cell. (#9108)
* Also set trusted by default when opening a notebook without any code cells.
This commit is contained in:
@@ -339,6 +339,8 @@ export class CellModel implements ICellModel {
|
||||
}
|
||||
let content = this.source;
|
||||
if ((Array.isArray(content) && content.length > 0) || (!Array.isArray(content) && content)) {
|
||||
this.notebookModel.trustedMode = true;
|
||||
|
||||
// requestExecute expects a string for the code parameter
|
||||
content = Array.isArray(content) ? content.join('') : content;
|
||||
const future = kernel.requestExecute({
|
||||
|
||||
@@ -308,6 +308,11 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Trust notebook by default if there are no code cells
|
||||
if (this._cells.length === 0 || this._cells.every(cell => cell.cellType === CellTypes.Markdown)) {
|
||||
this.trustedMode = true;
|
||||
}
|
||||
} catch (error) {
|
||||
this._inErrorState = true;
|
||||
throw error;
|
||||
|
||||
@@ -21,8 +21,8 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
|
||||
import { AngularDisposable } from 'sql/base/browser/lifecycle';
|
||||
import { CellTypes, CellType } from 'sql/workbench/contrib/notebook/common/models/contracts';
|
||||
import { ICellModel, IModelFactory, INotebookModel } from 'sql/workbench/contrib/notebook/browser/models/modelInterfaces';
|
||||
import { CellTypes, CellType, NotebookChangeType } from 'sql/workbench/contrib/notebook/common/models/contracts';
|
||||
import { ICellModel, IModelFactory, INotebookModel, NotebookContentChange } from 'sql/workbench/contrib/notebook/browser/models/modelInterfaces';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { INotebookService, INotebookParams, INotebookManager, INotebookEditor, DEFAULT_NOTEBOOK_PROVIDER, SQL_NOTEBOOK_PROVIDER, INotebookSection, INavigationProvider, ICellEditorProvider } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { NotebookModel } from 'sql/workbench/contrib/notebook/browser/models/notebookModel';
|
||||
@@ -309,7 +309,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
||||
}, this.profile, this.logService, this.notificationService, this.telemetryService);
|
||||
let trusted = await this.notebookService.isNotebookTrustCached(this._notebookParams.notebookUri, this.isDirty());
|
||||
this._register(model.onError((errInfo: INotification) => this.handleModelError(errInfo)));
|
||||
this._register(model.contentChanged((change) => this.handleContentChanged()));
|
||||
this._register(model.contentChanged((change) => this.handleContentChanged(change)));
|
||||
this._register(model.onProviderIdChange((provider) => this.handleProviderIdChanged(provider)));
|
||||
this._register(model.kernelChanged((kernelArgs) => this.handleKernelChanged(kernelArgs)));
|
||||
this._model = this._register(model);
|
||||
@@ -360,7 +360,11 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
||||
this.notificationService.notify(notification);
|
||||
}
|
||||
|
||||
private handleContentChanged() {
|
||||
private handleContentChanged(change: NotebookContentChange) {
|
||||
if (change.changeType === NotebookChangeType.TrustChanged) {
|
||||
this._trustedAction.trusted = this._model.trustedMode;
|
||||
}
|
||||
|
||||
// Note: for now we just need to set dirty state and refresh the UI.
|
||||
this.detectChanges();
|
||||
}
|
||||
|
||||
@@ -155,8 +155,9 @@ suite('notebook model', function (): void {
|
||||
|
||||
// Then I expect to have 0 code cell as the contents
|
||||
assert.equal(model.cells.length, 0);
|
||||
// And Trust should be false by default
|
||||
assert(!model.trustedMode);
|
||||
|
||||
// And Trust should be true by default if there are no cells
|
||||
assert(model.trustedMode);
|
||||
});
|
||||
|
||||
test('Should use trusted state set in model load', async function (): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user