File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,13 +77,27 @@ async function showNote (req, res) {
7777 return responseCodiMD ( res , note )
7878}
7979
80+ function canViewNote ( note , isLogin , userId ) {
81+ if ( note . permission === 'private' ) {
82+ return note . ownerId === userId
83+ }
84+ if ( note . permission === 'limited' || note . permission === 'protected' ) {
85+ return isLogin
86+ }
87+ return true
88+ }
89+
8090async function showPublishNote ( req , res ) {
8191 const shortid = req . params . shortid
8292
8393 const note = await getNoteById ( shortid , {
8494 includeUser : true
8595 } )
8696
97+ if ( ! canViewNote ( note , req . isAuthenticated ( ) , req . user ? req . user . id : null ) ) {
98+ return errorForbidden ( req )
99+ }
100+
87101 if ( ! note ) {
88102 return errorNotFound ( res )
89103 }
@@ -130,10 +144,15 @@ async function noteActions (req, res) {
130144 const noteId = req . params . noteId
131145
132146 const note = await getNoteById ( noteId )
147+
133148 if ( ! note ) {
134149 return errorNotFound ( res )
135150 }
136151
152+ if ( ! canViewNote ( note , req . isAuthenticated ( ) , req . user ? req . user . id : null ) ) {
153+ return errorForbidden ( req )
154+ }
155+
137156 const action = req . params . action
138157 switch ( action ) {
139158 case 'publish' :
You can’t perform that action at this time.
0 commit comments