|
@@ -1,62 +1,48 @@
|
|
|
import { PageGrant } from '@growi/core';
|
|
import { PageGrant } from '@growi/core';
|
|
|
|
|
+import { Types } from 'mongoose';
|
|
|
|
|
|
|
|
-const mongoose = require('mongoose');
|
|
|
|
|
|
|
+import type { ImportOptionForPages } from '~/models/admin/import-option-for-pages';
|
|
|
|
|
|
|
|
-// eslint-disable-next-line no-unused-vars
|
|
|
|
|
-const ImportOptionForPages = require('~/models/admin/import-option-for-pages');
|
|
|
|
|
|
|
+import type { OverwriteParams } from '../import-settings';
|
|
|
|
|
|
|
|
-const { ObjectId } = mongoose.Types;
|
|
|
|
|
|
|
+const { ObjectId } = Types;
|
|
|
|
|
|
|
|
-class PageOverwriteParamsFactory {
|
|
|
|
|
|
|
+export const generateOverwriteParams = (operatorUserId: string, option: ImportOptionForPages): OverwriteParams => {
|
|
|
|
|
+ const params: OverwriteParams = {};
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * generate overwrite params object
|
|
|
|
|
- * @param {string} operatorUserId
|
|
|
|
|
- * @param {ImportOptionForPages} option
|
|
|
|
|
- * @return {import('~/server/service/import').OverwriteParams}
|
|
|
|
|
- * key: property name
|
|
|
|
|
- * value: any value or a function `(value, { document, schema, propertyName }) => { return newValue }`
|
|
|
|
|
- */
|
|
|
|
|
- static generate(operatorUserId, option) {
|
|
|
|
|
- const params = {};
|
|
|
|
|
|
|
+ if (option.isOverwriteAuthorWithCurrentUser) {
|
|
|
|
|
+ const userId = new ObjectId(operatorUserId);
|
|
|
|
|
+ params.creator = userId;
|
|
|
|
|
+ params.lastUpdateUser = userId;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (option.isOverwriteAuthorWithCurrentUser) {
|
|
|
|
|
- const userId = ObjectId(operatorUserId);
|
|
|
|
|
- params.creator = userId;
|
|
|
|
|
- params.lastUpdateUser = userId;
|
|
|
|
|
|
|
+ params.grant = (value, { document, schema, propertyName }) => {
|
|
|
|
|
+ if (option.makePublicForGrant2 && value === 2) {
|
|
|
|
|
+ return PageGrant.GRANT_PUBLIC;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- params.grant = (value, { document, schema, propertyName }) => {
|
|
|
|
|
- if (option.makePublicForGrant2 && value === 2) {
|
|
|
|
|
- return PageGrant.GRANT_PUBLIC;
|
|
|
|
|
- }
|
|
|
|
|
- if (option.makePublicForGrant4 && value === 4) {
|
|
|
|
|
- return PageGrant.GRANT_PUBLIC;
|
|
|
|
|
- }
|
|
|
|
|
- if (option.makePublicForGrant5 && value === 5) {
|
|
|
|
|
- return PageGrant.GRANT_PUBLIC;
|
|
|
|
|
- }
|
|
|
|
|
- return value;
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- params.parent = (value, { document, schema, propertyName }) => {
|
|
|
|
|
- return null;
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- params.descendantCount = (value, { document, schema, propertyName }) => {
|
|
|
|
|
- return 0;
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- if (option.initPageMetadatas) {
|
|
|
|
|
- params.liker = [];
|
|
|
|
|
- params.seenUsers = [];
|
|
|
|
|
- params.commentCount = 0;
|
|
|
|
|
- params.extended = {};
|
|
|
|
|
|
|
+ if (option.makePublicForGrant4 && value === 4) {
|
|
|
|
|
+ return PageGrant.GRANT_PUBLIC;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- return params;
|
|
|
|
|
|
|
+ if (option.makePublicForGrant5 && value === 5) {
|
|
|
|
|
+ return PageGrant.GRANT_PUBLIC;
|
|
|
|
|
+ }
|
|
|
|
|
+ return value;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ params.parent = (value, { document, schema, propertyName }) => {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ params.descendantCount = (value, { document, schema, propertyName }) => {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ if (option.initPageMetadatas) {
|
|
|
|
|
+ params.liker = [];
|
|
|
|
|
+ params.seenUsers = [];
|
|
|
|
|
+ params.commentCount = 0;
|
|
|
|
|
+ params.extended = {};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-module.exports = (operatorUserId, option) => PageOverwriteParamsFactory.generate(operatorUserId, option);
|
|
|
|
|
|
|
+ return params;
|
|
|
|
|
+};
|