Merge pull request #926 from hedgedoc/1.x/note-nonexistent-404

Add HTTP 404 error on actions for non-existent notes
This commit is contained in:
David Mehren 2021-02-19 11:57:11 +01:00 committed by GitHub
commit 090d4178d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -119,7 +119,7 @@ exports.doAction = function (req, res, next) {
default:
return res.redirect(config.serverURL + '/' + noteId)
}
})
}, null, false)
}
exports.downloadMarkdown = function (req, res, note) {

View file

@ -5,7 +5,7 @@ const errors = require('../../errors')
const fs = require('fs')
const path = require('path')
exports.findNote = function (req, res, callback, include) {
exports.findNote = function (req, res, callback, include, createIfNotFound = true) {
const id = req.params.noteId || req.params.shortid
models.Note.parseNoteId(id, function (err, _id) {
if (err) {
@ -18,9 +18,12 @@ exports.findNote = function (req, res, callback, include) {
},
include: include || null
}).then(function (note) {
if (!note) {
if (!note && createIfNotFound) {
return exports.newNote(req, res, '')
}
if (!note && !createIfNotFound) {
return errors.errorNotFound(res)
}
if (!exports.checkViewPermission(req, note)) {
return errors.errorForbidden(res)
} else {