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

+ 4 - 7
packages/app/src/server/models/obsolete-page.js

@@ -247,13 +247,10 @@ export const getPageSchema = (crowi) => {
     return this.populate('revision');
   };
 
-  pageSchema.methods.applyScope = function(user, grant, grantUserGroupId, grantedUsers, options = {}) {
+  pageSchema.methods.applyScope = function(user, grant, grantUserGroupId, grantedUsers) {
     // Validate
-    if (grant === GRANT_OWNER && options.isSystematically && grantedUsers?.length !== 1) {
-      throw Error('The grantedUsers must exist when (GRANT_OWNER && isSystematically).');
-    }
-    if (grant === GRANT_OWNER && !options.isSystematically && user == null) {
-      throw Error('The user must exist when (GRANT_OWNER && !isSystematically).');
+    if (grant === GRANT_OWNER && (user == null && grantedUsers?.length !== 1)) {
+      throw Error('The "user" or "grantedUsers" must exist when the grant is GRANT_OWNER.');
     }
 
     // Reset
@@ -263,7 +260,7 @@ export const getPageSchema = (crowi) => {
     this.grant = grant || GRANT_PUBLIC;
 
     if (grant === GRANT_OWNER) {
-      this.grantedUsers.push(options.isSystematically ? grantedUsers[0] : user._id);
+      this.grantedUsers.push(grantedUsers[0] ?? user._id);
     }
 
     if (grant === GRANT_USER_GROUP) {

+ 7 - 7
packages/app/src/server/models/page.ts

@@ -861,11 +861,11 @@ schema.statics.findAncestorsChildrenByPathAndViewer = async function(path: strin
 /*
  * Utils from obsolete-page.js
  */
-async function pushRevision(pageData, newRevision, user, options?: { isSystematically?: boolean }) {
+async function pushRevision(pageData, newRevision, user) {
   await newRevision.save();
 
   pageData.revision = newRevision;
-  pageData.lastUpdateUser = options?.isSystematically ? null : user;
+  pageData.lastUpdateUser = user._id;
   pageData.updatedAt = Date.now();
 
   return pageData.save();
@@ -1102,10 +1102,10 @@ export default (crowi: Crowi): any => {
       throw Error('This method is only available when v5 compatibale.');
     }
 
-    const user = null;
+    const dummyUser = { _id: new mongoose.Types.ObjectId() };
 
     options.isSystematically = true;
-    return (this.create as CreateMethod)(path, mrkdwn, user, options);
+    return (this.create as CreateMethod)(path, mrkdwn, dummyUser, options);
   };
 
   schema.statics.create = async function(path: string, body: string, user, options: PageCreateOptions = {}) {
@@ -1204,7 +1204,7 @@ export default (crowi: Crowi): any => {
       page.parent = parent._id;
     }
 
-    page.applyScope(user, grant, grantUserGroupId, grantedUserIds, { isSystematically });
+    page.applyScope(user, grant, grantUserGroupId, grantedUserIds);
 
     let savedPage = await page.save();
 
@@ -1222,8 +1222,8 @@ export default (crowi: Crowi): any => {
       logger.error('Failed to delete PageRedirect');
     }
 
-    const newRevision = Revision.prepareRevision(savedPage, body, null, user, { format, isSystematically });
-    savedPage = await pushRevision(savedPage, newRevision, user, { isSystematically });
+    const newRevision = Revision.prepareRevision(savedPage, body, null, user, { format });
+    savedPage = await pushRevision(savedPage, newRevision, user);
     await savedPage.populateDataToShowRevision();
 
     pageEvent.emit('create', savedPage, user);

+ 1 - 1
packages/app/src/server/models/revision.js

@@ -46,7 +46,7 @@ module.exports = function(crowi) {
     }
     const format = options.format || 'markdown';
 
-    if (!options.isSystematically && !user._id) {
+    if (!user._id) {
       throw new Error('Error: user should have _id');
     }
 

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

@@ -2294,7 +2294,6 @@ class PageService {
           grant: notEmptyParent.grant,
           grantedUserIds: notEmptyParent.grantedUsers,
           grantUserGroupId: notEmptyParent.grantedGroup,
-          isSystematically: true,
         },
       );
       page = systematicallyCreatedPage;