Skip to content

Commit c9399f3

Browse files
committed
Support anonymous updates via API if allowAnonymousEdits is true
Signed-off-by: Giuseppe Lo Presti <giuseppe.lopresti@cern.ch>
1 parent 7200506 commit c9399f3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/note/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ const deleteNote = async (req, res) => {
268268
}
269269

270270
const updateNote = async (req, res) => {
271-
if (req.isAuthenticated()) {
271+
if (req.isAuthenticated() || config.allowAnonymousEdits) {
272272
const noteId = await Note.parseNoteIdAsync(req.params.noteId)
273273
try {
274274
const note = await Note.findOne({
@@ -292,23 +292,25 @@ const updateNote = async (req, res) => {
292292
title: Note.parseNoteTitle(content),
293293
content: content,
294294
lastchangeAt: now,
295-
authorship: [
295+
authorship: req.isAuthenticated() ? [
296296
[
297297
req.user.id,
298298
0,
299299
content.length,
300300
now,
301301
now
302302
]
303-
]
303+
] : []
304304
})
305305

306306
if (!updated) {
307307
logger.error('Update note failed: Write note content error.')
308308
return errorInternalError(req, res)
309309
}
310310

311-
updateHistory(req.user.id, note.id, content)
311+
if (req.isAuthenticated()) {
312+
updateHistory(req.user.id, note.id, content)
313+
}
312314

313315
Revision.saveNoteRevision(note, (err, revision) => {
314316
if (err) {
@@ -321,7 +323,7 @@ const updateNote = async (req, res) => {
321323
})
322324
})
323325
} catch (err) {
324-
logger.error(err)
326+
logger.error(err.stack)
325327
logger.error('Update note failed: Internal Error.')
326328
return errorInternalError(req, res)
327329
}

0 commit comments

Comments
 (0)