Support anonymous updates via API if allowAnonymousEdits is true

Signed-off-by: Giuseppe Lo Presti <giuseppe.lopresti@cern.ch>
This commit is contained in:
Giuseppe Lo Presti 2021-03-09 12:31:46 +01:00
parent 7200506563
commit c9399f33d1
1 changed files with 7 additions and 5 deletions

View File

@ -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)
}