Skip to content

Commit

Permalink
Support anonymous updates via API if allowAnonymousEdits is true
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Lo Presti <giuseppe.lopresti@cern.ch>
  • Loading branch information
glpatcern committed Mar 9, 2021
1 parent 7200506 commit c9399f3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/note/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -292,23 +292,25 @@ const updateNote = async (req, res) => {
title: Note.parseNoteTitle(content),
content: content,
lastchangeAt: now,
authorship: [
authorship: req.isAuthenticated() ? [
[
req.user.id,
0,
content.length,
now,
now
]
]
] : []
})

if (!updated) {
logger.error('Update note failed: Write note content error.')
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) {
Expand All @@ -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)
}
Expand Down

0 comments on commit c9399f3

Please sign in to comment.