Просмотр исходного кода

Improved controller to ensure compatibility for other usages

Taichi Masuyama 3 лет назад
Родитель
Сommit
df8338646f

+ 0 - 3
packages/app/src/server/routes/apiv3/page.js

@@ -451,9 +451,6 @@ module.exports = (crowi) => {
     if (page == null) {
       return res.apiv3Err(new ErrorV3('Page is unreachable or empty.', 'page_unreachable_or_empty'), 400);
     }
-    if (isTopPage(page.path) || page.parent == null) {
-      return res.apiv3();
-    }
 
     let data;
     try {

+ 23 - 4
packages/app/src/server/service/page-grant.ts

@@ -408,6 +408,29 @@ class PageGrantService {
     const Page = mongoose.model('Page') as unknown as PageModel;
     const UserGroupRelation = mongoose.model('UserGroupRelation') as any; // TODO: Typescriptize model
 
+    // Increment an object (type IRecordApplicableGrant)
+    // grant is never public, anyone with the link, nor specified
+    const data: IRecordApplicableGrant = {
+      [Page.GRANT_RESTRICTED]: null, // any page can be restricted
+    };
+
+    // -- Public only if top page
+    const isOnlyPublicApplicable = isTopPage(page.path);
+    if (isOnlyPublicApplicable) {
+      data[Page.GRANT_PUBLIC] = null;
+      return data;
+    }
+
+    // -- Any grant is allowed if parent is null
+    const isAnyGrantApplicable = page.parent == null;
+    if (isAnyGrantApplicable) {
+      data[Page.GRANT_PUBLIC] = null;
+      data[Page.GRANT_OWNER] = null;
+      data[Page.GRANT_USER_GROUP] = await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user);
+      return data;
+    }
+
+    // -- Public is not applicable below
     const parent = await Page.findById(page.parent);
     if (parent == null) {
       throw Error('The page\'s parent does not exist.');
@@ -417,10 +440,6 @@ class PageGrantService {
       grant, grantedUsers, grantedGroup,
     } = parent;
 
-    // Increment an object (type IRecordApplicableGrant)
-    // grant is never public, anyone with the link, nor specified
-    const data: IRecordApplicableGrant = {};
-
     if (grant === Page.GRANT_OWNER) {
       const grantedUser = grantedUsers[0];