File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -77,13 +77,27 @@ async function showNote (req, res) {
77
77
return responseCodiMD ( res , note )
78
78
}
79
79
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
+
80
90
async function showPublishNote ( req , res ) {
81
91
const shortid = req . params . shortid
82
92
83
93
const note = await getNoteById ( shortid , {
84
94
includeUser : true
85
95
} )
86
96
97
+ if ( ! canViewNote ( note , req . isAuthenticated ( ) , req . user ? req . user . id : null ) ) {
98
+ return errorForbidden ( req )
99
+ }
100
+
87
101
if ( ! note ) {
88
102
return errorNotFound ( res )
89
103
}
@@ -130,10 +144,15 @@ async function noteActions (req, res) {
130
144
const noteId = req . params . noteId
131
145
132
146
const note = await getNoteById ( noteId )
147
+
133
148
if ( ! note ) {
134
149
return errorNotFound ( res )
135
150
}
136
151
152
+ if ( ! canViewNote ( note , req . isAuthenticated ( ) , req . user ? req . user . id : null ) ) {
153
+ return errorForbidden ( req )
154
+ }
155
+
137
156
const action = req . params . action
138
157
switch ( action ) {
139
158
case 'publish' :
You can’t perform that action at this time.
0 commit comments