|
@@ -6,24 +6,32 @@ const express = require('express');
|
|
|
|
|
|
|
|
const router = express.Router();
|
|
const router = express.Router();
|
|
|
|
|
|
|
|
|
|
+const ApiResponse = require('../../util/apiResponse');
|
|
|
|
|
+
|
|
|
// TODO: add swagger by GW3441
|
|
// TODO: add swagger by GW3441
|
|
|
|
|
|
|
|
module.exports = (crowi) => {
|
|
module.exports = (crowi) => {
|
|
|
const accessTokenParser = require('../../middlewares/access-token-parser')(crowi);
|
|
const accessTokenParser = require('../../middlewares/access-token-parser')(crowi);
|
|
|
const loginRequired = require('../../middlewares/login-required')(crowi);
|
|
const loginRequired = require('../../middlewares/login-required')(crowi);
|
|
|
|
|
+ const Page = crowi.model('Page');
|
|
|
const Attachment = crowi.model('Attachment');
|
|
const Attachment = crowi.model('Attachment');
|
|
|
|
|
|
|
|
router.get('/list', accessTokenParser, loginRequired, async(req, res) => {
|
|
router.get('/list', accessTokenParser, loginRequired, async(req, res) => {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- const id = req.query.page;
|
|
|
|
|
- const attachments = await Attachment.find({ page: id });
|
|
|
|
|
-
|
|
|
|
|
|
|
+ const pageId = req.query.page;
|
|
|
|
|
+ // check whether accessible
|
|
|
|
|
+ const isAccessible = await Page.isAccessiblePageByViewer(pageId, req.user);
|
|
|
|
|
+
|
|
|
|
|
+ if (!isAccessible) {
|
|
|
|
|
+ return res.json(ApiResponse.error('Current user is not accessible to this page.'));
|
|
|
|
|
+ }
|
|
|
|
|
+ const attachments = await Attachment.find({ page: pageId });
|
|
|
return res.apiv3({ attachments });
|
|
return res.apiv3({ attachments });
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
logger.error('Attachment not found', err);
|
|
logger.error('Attachment not found', err);
|
|
|
- return res.apiv3Err(err, 404);
|
|
|
|
|
|
|
+ return res.apiv3Err(err, 500);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|