Taichi Masuyama 4 years ago
parent
commit
25d0e56f6f

+ 4 - 0
packages/app/src/server/crowi/index.js

@@ -20,6 +20,7 @@ import AppService from '../service/app';
 import AclService from '../service/acl';
 import SearchService from '../service/search';
 import AttachmentService from '../service/attachment';
+import PageGrantService from '../service/page-grant';
 import { SlackIntegrationService } from '../service/slack-integration';
 import { UserNotificationService } from '../service/user-notification';
 
@@ -682,6 +683,9 @@ Crowi.prototype.setupPageService = async function() {
   if (this.pageService == null) {
     this.pageService = new PageEventService(this);
   }
+  if (this.pageGrantService == null) {
+    this.pageGrantService = new PageGrantService(this);
+  }
 };
 
 Crowi.prototype.setupInAppNotificationService = async function() {

+ 0 - 3
packages/app/src/server/models/obsolete-page.js

@@ -1002,9 +1002,6 @@ export const getPageSchema = (crowi) => {
       /*
        * UserGroup & Owner validation
        */
-      // if parent is null, find ancestors by ancestorsPath and check the grant of the page has the longest path
-      // if parent is not null, check the grant of it
-      // note: I think empty pages should also be grant private
 
 
       /*

+ 41 - 0
packages/app/src/server/service/page-grant.ts

@@ -0,0 +1,41 @@
+import mongoose from 'mongoose';
+
+import UserGroup from '~/server/models/user-group';
+import { PageModel, PageDocument } from '~/server/models/page';
+
+class PageGrantService {
+
+  crowi!: any;
+
+  Page: PageModel;
+
+  constructor(crowi: any) {
+    this.crowi = crowi;
+  }
+
+  async validateByTestAncestor(target: PageDocument, testAncestor: PageDocument): Promise<boolean> {
+    return false;
+  }
+
+  async validateByDescendant(target: PageDocument): Promise<boolean> {
+    return false;
+  }
+
+  async pageCreateValidation(pathToCreate) {
+    const Page = mongoose.model('Page');
+
+    // try to find target
+    const emptyTarget = await Page.findOne({ path: pathToCreate });
+
+    if (emptyTarget == null) { // checking the parent is enough
+
+    }
+
+    // get grant, grantedUser, grantedGroup of the target
+    // find the nearest parent excluding empty pages
+    // find all descendants & collect all
+  }
+
+}
+
+export default PageGrantService;