From 252183a7c52bbf27886f17afa5a4b80c481db0ef Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Tue, 5 Jan 2021 12:58:07 +0100 Subject: [PATCH] feat: (wip) authorize note access --- app/assets/javascripts/ui_models/app_state.ts | 31 +++++++------------ .../javascripts/views/editor/editor_view.ts | 8 ----- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/app/assets/javascripts/ui_models/app_state.ts b/app/assets/javascripts/ui_models/app_state.ts index f64d2f8c8..0fecb118f 100644 --- a/app/assets/javascripts/ui_models/app_state.ts +++ b/app/assets/javascripts/ui_models/app_state.ts @@ -222,9 +222,18 @@ export class AppState { } async openEditor(noteUuid: string) { + if (this.getActiveEditor()?.note?.uuid === noteUuid) { + return; + } + const note = this.application.findItem(noteUuid) as SNNote; - if (this.getActiveEditor()?.note?.uuid === noteUuid) return; - const run = async () => { + if (!note) { + console.warn('Tried accessing a non-existant note of UUID ' + noteUuid); + return; + }; + + const approved = this.application.authorizeNoteAccess(note); + if (approved === true || await approved) { const activeEditor = this.getActiveEditor(); if (!activeEditor || this.multiEditorEnabled) { this.application.editorGroup.createEditor(noteUuid); @@ -232,24 +241,6 @@ export class AppState { activeEditor.setNote(note); } await this.notifyEvent(AppStateEvent.ActiveEditorChanged); - }; - if ( - note && - note.safeContent.protected && - (await this.application.privilegesService!.actionRequiresPrivilege( - ProtectedAction.ViewProtectedNotes - )) - ) { - return new Promise((resolve) => { - this.application.presentPrivilegesModal( - ProtectedAction.ViewProtectedNotes, - () => { - run().then(resolve); - } - ); - }); - } else { - return run(); } } diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 1379dccd2..b1c1d3c6c 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -740,14 +740,6 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> { mutator.protected = !this.note.protected } ); - /** Show privileges manager if protection is not yet set up */ - this.application.privilegesService!.actionHasPrivilegesConfigured( - ProtectedAction.ViewProtectedNotes - ).then((configured) => { - if (!configured) { - this.application.presentPrivilegesManagementModal(); - } - }); } toggleNotePreview() {