Support trusted books in new version of Jupyter Books (#12874)

* Fix path gor v1 and v2 boooks

* Add tests and address PR comments

* fix failing tests

* Address pr comments

* address pr comments
This commit is contained in:
Barbara Valdez
2020-10-27 20:57:44 -07:00
committed by GitHub
parent e2c9d3899b
commit 42e16b1752
3 changed files with 349 additions and 266 deletions

View File

@@ -92,7 +92,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
trustBook(bookTreeItem?: BookTreeItem): void {
let bookPathToTrust: string = bookTreeItem ? bookTreeItem.root : this.currentBook?.bookPath;
if (bookPathToTrust) {
let trustChanged = this._bookTrustManager.setBookAsTrusted(bookPathToTrust);
let trustChanged = this._bookTrustManager.setBookAsTrusted(bookPathToTrust, true);
if (trustChanged) {
let notebookDocuments = azdata.nb.notebookDocuments;
if (notebookDocuments) {

View File

@@ -6,11 +6,11 @@ import * as path from 'path';
import * as vscode from 'vscode';
import * as constants from './../common/constants';
import { BookTreeItem } from './bookTreeItem';
import { BookModel } from './bookModel';
import { BookModel, BookVersion } from './bookModel';
export interface IBookTrustManager {
isNotebookTrustedByDefault(notebookUri: string): boolean;
setBookAsTrusted(bookRootPath: string): boolean;
setBookAsTrusted(bookRootPath: string, isTrusted: boolean): boolean;
}
enum TrustBookOperation {
@@ -27,7 +27,7 @@ export class BookTrustManager implements IBookTrustManager {
let trustableBookPaths = this.getTrustableBookPaths();
let hasTrustedBookPath: boolean = treeBookItems
.filter(bookItem => trustableBookPaths.some(trustableBookPath => trustableBookPath === path.join(bookItem.book.root, path.sep)))
.some(bookItem => normalizedNotebookUri.startsWith(path.join(bookItem.root, 'content', path.sep)));
.some(bookItem => normalizedNotebookUri.startsWith(bookItem.version === BookVersion.v1 ? path.join(bookItem.book.root, 'content', path.sep) : path.join(bookItem.book.root, path.sep)));
let isNotebookTrusted = hasTrustedBookPath && this.books.some(bookModel => bookModel.getNotebook(normalizedNotebookUri));
return isNotebookTrusted;
}
@@ -57,8 +57,11 @@ export class BookTrustManager implements IBookTrustManager {
.reduce((accumulator, currentBookItemList) => accumulator.concat(currentBookItemList), []);
}
setBookAsTrusted(bookRootPath: string): boolean {
return this.updateTrustedBooks(bookRootPath, TrustBookOperation.Add);
setBookAsTrusted(bookRootPath: string, isTrusted: boolean): boolean {
if (isTrusted) {
return this.updateTrustedBooks(bookRootPath, TrustBookOperation.Add);
}
return this.updateTrustedBooks(bookRootPath, TrustBookOperation.Remove);
}
getTrustedBookPathsInConfig(): string[] {