From 94f94c0570bc2547e8bde48af0eb06b25452a686 Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Fri, 16 Oct 2020 12:47:21 +0200 Subject: [PATCH] fix: prevent archiving locked notes --- app/assets/javascripts/strings.ts | 2 ++ app/assets/javascripts/views/editor/editor_view.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/strings.ts b/app/assets/javascripts/strings.ts index 5e6cd6056..6f4dbff99 100644 --- a/app/assets/javascripts/strings.ts +++ b/app/assets/javascripts/strings.ts @@ -19,6 +19,8 @@ export const STRING_INVALID_NOTE = "The note you are attempting to save can not export const STRING_ELLIPSES = "..."; export const STRING_GENERIC_SAVE_ERROR = "There was an error saving your note. Please try again."; export const STRING_DELETE_PLACEHOLDER_ATTEMPT = "This note is a placeholder and cannot be deleted. To remove from your list, simply navigate to a different note."; +export const STRING_ARCHIVE_LOCKED_ATTEMPT = "This note is locked. If you'd like to archive it, unlock it, and try again."; +export const STRING_UNARCHIVE_LOCKED_ATTEMPT = "This note is locked. If you'd like to archive it, unlock it, and try again."; export const STRING_DELETE_LOCKED_ATTEMPT = "This note is locked. If you'd like to delete it, unlock it, and try again."; export function StringDeleteNote(title: string, permanently: boolean) { return permanently diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index c33572ab4..974e6cfdb 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_SAVING_WHILE_DOCUMENT_HIDDEN } from './../../strings'; +import { 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'; @@ -34,7 +34,7 @@ import { StringDeleteNote, StringEmptyTrash } from '@/strings'; -import { confirmDialog } from '@/services/alertService'; +import { alertDialog, confirmDialog } from '@/services/alertService'; const NOTE_PREVIEW_CHAR_LIMIT = 80; const MINIMUM_STATUS_DURATION = 400; @@ -770,6 +770,14 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> { } toggleArchiveNote() { + if (this.note.locked) { + alertDialog({ + text: this.note.archived ? + STRING_UNARCHIVE_LOCKED_ATTEMPT : + STRING_ARCHIVE_LOCKED_ATTEMPT, + }); + return; + } this.saveNote( true, false,