Skip to content

Commit

Permalink
feat: (wip) authorize note access
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Jan 5, 2021
1 parent 7261c2f commit 252183a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
31 changes: 11 additions & 20 deletions app/assets/javascripts/ui_models/app_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,34 +222,25 @@ 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);
} else {
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();
}
}

Expand Down
8 changes: 0 additions & 8 deletions app/assets/javascripts/views/editor/editor_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 252183a

Please sign in to comment.