mirror of https://github.com/status-im/codimd.git
Merge pull request #1665 from glpatcern/develop
Support anonymous updates via API if allowAnonymousEdits is true
This commit is contained in:
commit
e00eaa82a9
|
@ -268,7 +268,7 @@ const deleteNote = async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateNote = async (req, res) => {
|
const updateNote = async (req, res) => {
|
||||||
if (req.isAuthenticated()) {
|
if (req.isAuthenticated() || config.allowAnonymousEdits) {
|
||||||
const noteId = await Note.parseNoteIdAsync(req.params.noteId)
|
const noteId = await Note.parseNoteIdAsync(req.params.noteId)
|
||||||
try {
|
try {
|
||||||
const note = await Note.findOne({
|
const note = await Note.findOne({
|
||||||
|
@ -294,7 +294,7 @@ const updateNote = async (req, res) => {
|
||||||
lastchangeAt: now,
|
lastchangeAt: now,
|
||||||
authorship: [
|
authorship: [
|
||||||
[
|
[
|
||||||
req.user.id,
|
req.isAuthenticated() ? req.user.id : null,
|
||||||
0,
|
0,
|
||||||
content.length,
|
content.length,
|
||||||
now,
|
now,
|
||||||
|
@ -308,7 +308,9 @@ const updateNote = async (req, res) => {
|
||||||
return errorInternalError(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) => {
|
Revision.saveNoteRevision(note, (err, revision) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -321,7 +323,7 @@ const updateNote = async (req, res) => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err)
|
logger.error(err.stack)
|
||||||
logger.error('Update note failed: Internal Error.')
|
logger.error('Update note failed: Internal Error.')
|
||||||
return errorInternalError(req, res)
|
return errorInternalError(req, res)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue