mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Toggle Trusted Button (#8569)
* Toggle Trusted Button * Persist Trusted information to Cache * Trusted toggle unit test fixed * Updated test comment
This commit is contained in:
@@ -106,7 +106,6 @@ export class TrustedAction extends ToggleableAction {
|
|||||||
// Constants
|
// Constants
|
||||||
private static readonly trustedLabel = localize('trustLabel', "Trusted");
|
private static readonly trustedLabel = localize('trustLabel', "Trusted");
|
||||||
private static readonly notTrustedLabel = localize('untrustLabel', "Not Trusted");
|
private static readonly notTrustedLabel = localize('untrustLabel', "Not Trusted");
|
||||||
private static readonly alreadyTrustedMsg = localize('alreadyTrustedMsg', "Notebook is already trusted.");
|
|
||||||
private static readonly baseClass = 'notebook-button';
|
private static readonly baseClass = 'notebook-button';
|
||||||
private static readonly trustedCssClass = 'icon-trusted';
|
private static readonly trustedCssClass = 'icon-trusted';
|
||||||
private static readonly notTrustedCssClass = 'icon-notTrusted';
|
private static readonly notTrustedCssClass = 'icon-notTrusted';
|
||||||
@@ -114,8 +113,7 @@ export class TrustedAction extends ToggleableAction {
|
|||||||
// Properties
|
// Properties
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
id: string,
|
id: string
|
||||||
@INotificationService private _notificationService: INotificationService
|
|
||||||
) {
|
) {
|
||||||
super(id, {
|
super(id, {
|
||||||
baseClass: TrustedAction.baseClass,
|
baseClass: TrustedAction.baseClass,
|
||||||
@@ -138,14 +136,8 @@ export class TrustedAction extends ToggleableAction {
|
|||||||
let self = this;
|
let self = this;
|
||||||
return new Promise<boolean>((resolve, reject) => {
|
return new Promise<boolean>((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
if (self.trusted) {
|
|
||||||
const actions: INotificationActions = { primary: [] };
|
|
||||||
self._notificationService.notify({ severity: Severity.Info, message: TrustedAction.alreadyTrustedMsg, actions });
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.trusted = !self.trusted;
|
self.trusted = !self.trusted;
|
||||||
context.model.trustedMode = self.trusted;
|
context.model.trustedMode = self.trusted;
|
||||||
}
|
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(e);
|
reject(e);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ suite('Notebook Actions', function (): void {
|
|||||||
let mockNotification = TypeMoq.Mock.ofType<INotificationService>(TestNotificationService);
|
let mockNotification = TypeMoq.Mock.ofType<INotificationService>(TestNotificationService);
|
||||||
mockNotification.setup(n => n.notify(TypeMoq.It.isAny()));
|
mockNotification.setup(n => n.notify(TypeMoq.It.isAny()));
|
||||||
|
|
||||||
let action = new TrustedAction('TestId', mockNotification.object);
|
let action = new TrustedAction('TestId');
|
||||||
assert.strictEqual(action.trusted, false, 'Should not be trusted by default');
|
assert.strictEqual(action.trusted, false, 'Should not be trusted by default');
|
||||||
|
|
||||||
// Normal use case
|
// Normal use case
|
||||||
@@ -77,10 +77,10 @@ suite('Notebook Actions', function (): void {
|
|||||||
assert.ok(result, 'Trusted Action should succeed');
|
assert.ok(result, 'Trusted Action should succeed');
|
||||||
assert.strictEqual(action.trusted, true, 'Should be trusted after toggling trusted state');
|
assert.strictEqual(action.trusted, true, 'Should be trusted after toggling trusted state');
|
||||||
|
|
||||||
// Should stay trusted when trying to toggle again
|
// Should toggle trusted to false on subsequent action
|
||||||
result = await action.run(contextStub);
|
result = await action.run(contextStub);
|
||||||
assert.ok(result, 'Trusted Action should succeed again');
|
assert.ok(result, 'Trusted Action should succeed again');
|
||||||
assert.strictEqual(action.trusted, true, 'Should stay trusted when trying to toggle trusted to false');
|
assert.strictEqual(action.trusted, false, 'Should toggle trusted to false');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Run All Cells Action', async function (): Promise<void> {
|
test('Run All Cells Action', async function (): Promise<void> {
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ export class NotebookService extends Disposable implements INotebookService {
|
|||||||
private _themeParticipant: IDisposable;
|
private _themeParticipant: IDisposable;
|
||||||
private _overrideEditorThemeSetting: boolean;
|
private _overrideEditorThemeSetting: boolean;
|
||||||
private _trustedCacheQueue: URI[] = [];
|
private _trustedCacheQueue: URI[] = [];
|
||||||
|
private _unTrustedCacheQueue: URI[] = [];
|
||||||
private _updateTrustCacheScheduler: RunOnceScheduler;
|
private _updateTrustCacheScheduler: RunOnceScheduler;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -589,8 +590,12 @@ export class NotebookService extends Disposable implements INotebookService {
|
|||||||
if (changeType === NotebookChangeType.Saved && firstIndex(this._trustedCacheQueue, uri => uri.toString() === notebookUriString) < 0) {
|
if (changeType === NotebookChangeType.Saved && firstIndex(this._trustedCacheQueue, uri => uri.toString() === notebookUriString) < 0) {
|
||||||
// Only save if it's trusted
|
// Only save if it's trusted
|
||||||
let notebook = find(this.listNotebookEditors(), n => n.id === notebookUriString);
|
let notebook = find(this.listNotebookEditors(), n => n.id === notebookUriString);
|
||||||
if (notebook && notebook.model.trustedMode) {
|
if (notebook && notebook.model) {
|
||||||
|
if (notebook.model.trustedMode) {
|
||||||
this._trustedCacheQueue.push(notebookUri);
|
this._trustedCacheQueue.push(notebookUri);
|
||||||
|
} else {
|
||||||
|
this._unTrustedCacheQueue.push(notebookUri);
|
||||||
|
}
|
||||||
this._updateTrustCacheScheduler.schedule();
|
this._updateTrustCacheScheduler.schedule();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -625,7 +630,19 @@ export class NotebookService extends Disposable implements INotebookService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this._trustedNotebooksMemento.saveMemento();
|
||||||
|
}
|
||||||
|
if (this._unTrustedCacheQueue.length > 0) {
|
||||||
|
// Copy out all items from the cache
|
||||||
|
let items = this._unTrustedCacheQueue;
|
||||||
|
this._unTrustedCacheQueue = [];
|
||||||
|
let trustedCache = this.trustedNotebooksMemento.trustedNotebooksCache;
|
||||||
|
//Remove the trusted intry from the cache
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
if (trustedCache[items[i].toString()]) {
|
||||||
|
trustedCache[items[i].toString()] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
this._trustedNotebooksMemento.saveMemento();
|
this._trustedNotebooksMemento.saveMemento();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user