Skip to content

Commit 6b1ce38

Browse files
committed
fix: change errorForbidden function signature, add req into function parameter
avoid incorrect function parameter passing Signed-off-by: BoHong Li <[email protected]>
1 parent 7870b82 commit 6b1ce38

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

lib/history/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function historyGet (req, res) {
123123
})
124124
})
125125
} else {
126-
return response.errorForbidden(res)
126+
return response.errorForbidden(req, res)
127127
}
128128
}
129129

@@ -164,7 +164,7 @@ function historyPost (req, res) {
164164
})
165165
}
166166
} else {
167-
return response.errorForbidden(res)
167+
return response.errorForbidden(req, res)
168168
}
169169
}
170170

@@ -188,7 +188,7 @@ function historyDelete (req, res) {
188188
})
189189
}
190190
} else {
191-
return response.errorForbidden(res)
191+
return response.errorForbidden(req, res)
192192
}
193193
}
194194

lib/imageRouter/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ imageRouter.post('/uploadimage', function (req, res) {
2121

2222
form.parse(req, function (err, fields, files) {
2323
if (err || !files.image || !files.image.path) {
24-
response.errorForbidden(res)
24+
response.errorForbidden(req, res)
2525
} else {
2626
if (config.debug) {
2727
logger.info('SERVER received uploadimage: ' + JSON.stringify(files.image))

lib/note/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function showNote (req, res) {
6666
}
6767

6868
if (!newCheckViewPermission(note, req.isAuthenticated(), userId)) {
69-
return errorForbidden(res)
69+
return errorForbidden(req, res)
7070
}
7171

7272
// force to use note id
@@ -99,7 +99,7 @@ async function showPublishNote (req, res) {
9999
}
100100

101101
if (!canViewNote(note, req.isAuthenticated(), req.user ? req.user.id : null)) {
102-
return errorForbidden(req)
102+
return errorForbidden(req, res)
103103
}
104104

105105
if ((note.alias && shortid !== note.alias) || (!note.alias && shortid !== note.shortid)) {
@@ -150,7 +150,7 @@ async function noteActions (req, res) {
150150
}
151151

152152
if (!canViewNote(note, req.isAuthenticated(), req.user ? req.user.id : null)) {
153-
return errorForbidden(req)
153+
return errorForbidden(req, res)
154154
}
155155

156156
const action = req.params.action
@@ -171,7 +171,7 @@ async function noteActions (req, res) {
171171
actionPDF(req, res, note)
172172
} else {
173173
logger.error('PDF export failed: Disabled by config. Set "allowPDFExport: true" to enable. Check the documentation for details')
174-
errorForbidden(res)
174+
errorForbidden(req, res)
175175
}
176176
break
177177
case 'gist':

lib/response.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ exports.checkViewPermission = checkViewPermission
2828
exports.newCheckViewPermission = newCheckViewPermission
2929
exports.responseCodiMD = responseCodiMD
3030

31-
function errorForbidden (res) {
32-
const { req } = res
31+
function errorForbidden (req, res) {
3332
if (req.user) {
3433
responseError(res, '403', 'Forbidden', 'oh no.')
3534
} else {
@@ -100,7 +99,7 @@ function newNote (req, res, next) {
10099
if (req.isAuthenticated()) {
101100
owner = req.user.id
102101
} else if (!config.allowAnonymous) {
103-
return errorForbidden(res)
102+
return errorForbidden(req, res)
104103
}
105104
models.Note.create({
106105
ownerId: owner,
@@ -161,7 +160,7 @@ function findNote (req, res, callback, include) {
161160
}
162161
}
163162
if (!checkViewPermission(req, note)) {
164-
return errorForbidden(res)
163+
return errorForbidden(req, res)
165164
} else {
166165
return callback(note)
167166
}
@@ -239,7 +238,7 @@ function githubActionGist (req, res, note) {
239238
var code = req.query.code
240239
var state = req.query.state
241240
if (!code || !state) {
242-
return errorForbidden(res)
241+
return errorForbidden(req, res)
243242
} else {
244243
var data = {
245244
client_id: config.github.clientID,
@@ -279,14 +278,14 @@ function githubActionGist (req, res, note) {
279278
res.setHeader('referer', '')
280279
res.redirect(body.html_url)
281280
} else {
282-
return errorForbidden(res)
281+
return errorForbidden(req, res)
283282
}
284283
})
285284
} else {
286-
return errorForbidden(res)
285+
return errorForbidden(req, res)
287286
}
288287
} else {
289-
return errorForbidden(res)
288+
return errorForbidden(req, res)
290289
}
291290
})
292291
}
@@ -334,7 +333,7 @@ function gitlabActionProjects (req, res, note) {
334333
return errorInternalError(res)
335334
})
336335
} else {
337-
return errorForbidden(res)
336+
return errorForbidden(req, res)
338337
}
339338
}
340339

lib/user/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ exports.getMe = async (req, res) => {
3737

3838
exports.deleteUser = async (req, res) => {
3939
if (!req.isAuthenticated()) {
40-
return response.errorForbidden(res)
40+
return response.errorForbidden(req, res)
4141
}
4242

4343
const user = await models.User.findOne({
@@ -51,7 +51,7 @@ exports.deleteUser = async (req, res) => {
5151
}
5252

5353
if (user.deleteToken !== req.params.token) {
54-
return response.errorForbidden(res)
54+
return response.errorForbidden(req, res)
5555
}
5656

5757
await user.destroy()
@@ -60,7 +60,7 @@ exports.deleteUser = async (req, res) => {
6060

6161
exports.exportMyData = (req, res) => {
6262
if (!req.isAuthenticated()) {
63-
return response.errorForbidden(res)
63+
return response.errorForbidden(req, res)
6464
}
6565

6666
const archive = archiver('zip', {

0 commit comments

Comments
 (0)