mirror of https://github.com/status-im/codimd.git
fix(noteController): should check permission when user view note
Signed-off-by: BoHong Li <raccoon@hackmd.io>
This commit is contained in:
parent
ea52ed8689
commit
7969d17366
|
@ -77,6 +77,16 @@ async function showNote (req, res) {
|
||||||
return responseCodiMD(res, note)
|
return responseCodiMD(res, note)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function canViewNote (note, isLogin, userId) {
|
||||||
|
if (note.permission === 'private') {
|
||||||
|
return note.ownerId === userId
|
||||||
|
}
|
||||||
|
if (note.permission === 'limited' || note.permission === 'protected') {
|
||||||
|
return isLogin
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
async function showPublishNote (req, res) {
|
async function showPublishNote (req, res) {
|
||||||
const shortid = req.params.shortid
|
const shortid = req.params.shortid
|
||||||
|
|
||||||
|
@ -84,6 +94,10 @@ async function showPublishNote (req, res) {
|
||||||
includeUser: true
|
includeUser: true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!canViewNote(note, req.isAuthenticated(), req.user ? req.user.id : null)) {
|
||||||
|
return errorForbidden(req)
|
||||||
|
}
|
||||||
|
|
||||||
if (!note) {
|
if (!note) {
|
||||||
return errorNotFound(res)
|
return errorNotFound(res)
|
||||||
}
|
}
|
||||||
|
@ -130,10 +144,15 @@ async function noteActions (req, res) {
|
||||||
const noteId = req.params.noteId
|
const noteId = req.params.noteId
|
||||||
|
|
||||||
const note = await getNoteById(noteId)
|
const note = await getNoteById(noteId)
|
||||||
|
|
||||||
if (!note) {
|
if (!note) {
|
||||||
return errorNotFound(res)
|
return errorNotFound(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!canViewNote(note, req.isAuthenticated(), req.user ? req.user.id : null)) {
|
||||||
|
return errorForbidden(req)
|
||||||
|
}
|
||||||
|
|
||||||
const action = req.params.action
|
const action = req.params.action
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'publish':
|
case 'publish':
|
||||||
|
|
Loading…
Reference in New Issue