obsolete-page.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. import { PageGrant, GroupType } from '@growi/core';
  2. import { templateChecker, pagePathUtils, pathUtils } from '@growi/core/dist/utils';
  3. import escapeStringRegexp from 'escape-string-regexp';
  4. import { Comment } from '~/features/comment/server/models/comment';
  5. import ExternalUserGroup from '~/features/external-user-group/server/models/external-user-group';
  6. import ExternalUserGroupRelation from '~/features/external-user-group/server/models/external-user-group-relation';
  7. import loggerFactory from '~/utils/logger';
  8. import UserGroup from './user-group';
  9. import UserGroupRelation from './user-group-relation';
  10. // disable no-return-await for model functions
  11. /* eslint-disable no-return-await */
  12. /* eslint-disable no-use-before-define */
  13. const nodePath = require('path');
  14. const differenceInYears = require('date-fns/differenceInYears');
  15. const debug = require('debug')('growi:models:page');
  16. const mongoose = require('mongoose');
  17. const urljoin = require('url-join');
  18. const { isTopPage, isTrashPage } = pagePathUtils;
  19. const { checkTemplatePath } = templateChecker;
  20. const logger = loggerFactory('growi:models:page');
  21. const GRANT_PUBLIC = 1;
  22. const GRANT_RESTRICTED = 2;
  23. const GRANT_SPECIFIED = 3;
  24. const GRANT_OWNER = 4;
  25. const GRANT_USER_GROUP = 5;
  26. const PAGE_GRANT_ERROR = 1;
  27. const STATUS_PUBLISHED = 'published';
  28. const STATUS_DELETED = 'deleted';
  29. // schema definition has moved to page.ts
  30. const pageSchema = {
  31. statics: {},
  32. methods: {},
  33. };
  34. /**
  35. * return an array of ancestors paths that is extracted from specified pagePath
  36. * e.g.
  37. * when `pagePath` is `/foo/bar/baz`,
  38. * this method returns [`/foo/bar/baz`, `/foo/bar`, `/foo`, `/`]
  39. *
  40. * @param {string} pagePath
  41. * @return {string[]} ancestors paths
  42. */
  43. export const extractToAncestorsPaths = (pagePath) => {
  44. const ancestorsPaths = [];
  45. let parentPath;
  46. while (parentPath !== '/') {
  47. parentPath = nodePath.dirname(parentPath || pagePath);
  48. ancestorsPaths.push(parentPath);
  49. }
  50. return ancestorsPaths;
  51. };
  52. /**
  53. * populate page (Query or Document) to show revision
  54. * @param {any} page Query or Document
  55. * @param {string} userPublicFields string to set to select
  56. * @param {boolean} shouldExcludeBody boolean indicating whether to include 'revision.body' or not
  57. */
  58. /* eslint-disable object-curly-newline, object-property-newline */
  59. export const populateDataToShowRevision = (page, userPublicFields, shouldExcludeBody = false) => {
  60. return page
  61. .populate([
  62. { path: 'lastUpdateUser', select: userPublicFields },
  63. { path: 'creator', select: userPublicFields },
  64. { path: 'deleteUser', select: userPublicFields },
  65. { path: 'grantedGroups.item' },
  66. { path: 'revision', select: shouldExcludeBody ? '-body' : undefined, populate: {
  67. path: 'author', select: userPublicFields,
  68. } },
  69. ]);
  70. };
  71. /* eslint-enable object-curly-newline, object-property-newline */
  72. export const getPageSchema = (crowi) => {
  73. let pageEvent;
  74. // init event
  75. if (crowi != null) {
  76. pageEvent = crowi.event('page');
  77. pageEvent.on('create', pageEvent.onCreate);
  78. pageEvent.on('update', pageEvent.onUpdate);
  79. pageEvent.on('createMany', pageEvent.onCreateMany);
  80. pageEvent.on('addSeenUsers', pageEvent.onAddSeenUsers);
  81. }
  82. function validateCrowi() {
  83. if (crowi == null) {
  84. throw new Error('"crowi" is null. Init User model with "crowi" argument first.');
  85. }
  86. }
  87. pageSchema.methods.isDeleted = function() {
  88. return isTrashPage(this.path);
  89. };
  90. pageSchema.methods.isPublic = function() {
  91. if (!this.grant || this.grant === GRANT_PUBLIC) {
  92. return true;
  93. }
  94. return false;
  95. };
  96. pageSchema.methods.isTopPage = function() {
  97. return isTopPage(this.path);
  98. };
  99. pageSchema.methods.isTemplate = function() {
  100. return checkTemplatePath(this.path);
  101. };
  102. pageSchema.methods.isLatestRevision = function() {
  103. // populate されていなくて判断できない
  104. if (!this.latestRevision || !this.revision) {
  105. return true;
  106. }
  107. // comparing ObjectId with string
  108. // eslint-disable-next-line eqeqeq
  109. return (this.latestRevision == this.revision._id.toString());
  110. };
  111. pageSchema.methods.findRelatedTagsById = async function() {
  112. const PageTagRelation = mongoose.model('PageTagRelation');
  113. const relations = await PageTagRelation.find({ relatedPage: this._id }).populate('relatedTag');
  114. return relations.map((relation) => { return relation.relatedTag.name });
  115. };
  116. pageSchema.methods.isUpdatable = function(previousRevision) {
  117. const revision = this.latestRevision || this.revision;
  118. // comparing ObjectId with string
  119. // eslint-disable-next-line eqeqeq
  120. if (revision != previousRevision) {
  121. return false;
  122. }
  123. return true;
  124. };
  125. pageSchema.methods.isLiked = function(user) {
  126. if (user == null || user._id == null) {
  127. return false;
  128. }
  129. return this.liker.some((likedUserId) => {
  130. return likedUserId.toString() === user._id.toString();
  131. });
  132. };
  133. pageSchema.methods.like = function(userData) {
  134. const self = this;
  135. return new Promise(((resolve, reject) => {
  136. const added = self.liker.addToSet(userData._id);
  137. if (added.length > 0) {
  138. self.save((err, data) => {
  139. if (err) {
  140. return reject(err);
  141. }
  142. logger.debug('liker updated!', added);
  143. return resolve(data);
  144. });
  145. }
  146. else {
  147. logger.debug('liker not updated');
  148. return reject(new Error('Already liked'));
  149. }
  150. }));
  151. };
  152. pageSchema.methods.unlike = function(userData, callback) {
  153. const self = this;
  154. return new Promise(((resolve, reject) => {
  155. const beforeCount = self.liker.length;
  156. self.liker.pull(userData._id);
  157. if (self.liker.length !== beforeCount) {
  158. self.save((err, data) => {
  159. if (err) {
  160. return reject(err);
  161. }
  162. return resolve(data);
  163. });
  164. }
  165. else {
  166. logger.debug('liker not updated');
  167. return reject(new Error('Already unliked'));
  168. }
  169. }));
  170. };
  171. pageSchema.methods.isSeenUser = function(userData) {
  172. return this.seenUsers.includes(userData._id);
  173. };
  174. pageSchema.methods.seen = async function(userData) {
  175. if (this.isSeenUser(userData)) {
  176. debug('seenUsers not updated');
  177. return this;
  178. }
  179. if (!userData || !userData._id) {
  180. throw new Error('User data is not valid');
  181. }
  182. const added = this.seenUsers.addToSet(userData._id);
  183. const saved = await this.save();
  184. debug('seenUsers updated!', added);
  185. pageEvent.emit('addSeenUsers', saved);
  186. return saved;
  187. };
  188. pageSchema.methods.updateSlackChannels = function(slackChannels) {
  189. this.slackChannels = slackChannels;
  190. return this.save();
  191. };
  192. pageSchema.methods.initLatestRevisionField = async function(revisionId) {
  193. this.latestRevision = this.revision;
  194. if (revisionId != null) {
  195. this.revision = revisionId;
  196. }
  197. };
  198. pageSchema.methods.populateDataToShowRevision = async function(shouldExcludeBody) {
  199. validateCrowi();
  200. const User = crowi.model('User');
  201. return populateDataToShowRevision(this, User.USER_FIELDS_EXCEPT_CONFIDENTIAL, shouldExcludeBody);
  202. };
  203. pageSchema.methods.populateDataToMakePresentation = async function(revisionId) {
  204. this.latestRevision = this.revision;
  205. if (revisionId != null) {
  206. this.revision = revisionId;
  207. }
  208. return this.populate('revision');
  209. };
  210. pageSchema.methods.applyScope = function(user, grant, grantUserGroupIds) {
  211. // Reset
  212. this.grantedUsers = [];
  213. this.grantedGroups = [];
  214. this.grant = grant || GRANT_PUBLIC;
  215. if (grant === GRANT_OWNER) {
  216. this.grantedUsers.push(user?._id ?? user);
  217. }
  218. if (grant === GRANT_USER_GROUP) {
  219. this.grantedGroups = grantUserGroupIds;
  220. }
  221. };
  222. pageSchema.methods.getContentAge = function() {
  223. return differenceInYears(new Date(), this.updatedAt);
  224. };
  225. pageSchema.statics.updateCommentCount = function(pageId) {
  226. validateCrowi();
  227. const self = this;
  228. return Comment.countCommentByPageId(pageId)
  229. .then((count) => {
  230. self.update({ _id: pageId }, { commentCount: count }, {}, (err, data) => {
  231. if (err) {
  232. debug('Update commentCount Error', err);
  233. throw err;
  234. }
  235. return data;
  236. });
  237. });
  238. };
  239. pageSchema.statics.getDeletedPageName = function(path) {
  240. if (path.match('/')) {
  241. // eslint-disable-next-line no-param-reassign
  242. path = path.substr(1);
  243. }
  244. return `/trash/${path}`;
  245. };
  246. pageSchema.statics.getRevertDeletedPageName = function(path) {
  247. return path.replace('/trash', '');
  248. };
  249. pageSchema.statics.fixToCreatableName = function(path) {
  250. return path
  251. .replace(/\/\//g, '/');
  252. };
  253. pageSchema.statics.updateRevision = function(pageId, revisionId, cb) {
  254. this.update({ _id: pageId }, { revision: revisionId }, {}, (err, data) => {
  255. cb(err, data);
  256. });
  257. };
  258. /**
  259. * return whether the user is accessible to the page
  260. * @param {string} id ObjectId
  261. * @param {User} user
  262. */
  263. pageSchema.statics.isAccessiblePageByViewer = async function(id, user) {
  264. const baseQuery = this.count({ _id: id });
  265. const userGroups = user != null ? [
  266. ...(await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user)),
  267. ...(await ExternalUserGroupRelation.findAllUserGroupIdsRelatedToUser(user)),
  268. ] : [];
  269. const queryBuilder = new this.PageQueryBuilder(baseQuery);
  270. queryBuilder.addConditionToFilteringByViewer(user, userGroups, true);
  271. const count = await queryBuilder.query.exec();
  272. return count > 0;
  273. };
  274. /**
  275. * @param {string} id ObjectId
  276. * @param {User} user User instance
  277. * @param {UserGroup[]} userGroups List of UserGroup instances
  278. */
  279. pageSchema.statics.findByIdAndViewer = async function(id, user, userGroups, includeEmpty = false) {
  280. const baseQuery = this.findOne({ _id: id });
  281. const relatedUserGroups = (user != null && userGroups == null) ? [
  282. ...(await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user)),
  283. ...(await ExternalUserGroupRelation.findAllUserGroupIdsRelatedToUser(user)),
  284. ] : userGroups;
  285. const queryBuilder = new this.PageQueryBuilder(baseQuery, includeEmpty);
  286. queryBuilder.addConditionToFilteringByViewer(user, relatedUserGroups, true);
  287. return queryBuilder.query.exec();
  288. };
  289. // find page by path
  290. pageSchema.statics.findByPath = function(path, includeEmpty = false) {
  291. if (path == null) {
  292. return null;
  293. }
  294. const builder = new this.PageQueryBuilder(this.findOne({ path }), includeEmpty);
  295. return builder.query.exec();
  296. };
  297. /**
  298. * @param {string} path Page path
  299. * @param {User} user User instance
  300. * @param {UserGroup[]} userGroups List of UserGroup instances
  301. */
  302. pageSchema.statics.findAncestorByPathAndViewer = async function(path, user, userGroups, includeEmpty = false) {
  303. if (path == null) {
  304. throw new Error('path is required.');
  305. }
  306. if (path === '/') {
  307. return null;
  308. }
  309. const ancestorsPaths = extractToAncestorsPaths(path);
  310. // pick the longest one
  311. const baseQuery = this.findOne({ path: { $in: ancestorsPaths } }).sort({ path: -1 });
  312. const relatedUserGroups = (user != null && userGroups == null) ? [
  313. ...(await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user)),
  314. ...(await ExternalUserGroupRelation.findAllUserGroupIdsRelatedToUser(user)),
  315. ] : userGroups;
  316. const queryBuilder = new this.PageQueryBuilder(baseQuery, includeEmpty);
  317. queryBuilder.addConditionToFilteringByViewer(user, relatedUserGroups);
  318. return queryBuilder.query.exec();
  319. };
  320. /**
  321. * find pages that is match with `path` and its descendants
  322. */
  323. pageSchema.statics.findListWithDescendants = async function(path, user, option = {}, includeEmpty = false) {
  324. const builder = new this.PageQueryBuilder(this.find(), includeEmpty);
  325. builder.addConditionToListWithDescendants(path, option);
  326. return findListFromBuilderAndViewer(builder, user, false, option);
  327. };
  328. /**
  329. * find pages that is match with `path` and its descendants which user is able to manage
  330. */
  331. pageSchema.statics.findManageableListWithDescendants = async function(page, user, option = {}, includeEmpty = false) {
  332. if (user == null) {
  333. return null;
  334. }
  335. const builder = new this.PageQueryBuilder(this.find(), includeEmpty);
  336. builder.addConditionToListWithDescendants(page.path, option);
  337. // add grant conditions
  338. await addConditionToFilteringByViewerToEdit(builder, user);
  339. const { pages } = await findListFromBuilderAndViewer(builder, user, false, option);
  340. // add page if 'grant' is GRANT_RESTRICTED
  341. // because addConditionToListWithDescendants excludes GRANT_RESTRICTED pages
  342. if (page.grant === GRANT_RESTRICTED) {
  343. pages.push(page);
  344. }
  345. return pages;
  346. };
  347. /**
  348. * find pages that start with `path`
  349. */
  350. pageSchema.statics.findListByStartWith = async function(path, user, option, includeEmpty = false) {
  351. const builder = new this.PageQueryBuilder(this.find(), includeEmpty);
  352. builder.addConditionToListByStartWith(path, option);
  353. return findListFromBuilderAndViewer(builder, user, false, option);
  354. };
  355. /**
  356. * find pages that is created by targetUser
  357. *
  358. * @param {User} targetUser
  359. * @param {User} currentUser
  360. * @param {any} option
  361. */
  362. pageSchema.statics.findListByCreator = async function(targetUser, currentUser, option) {
  363. const opt = Object.assign({ sort: 'createdAt', desc: -1 }, option);
  364. const builder = new this.PageQueryBuilder(this.find({ creator: targetUser._id }));
  365. let showAnyoneKnowsLink = null;
  366. if (targetUser != null && currentUser != null) {
  367. showAnyoneKnowsLink = targetUser._id.equals(currentUser._id);
  368. }
  369. return await findListFromBuilderAndViewer(builder, currentUser, showAnyoneKnowsLink, opt);
  370. };
  371. /**
  372. * find pages by PageQueryBuilder
  373. * @param {PageQueryBuilder} builder
  374. * @param {User} user
  375. * @param {boolean} showAnyoneKnowsLink
  376. * @param {any} option
  377. */
  378. async function findListFromBuilderAndViewer(builder, user, showAnyoneKnowsLink, option) {
  379. validateCrowi();
  380. const User = crowi.model('User');
  381. const opt = Object.assign({ sort: 'updatedAt', desc: -1 }, option);
  382. const sortOpt = {};
  383. sortOpt[opt.sort] = opt.desc;
  384. // exclude trashed pages
  385. if (!opt.includeTrashed) {
  386. builder.addConditionToExcludeTrashed();
  387. }
  388. // add grant conditions
  389. await addConditionToFilteringByViewerForList(builder, user, showAnyoneKnowsLink);
  390. // count
  391. const totalCount = await builder.query.exec('count');
  392. // find
  393. builder.addConditionToPagenate(opt.offset, opt.limit, sortOpt);
  394. builder.populateDataToList(User.USER_FIELDS_EXCEPT_CONFIDENTIAL);
  395. const pages = await builder.query.lean().clone().exec('find');
  396. const result = {
  397. pages, totalCount, offset: opt.offset, limit: opt.limit,
  398. };
  399. return result;
  400. }
  401. /**
  402. * Add condition that filter pages by viewer
  403. * by considering Config
  404. *
  405. * @param {PageQueryBuilder} builder
  406. * @param {User} user
  407. * @param {boolean} showAnyoneKnowsLink
  408. */
  409. async function addConditionToFilteringByViewerForList(builder, user, showAnyoneKnowsLink) {
  410. validateCrowi();
  411. // determine User condition
  412. const hidePagesRestrictedByOwner = crowi.configManager.getConfig('crowi', 'security:list-policy:hideRestrictedByOwner');
  413. const hidePagesRestrictedByGroup = crowi.configManager.getConfig('crowi', 'security:list-policy:hideRestrictedByGroup');
  414. // determine UserGroup condition
  415. const userGroups = user != null ? [
  416. ...(await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user)),
  417. ...(await ExternalUserGroupRelation.findAllUserGroupIdsRelatedToUser(user)),
  418. ] : null;
  419. return builder.addConditionToFilteringByViewer(user, userGroups, showAnyoneKnowsLink, !hidePagesRestrictedByOwner, !hidePagesRestrictedByGroup);
  420. }
  421. /**
  422. * Add condition that filter pages by viewer
  423. * by considering Config
  424. *
  425. * @param {PageQueryBuilder} builder
  426. * @param {User} user
  427. * @param {boolean} showAnyoneKnowsLink
  428. */
  429. async function addConditionToFilteringByViewerToEdit(builder, user) {
  430. // determine UserGroup condition
  431. const userGroups = user != null ? [
  432. ...(await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user)),
  433. ...(await ExternalUserGroupRelation.findAllUserGroupIdsRelatedToUser(user)),
  434. ] : null;
  435. return builder.addConditionToFilteringByViewer(user, userGroups, false, false, false);
  436. }
  437. /**
  438. * export addConditionToFilteringByViewerForList as static method
  439. */
  440. pageSchema.statics.addConditionToFilteringByViewerForList = addConditionToFilteringByViewerForList;
  441. /**
  442. * export addConditionToFilteringByViewerToEdit as static method
  443. */
  444. pageSchema.statics.addConditionToFilteringByViewerToEdit = addConditionToFilteringByViewerToEdit;
  445. /**
  446. * Throw error for growi-lsx-plugin (v1.x)
  447. */
  448. pageSchema.statics.generateQueryToListByStartWith = function(path, user, option) {
  449. const dummyQuery = this.find();
  450. dummyQuery.exec = async() => {
  451. throw new Error('Plugin version mismatch. Upgrade growi-lsx-plugin to v2.0.0 or above.');
  452. };
  453. return dummyQuery;
  454. };
  455. pageSchema.statics.generateQueryToListWithDescendants = pageSchema.statics.generateQueryToListByStartWith;
  456. /**
  457. * find all templates applicable to the new page
  458. */
  459. pageSchema.statics.findTemplate = async function(path) {
  460. const templatePath = nodePath.posix.dirname(path);
  461. const pathList = generatePathsOnTree(path, []);
  462. const regexpList = pathList.map((path) => {
  463. const pathWithTrailingSlash = pathUtils.addTrailingSlash(path);
  464. return new RegExp(`^${escapeStringRegexp(pathWithTrailingSlash)}_{1,2}template$`);
  465. });
  466. const templatePages = await this.find({ path: { $in: regexpList } })
  467. .populate({ path: 'revision', model: 'Revision' })
  468. .exec();
  469. return fetchTemplate(templatePages, templatePath);
  470. };
  471. const generatePathsOnTree = (path, pathList) => {
  472. pathList.push(path);
  473. if (path === '/') {
  474. return pathList;
  475. }
  476. const newPath = nodePath.posix.dirname(path);
  477. return generatePathsOnTree(newPath, pathList);
  478. };
  479. const assignTemplateByType = (templates, path, type) => {
  480. const targetTemplatePath = urljoin(path, `${type}template`);
  481. return templates.find((template) => {
  482. return (template.path === targetTemplatePath);
  483. });
  484. };
  485. const assignDecendantsTemplate = (decendantsTemplates, path) => {
  486. const decendantsTemplate = assignTemplateByType(decendantsTemplates, path, '__');
  487. if (decendantsTemplate) {
  488. return decendantsTemplate;
  489. }
  490. if (path === '/') {
  491. return;
  492. }
  493. const newPath = nodePath.posix.dirname(path);
  494. return assignDecendantsTemplate(decendantsTemplates, newPath);
  495. };
  496. const fetchTemplate = async(templates, templatePath) => {
  497. let templateBody;
  498. let templateTags;
  499. /**
  500. * get children template
  501. * __tempate: applicable only to immediate decendants
  502. */
  503. const childrenTemplate = assignTemplateByType(templates, templatePath, '_');
  504. /**
  505. * get decendants templates
  506. * _tempate: applicable to all pages under
  507. */
  508. const decendantsTemplate = assignDecendantsTemplate(templates, templatePath);
  509. if (childrenTemplate) {
  510. templateBody = childrenTemplate.revision.body;
  511. templateTags = await childrenTemplate.findRelatedTagsById();
  512. }
  513. else if (decendantsTemplate) {
  514. templateBody = decendantsTemplate.revision.body;
  515. templateTags = await decendantsTemplate.findRelatedTagsById();
  516. }
  517. return { templateBody, templateTags };
  518. };
  519. pageSchema.statics.findListByPathsArray = async function(paths, includeEmpty = false) {
  520. const queryBuilder = new this.PageQueryBuilder(this.find(), includeEmpty);
  521. queryBuilder.addConditionToListByPathsArray(paths);
  522. return await queryBuilder.query.exec();
  523. };
  524. /**
  525. * transfer pages grant to specified user group
  526. * @param {Page[]} pages
  527. * @param {IGrantedGroup} transferToUserGroup
  528. */
  529. pageSchema.statics.transferPagesToGroup = async function(pages, transferToUserGroup) {
  530. const userGroupModel = transferToUserGroup.type === GroupType.userGroup ? UserGroup : ExternalUserGroup;
  531. if ((await userGroupModel.count({ _id: transferToUserGroup.item })) === 0) {
  532. throw Error('Cannot find the group to which private pages belong to. _id: ', transferToUserGroup.item);
  533. }
  534. await this.updateMany({ _id: { $in: pages.map(p => p._id) } }, { grantedGroups: [transferToUserGroup] });
  535. };
  536. pageSchema.methods.getNotificationTargetUsers = async function() {
  537. const Revision = mongoose.model('Revision');
  538. const [commentCreators, revisionAuthors] = await Promise.all([Comment.findCreatorsByPage(this), Revision.findAuthorsByPage(this)]);
  539. const targetUsers = new Set([this.creator].concat(commentCreators, revisionAuthors));
  540. return Array.from(targetUsers);
  541. };
  542. pageSchema.statics.getHistories = function() {
  543. // TODO
  544. };
  545. pageSchema.statics.STATUS_PUBLISHED = STATUS_PUBLISHED;
  546. pageSchema.statics.STATUS_DELETED = STATUS_DELETED;
  547. pageSchema.statics.GRANT_PUBLIC = GRANT_PUBLIC;
  548. pageSchema.statics.GRANT_RESTRICTED = GRANT_RESTRICTED;
  549. pageSchema.statics.GRANT_SPECIFIED = GRANT_SPECIFIED;
  550. pageSchema.statics.GRANT_OWNER = GRANT_OWNER;
  551. pageSchema.statics.GRANT_USER_GROUP = GRANT_USER_GROUP;
  552. pageSchema.statics.PAGE_GRANT_ERROR = PAGE_GRANT_ERROR;
  553. return pageSchema;
  554. };