feat: (wip) authorize note access

This commit is contained in:
Baptiste Grob
2021-01-05 12:58:07 +01:00
parent 7261c2f119
commit 252183a7c5
2 changed files with 11 additions and 28 deletions

View File

@@ -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();
}
}

View File

@@ -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() {