From ef3a962d788c4d1c375ed0fee28ce92da5a914de Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Mon, 22 Feb 2021 17:51:45 +0100 Subject: [PATCH] feat: show warning when protecting a note with no protection source --- app/assets/javascripts/strings.ts | 2 ++ .../javascripts/views/editor/editor_view.ts | 22 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/strings.ts b/app/assets/javascripts/strings.ts index c8782ae29..25232bc9c 100644 --- a/app/assets/javascripts/strings.ts +++ b/app/assets/javascripts/strings.ts @@ -124,4 +124,6 @@ export const Strings = { : 'password manager'; return `Your keys are currently stored in your operating system's ${keychainName}. Adding a passcode prevents even your operating system from reading them.`; }, + protectingNoteWithoutProtectionSources: 'Access to this note will not be restricted until you set up a passcode or account.', + openAccountMenu: 'Open Account Menu' }; diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index c0f67f836..5fca2e50e 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -1,4 +1,4 @@ -import { STRING_ARCHIVE_LOCKED_ATTEMPT, STRING_SAVING_WHILE_DOCUMENT_HIDDEN, STRING_UNARCHIVE_LOCKED_ATTEMPT } from './../../strings'; +import { Strings, STRING_ARCHIVE_LOCKED_ATTEMPT, STRING_SAVING_WHILE_DOCUMENT_HIDDEN, STRING_UNARCHIVE_LOCKED_ATTEMPT } from './../../strings'; import { Editor } from '@/ui_models/editor'; import { WebApplication } from '@/ui_models/application'; import { PanelPuppet, WebDirective } from '@/types'; @@ -713,15 +713,23 @@ class EditorViewCtrl extends PureViewCtrl { ); } - toggleProtectNote() { - this.saveNote( - true, - false, - true, + async toggleProtectNote() { + const note = await this.application.changeAndSaveItem( + this.note.uuid, (mutator) => { mutator.protected = !this.note.protected; - } + }, + false ); + if (note?.protected && !this.application.hasProtectionSources()) { + if (await confirmDialog({ + text: Strings.protectingNoteWithoutProtectionSources, + confirmButtonText: Strings.openAccountMenu, + confirmButtonStyle: 'info', + })) { + this.appState.accountMenu.setShow(true); + } + } } toggleNotePreview() {