Explorar el Código

add permission in tag update api

yuto-o hace 4 años
padre
commit
22656c5f35
Se han modificado 1 ficheros con 8 adiciones y 0 borrados
  1. 8 0
      packages/app/src/server/routes/tag.js

+ 8 - 0
packages/app/src/server/routes/tag.js

@@ -136,15 +136,23 @@ module.exports = function(crowi, app) {
    */
   api.update = async function(req, res) {
     const Page = crowi.model('Page');
+    const User = crowi.model('User');
     const PageTagRelation = crowi.model('PageTagRelation');
     const tagEvent = crowi.event('tag');
     const pageId = req.body.pageId;
     const tags = req.body.tags;
+    const userId = req.user._id;
 
     const result = {};
     try {
       // TODO GC-1921 consider permission
       const page = await Page.findById(pageId);
+      const user = await User.findById(userId);
+
+      if (!await Page.isAccessiblePageByViewer(page._id, user)) {
+        return res.json(ApiResponse.error("You don't have permission to update this page"));
+      }
+
       await PageTagRelation.updatePageTags(pageId, tags);
       result.tags = await PageTagRelation.listTagNamesByPage(pageId);