From c9399f33d14d0420af4051bb706baf95af36ec79 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Tue, 9 Mar 2021 12:31:46 +0100 Subject: [PATCH 1/2] Support anonymous updates via API if allowAnonymousEdits is true Signed-off-by: Giuseppe Lo Presti --- lib/note/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/note/index.js b/lib/note/index.js index 0a20238e..badf69d7 100644 --- a/lib/note/index.js +++ b/lib/note/index.js @@ -268,7 +268,7 @@ const deleteNote = async (req, res) => { } const updateNote = async (req, res) => { - if (req.isAuthenticated()) { + if (req.isAuthenticated() || config.allowAnonymousEdits) { const noteId = await Note.parseNoteIdAsync(req.params.noteId) try { const note = await Note.findOne({ @@ -292,7 +292,7 @@ const updateNote = async (req, res) => { title: Note.parseNoteTitle(content), content: content, lastchangeAt: now, - authorship: [ + authorship: req.isAuthenticated() ? [ [ req.user.id, 0, @@ -300,7 +300,7 @@ const updateNote = async (req, res) => { now, now ] - ] + ] : [] }) if (!updated) { @@ -308,7 +308,9 @@ const updateNote = async (req, res) => { return errorInternalError(req, res) } - updateHistory(req.user.id, note.id, content) + if (req.isAuthenticated()) { + updateHistory(req.user.id, note.id, content) + } Revision.saveNoteRevision(note, (err, revision) => { if (err) { @@ -321,7 +323,7 @@ const updateNote = async (req, res) => { }) }) } catch (err) { - logger.error(err) + logger.error(err.stack) logger.error('Update note failed: Internal Error.') return errorInternalError(req, res) } From dc37e5df6322fe6b204e305a875a5d9d6645aab7 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Thu, 18 Mar 2021 08:56:19 +0100 Subject: [PATCH 2/2] Better update of the authorship of anonymous users Co-authored-by: Yukai Huang Signed-off-by: Giuseppe Lo Presti --- lib/note/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/note/index.js b/lib/note/index.js index badf69d7..7f215149 100644 --- a/lib/note/index.js +++ b/lib/note/index.js @@ -292,15 +292,15 @@ const updateNote = async (req, res) => { title: Note.parseNoteTitle(content), content: content, lastchangeAt: now, - authorship: req.isAuthenticated() ? [ + authorship: [ [ - req.user.id, + req.isAuthenticated() ? req.user.id : null, 0, content.length, now, now ] - ] : [] + ] }) if (!updated) {