Skip to content

Commit e00eaa8

Browse files
authored
Merge pull request #1665 from glpatcern/develop
Support anonymous updates via API if allowAnonymousEdits is true
2 parents a7d392c + dc37e5d commit e00eaa8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/note/index.js

+6-4
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({
@@ -294,7 +294,7 @@ const updateNote = async (req, res) => {
294294
lastchangeAt: now,
295295
authorship: [
296296
[
297-
req.user.id,
297+
req.isAuthenticated() ? req.user.id : null,
298298
0,
299299
content.length,
300300
now,
@@ -308,7 +308,9 @@ const updateNote = async (req, res) => {
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)