Skip to content

Commit

Permalink
Merge pull request #1665 from glpatcern/develop
Browse files Browse the repository at this point in the history
Support anonymous updates via API if allowAnonymousEdits is true
  • Loading branch information
Yukaii authored Mar 22, 2021
2 parents a7d392c + dc37e5d commit e00eaa8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 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 @@ -294,7 +294,7 @@ const updateNote = async (req, res) => {
lastchangeAt: now,
authorship: [
[
req.user.id,
req.isAuthenticated() ? req.user.id : null,
0,
content.length,
now,
Expand All @@ -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) {
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 e00eaa8

Please sign in to comment.