page.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. module.exports = function(crowi) {
  2. var debug = require('debug')('crowi:models:page')
  3. , mongoose = require('mongoose')
  4. , ObjectId = mongoose.Schema.Types.ObjectId
  5. , GRANT_PUBLIC = 1
  6. , GRANT_RESTRICTED = 2
  7. , GRANT_SPECIFIED = 3
  8. , GRANT_OWNER = 4
  9. , PAGE_GRANT_ERROR = 1
  10. , pageEvent = crowi.event('page')
  11. , pageSchema;
  12. function isPortalPath(path) {
  13. if (path.match(/.*\/$/)) {
  14. return true;
  15. }
  16. return false;
  17. }
  18. pageSchema = new mongoose.Schema({
  19. path: { type: String, required: true, index: true },
  20. revision: { type: ObjectId, ref: 'Revision' },
  21. redirectTo: { type: String, index: true },
  22. grant: { type: Number, default: GRANT_PUBLIC, index: true },
  23. grantedUsers: [{ type: ObjectId, ref: 'User' }],
  24. creator: { type: ObjectId, ref: 'User', index: true },
  25. liker: [{ type: ObjectId, ref: 'User', index: true }],
  26. seenUsers: [{ type: ObjectId, ref: 'User', index: true }],
  27. commentCount: { type: Number, default: 0 },
  28. extended: {
  29. type: String,
  30. default: '{}',
  31. get: function(data) {
  32. try {
  33. return JSON.parse(data);
  34. } catch(e) {
  35. return data;
  36. }
  37. },
  38. set: function(data) {
  39. return JSON.stringify(data);
  40. }
  41. },
  42. createdAt: { type: Date, default: Date.now },
  43. updatedAt: Date
  44. }, {
  45. toJSON: {getters: true},
  46. toObject: {getters: true}
  47. });
  48. pageEvent.on('create', pageEvent.onCreate);
  49. pageEvent.on('update', pageEvent.onUpdate);
  50. pageSchema.methods.isPublic = function() {
  51. if (!this.grant || this.grant == GRANT_PUBLIC) {
  52. return true;
  53. }
  54. return false;
  55. };
  56. pageSchema.methods.isPortal = function() {
  57. return isPortalPath(this.path);
  58. };
  59. pageSchema.methods.isCreator = function(userData) {
  60. if (this.populated('creator') && this.creator._id.toString() === userData._id.toString()) {
  61. return true;
  62. } else if (this.creator.toString() === userData._id.toString()) {
  63. return true
  64. }
  65. return false;
  66. };
  67. pageSchema.methods.isGrantedFor = function(userData) {
  68. if (this.isPublic() || this.isCreator(userData)) {
  69. return true;
  70. }
  71. if (this.grantedUsers.indexOf(userData._id) >= 0) {
  72. return true;
  73. }
  74. return false;
  75. };
  76. pageSchema.methods.isLatestRevision = function() {
  77. // populate されていなくて判断できない
  78. if (!this.latestRevision || !this.revision) {
  79. return true;
  80. }
  81. return (this.latestRevision == this.revision._id.toString());
  82. };
  83. pageSchema.methods.isUpdatable = function(previousRevision) {
  84. var revision = this.latestRevision || this.revision;
  85. if (revision != previousRevision) {
  86. return false;
  87. }
  88. return true;
  89. };
  90. pageSchema.methods.isLiked = function(userData) {
  91. return this.liker.some(function(likedUser) {
  92. return likedUser == userData._id.toString();
  93. });
  94. };
  95. pageSchema.methods.like = function(userData) {
  96. var self = this,
  97. Page = self;
  98. return new Promise(function(resolve, reject) {
  99. var added = self.liker.addToSet(userData._id);
  100. if (added.length > 0) {
  101. self.save(function(err, data) {
  102. if (err) {
  103. return reject(err);
  104. }
  105. debug('liker updated!', added);
  106. return resolve(data);
  107. });
  108. } else {
  109. debug('liker not updated');
  110. return reject(self);
  111. }
  112. });
  113. };
  114. pageSchema.methods.unlike = function(userData, callback) {
  115. var self = this,
  116. Page = self;
  117. return new Promise(function(resolve, reject) {
  118. var beforeCount = self.liker.length;
  119. self.liker.pull(userData._id);
  120. if (self.liker.length != beforeCount) {
  121. self.save(function(err, data) {
  122. if (err) {
  123. return reject(err);
  124. }
  125. return resolve(data);
  126. });
  127. } else {
  128. debug('liker not updated');
  129. return reject(self);
  130. }
  131. });
  132. };
  133. pageSchema.methods.isSeenUser = function(userData) {
  134. var self = this,
  135. Page = self;
  136. return this.seenUsers.some(function(seenUser) {
  137. return seenUser.equals(userData._id);
  138. });
  139. };
  140. pageSchema.methods.seen = function(userData) {
  141. var self = this,
  142. Page = self;
  143. if (this.isSeenUser(userData)) {
  144. debug('seenUsers not updated');
  145. return Promise.resolve(this);
  146. }
  147. return new Promise(function(resolve, reject) {
  148. if (!userData || !userData._id) {
  149. reject(new Error('User data is not valid'));
  150. }
  151. var added = self.seenUsers.addToSet(userData);
  152. self.save(function(err, data) {
  153. if (err) {
  154. return reject(err);
  155. }
  156. debug('seenUsers updated!', added);
  157. return resolve(self);
  158. });
  159. });
  160. };
  161. pageSchema.methods.getSlackChannel = function() {
  162. var extended = this.get('extended');
  163. if (!extended) {
  164. return '';
  165. }
  166. return extended.slack || '';
  167. };
  168. pageSchema.methods.updateSlackChannel = function(slackChannel) {
  169. var extended = this.extended;
  170. extended.slack = slackChannel;
  171. return this.updateExtended(extended);
  172. };
  173. pageSchema.methods.updateExtended = function(extended) {
  174. var page = this;
  175. page.extended = extended;
  176. return new Promise(function(resolve, reject) {
  177. return page.save(function(err, doc) {
  178. if (err) {
  179. return reject(err);
  180. }
  181. return resolve(doc);
  182. });
  183. });
  184. };
  185. pageSchema.statics.populatePageData = function(pageData, revisionId) {
  186. var Page = crowi.model('Page');
  187. var User = crowi.model('User');
  188. pageData.latestRevision = pageData.revision;
  189. if (revisionId) {
  190. pageData.revision = revisionId;
  191. }
  192. pageData.likerCount = pageData.liker.length || 0;
  193. pageData.seenUsersCount = pageData.seenUsers.length || 0;
  194. return new Promise(function(resolve, reject) {
  195. pageData.populate([
  196. {path: 'creator', model: 'User', select: User.USER_PUBLIC_FIELDS},
  197. {path: 'revision', model: 'Revision'},
  198. //{path: 'liker', options: { limit: 11 }},
  199. //{path: 'seenUsers', options: { limit: 11 }},
  200. ], function (err, pageData) {
  201. Page.populate(pageData, {path: 'revision.author', model: 'User', select: User.USER_PUBLIC_FIELDS}, function(err, data) {
  202. if (err) {
  203. return reject(err);
  204. }
  205. return resolve(data);
  206. });
  207. });
  208. });
  209. };
  210. pageSchema.statics.populatePageListToAnyObjects = function(pageIdObjectArray) {
  211. var Page = this;
  212. var pageIdMappings = {};
  213. var pageIds = pageIdObjectArray.map(function(page, idx) {
  214. if (!page._id) {
  215. throw new Error('Pass the arg of populatePageListToAnyObjects() must have _id on each element.');
  216. }
  217. pageIdMappings[String(page._id)] = idx;
  218. return page._id;
  219. });
  220. return new Promise(function(resolve, reject) {
  221. Page.findListByPageIds(pageIds, {limit: 100}) // limit => if the pagIds is greater than 100, ignore
  222. .then(function(pages) {
  223. pages.forEach(function(page) {
  224. Object.assign(pageIdObjectArray[pageIdMappings[String(page._id)]], page._doc);
  225. });
  226. resolve(pageIdObjectArray);
  227. });
  228. });
  229. };
  230. pageSchema.statics.updateCommentCount = function (page, num)
  231. {
  232. var self = this;
  233. return new Promise(function(resolve, reject) {
  234. self.update({_id: page}, {commentCount: num}, {}, function(err, data) {
  235. if (err) {
  236. debug('Update commentCount Error', err);
  237. return reject(err);
  238. }
  239. return resolve(data);
  240. });
  241. });
  242. };
  243. pageSchema.statics.hasPortalPage = function (path, user) {
  244. var self = this;
  245. return new Promise(function(resolve, reject) {
  246. self.findPage(path, user)
  247. .then(function(page) {
  248. resolve(page);
  249. }).catch(function(err) {
  250. resolve(null); // check only has portal page, through error
  251. });
  252. });
  253. };
  254. pageSchema.statics.getGrantLabels = function() {
  255. var grantLabels = {};
  256. grantLabels[GRANT_PUBLIC] = '公開';
  257. grantLabels[GRANT_RESTRICTED] = 'リンクを知っている人のみ';
  258. //grantLabels[GRANT_SPECIFIED] = '特定ユーザーのみ';
  259. grantLabels[GRANT_OWNER] = '自分のみ';
  260. return grantLabels;
  261. };
  262. pageSchema.statics.normalizePath = function(path) {
  263. if (!path.match(/^\//)) {
  264. path = '/' + path;
  265. }
  266. return path;
  267. };
  268. pageSchema.statics.getUserPagePath = function(user) {
  269. return '/user/' + user.username;
  270. };
  271. pageSchema.statics.isCreatableName = function(name) {
  272. var forbiddenPages = [
  273. /\^|\$|\*|\+|\#/,
  274. /^\/_api\/.*/,
  275. /^\/\-\/.*/,
  276. /^\/_r\/.*/,
  277. /^\/user\/[^\/]+\/(bookmarks|comments|activities|pages|recent-create|recent-edit)/, // reserved
  278. /^http:\/\/.+$/, // avoid miss in renaming
  279. /.+\/edit$/,
  280. /.+\.md$/,
  281. /^\/(installer|register|login|logout|admin|me|files|trash|paste|comments).+/,
  282. ];
  283. var isCreatable = true;
  284. forbiddenPages.forEach(function(page) {
  285. var pageNameReg = new RegExp(page);
  286. if (name.match(pageNameReg)) {
  287. isCreatable = false;
  288. return ;
  289. }
  290. });
  291. return isCreatable;
  292. };
  293. pageSchema.statics.updateRevision = function(pageId, revisionId, cb) {
  294. this.update({_id: pageId}, {revision: revisionId}, {}, function(err, data) {
  295. cb(err, data);
  296. });
  297. };
  298. pageSchema.statics.findUpdatedList = function(offset, limit, cb) {
  299. this
  300. .find({})
  301. .sort({updatedAt: -1})
  302. .skip(offset)
  303. .limit(limit)
  304. .exec(function(err, data) {
  305. cb(err, data);
  306. });
  307. };
  308. pageSchema.statics.findPageById = function(id) {
  309. var Page = this;
  310. return new Promise(function(resolve, reject) {
  311. Page.findOne({_id: id}, function(err, pageData) {
  312. if (err) {
  313. return reject(err);
  314. }
  315. if (pageData == null) {
  316. return reject(new Error('Page not found'));
  317. }
  318. return Page.populatePageData(pageData, null).then(resolve);
  319. });
  320. });
  321. };
  322. pageSchema.statics.findPageByIdAndGrantedUser = function(id, userData) {
  323. var Page = this;
  324. return new Promise(function(resolve, reject) {
  325. Page.findPageById(id)
  326. .then(function(pageData) {
  327. if (userData && !pageData.isGrantedFor(userData)) {
  328. return reject(new Error('Page is not granted for the user')); //PAGE_GRANT_ERROR, null);
  329. }
  330. return resolve(pageData);
  331. }).catch(function(err) {
  332. return reject(err);
  333. });
  334. });
  335. };
  336. // find page and check if granted user
  337. pageSchema.statics.findPage = function(path, userData, revisionId, ignoreNotFound) {
  338. var self = this;
  339. return new Promise(function(resolve, reject) {
  340. self.findOne({path: path}, function(err, pageData) {
  341. if (err) {
  342. return reject(err);
  343. }
  344. if (pageData === null) {
  345. if (ignoreNotFound) {
  346. return resolve(null);
  347. }
  348. var pageNotFoundError = new Error('Page Not Found')
  349. pageNotFoundError.name = 'Crowi:Page:NotFound';
  350. return reject(pageNotFoundError);
  351. }
  352. if (!pageData.isGrantedFor(userData)) {
  353. return reject(new Error('Page is not granted for the user')); //PAGE_GRANT_ERROR, null);
  354. }
  355. self.populatePageData(pageData, revisionId || null).then(resolve).catch(reject);
  356. });
  357. });
  358. };
  359. // find page by path
  360. pageSchema.statics.findPageByPath = function(path) {
  361. var Page = this;
  362. return new Promise(function(resolve, reject) {
  363. Page.findOne({path: path}, function(err, pageData) {
  364. if (err || pageData === null) {
  365. return reject(err);
  366. }
  367. return resolve(pageData);
  368. });
  369. });
  370. };
  371. pageSchema.statics.findListByPageIds = function(ids, options) {
  372. var Page = this;
  373. var User = crowi.model('User');
  374. var options = options || {}
  375. , limit = options.limit || 50
  376. , offset = options.skip || 0
  377. ;
  378. return new Promise(function(resolve, reject) {
  379. Page
  380. .find({ _id: { $in: ids }, grant: GRANT_PUBLIC })
  381. //.sort({createdAt: -1}) // TODO optionize
  382. .skip(offset)
  383. .limit(limit)
  384. .populate([
  385. {path: 'creator', model: 'User', select: User.USER_PUBLIC_FIELDS},
  386. {path: 'revision', model: 'Revision'},
  387. ])
  388. .exec(function(err, pages) {
  389. if (err) {
  390. return reject(err);
  391. }
  392. Page.populate(pages, {path: 'revision.author', model: 'User', select: User.USER_PUBLIC_FIELDS}, function(err, data) {
  393. if (err) {
  394. return reject(err);
  395. }
  396. return resolve(data);
  397. });
  398. });
  399. });
  400. };
  401. /**
  402. * とりあえず、公開ページであり、redirectTo が無いものだけを出すためだけのAPI
  403. */
  404. pageSchema.statics.findListByCreator = function(user, option) {
  405. var Page = this;
  406. var User = crowi.model('User');
  407. var limit = option.limit || 50;
  408. var offset = option.offset || 0;
  409. return new Promise(function(resolve, reject) {
  410. Page
  411. .find({ creator: user._id, grant: GRANT_PUBLIC, redirectTo: null })
  412. .sort({createdAt: -1})
  413. .skip(offset)
  414. .limit(limit)
  415. .populate('revision')
  416. .exec()
  417. .then(function(pages) {
  418. return Page.populate(pages, {path: 'revision.author', model: 'User', select: User.USER_PUBLIC_FIELDS}).then(resolve);
  419. });
  420. });
  421. };
  422. /**
  423. * Bulk get (for internal only)
  424. */
  425. pageSchema.statics.getStreamOfFindAll = function(options) {
  426. var Page = this
  427. , options = options || {}
  428. , publicOnly = options.publicOnly || true
  429. , criteria = {redirectTo: null,}
  430. ;
  431. if (publicOnly) {
  432. criteria.grant = GRANT_PUBLIC;
  433. }
  434. return this.find(criteria)
  435. .populate([
  436. {path: 'creator', model: 'User'},
  437. {path: 'revision', model: 'Revision'},
  438. ])
  439. .sort({updatedAt: -1})
  440. .stream();
  441. };
  442. /**
  443. * findListByStartWith
  444. *
  445. * If `path` has `/` at the end, returns '{path}/*' and '{path}' self.
  446. * If `path` doesn't have `/` at the end, returns '{path}*'
  447. * e.g.
  448. */
  449. pageSchema.statics.findListByStartWith = function(path, userData, option) {
  450. var Page = this;
  451. var User = crowi.model('User');
  452. var pathCondition = [];
  453. if (!option) {
  454. option = {sort: 'updatedAt', desc: -1, offset: 0, limit: 50};
  455. }
  456. var opt = {
  457. sort: option.sort || 'updatedAt',
  458. desc: option.desc || -1,
  459. offset: option.offset || 0,
  460. limit: option.limit || 50
  461. };
  462. var sortOpt = {};
  463. sortOpt[opt.sort] = opt.desc;
  464. var queryReg = new RegExp('^' + path);
  465. var sliceOption = option.revisionSlice || {$slice: 1};
  466. pathCondition.push({path: queryReg});
  467. if (path.match(/\/$/)) {
  468. debug('Page list by ending with /, so find also upper level page');
  469. pathCondition.push({path: path.substr(0, path.length -1)});
  470. }
  471. return new Promise(function(resolve, reject) {
  472. // FIXME: might be heavy
  473. var q = Page.find({
  474. redirectTo: null,
  475. $or: [
  476. {grant: null},
  477. {grant: GRANT_PUBLIC},
  478. {grant: GRANT_RESTRICTED, grantedUsers: userData._id},
  479. {grant: GRANT_SPECIFIED, grantedUsers: userData._id},
  480. {grant: GRANT_OWNER, grantedUsers: userData._id},
  481. ],})
  482. .populate('revision')
  483. .and({
  484. $or: pathCondition
  485. })
  486. .sort(sortOpt)
  487. .skip(opt.offset)
  488. .limit(opt.limit);
  489. q.exec()
  490. .then(function(pages) {
  491. Page.populate(pages, {path: 'revision.author', model: 'User', select: User.USER_PUBLIC_FIELDS})
  492. .then(resolve)
  493. .catch(reject);
  494. })
  495. });
  496. };
  497. pageSchema.statics.updatePage = function(page, updateData) {
  498. var Page = this;
  499. return new Promise(function(resolve, reject) {
  500. // TODO foreach して save
  501. Page.update({_id: page._id}, {$set: updateData}, function(err, data) {
  502. if (err) {
  503. return reject(err);
  504. }
  505. return resolve(data);
  506. });
  507. });
  508. };
  509. pageSchema.statics.updateGrant = function(page, grant, userData) {
  510. var self = this;
  511. return new Promise(function(resolve, reject) {
  512. self.update({_id: page._id}, {$set: {grant: grant}}, function(err, data) {
  513. if (err) {
  514. return reject(err);
  515. }
  516. if (grant == GRANT_PUBLIC) {
  517. page.grantedUsers = [];
  518. } else {
  519. page.grantedUsers = [];
  520. page.grantedUsers.push(userData._id);
  521. }
  522. page.save(function(err, data) {
  523. if (err) {
  524. return reject(err);
  525. }
  526. return resolve(data);
  527. });
  528. });
  529. });
  530. };
  531. // Instance method でいいのでは
  532. pageSchema.statics.pushToGrantedUsers = function(page, userData) {
  533. return new Promise(function(resolve, reject) {
  534. if (!page.grantedUsers || !Array.isArray(page.grantedUsers)) {
  535. page.grantedUsers = [];
  536. }
  537. page.grantedUsers.push(userData);
  538. page.save(function(err, data) {
  539. if (err) {
  540. return reject(err);
  541. }
  542. return resolve(data);
  543. });
  544. });
  545. };
  546. pageSchema.statics.pushRevision = function(pageData, newRevision, user) {
  547. var isCreate = false;
  548. if (pageData.revision === undefined) {
  549. debug('pushRevision on Create');
  550. isCreate = true;
  551. }
  552. return new Promise(function(resolve, reject) {
  553. newRevision.save(function(err, newRevision) {
  554. if (err) {
  555. debug('Error on saving revision', err);
  556. return reject(err);
  557. }
  558. debug('Successfully saved new revision', newRevision);
  559. pageData.revision = newRevision;
  560. pageData.updatedAt = Date.now();
  561. pageData.save(function(err, data) {
  562. if (err) {
  563. // todo: remove new revision?
  564. debug('Error on save page data (after push revision)', err);
  565. return reject(err);
  566. }
  567. resolve(data);
  568. if (!isCreate) {
  569. debug('pushRevision on Update');
  570. pageEvent.emit('update', data, user);
  571. }
  572. });
  573. });
  574. });
  575. };
  576. pageSchema.statics.create = function(path, body, user, options) {
  577. var Page = this
  578. , Revision = crowi.model('Revision')
  579. , format = options.format || 'markdown'
  580. , grant = options.grant || GRANT_PUBLIC
  581. , redirectTo = options.redirectTo || null;
  582. // force public
  583. if (isPortalPath(path)) {
  584. grant = GRANT_PUBLIC;
  585. }
  586. return new Promise(function(resolve, reject) {
  587. Page.findOne({path: path}, function(err, pageData) {
  588. if (pageData) {
  589. return reject(new Error('Cannot create new page to existed path'));
  590. }
  591. var newPage = new Page();
  592. newPage.path = path;
  593. newPage.creator = user;
  594. newPage.createdAt = Date.now();
  595. newPage.updatedAt = Date.now();
  596. newPage.redirectTo = redirectTo;
  597. newPage.grant = grant;
  598. newPage.grantedUsers = [];
  599. newPage.grantedUsers.push(user);
  600. newPage.save(function (err, newPage) {
  601. if (err) {
  602. return reject(err);
  603. }
  604. var newRevision = Revision.prepareRevision(newPage, body, user, {format: format});
  605. Page.pushRevision(newPage, newRevision, user).then(function(data) {
  606. resolve(data);
  607. pageEvent.emit('create', data, user);
  608. }).catch(function(err) {
  609. debug('Push Revision Error on create page', err);
  610. return reject(err);
  611. });
  612. });
  613. });
  614. });
  615. };
  616. pageSchema.statics.rename = function(pageData, newPagePath, user, options) {
  617. var Page = this
  618. , Revision = crowi.model('Revision')
  619. , path = pageData.path
  620. , createRedirectPage = options.createRedirectPage || 0
  621. , moveUnderTrees = options.moveUnderTrees || 0;
  622. return new Promise(function(resolve, reject) {
  623. // pageData の path を変更
  624. Page.updatePage(pageData, {updatedAt: Date.now(), path: newPagePath})
  625. .then(function(data) {
  626. debug('Before ', pageData);
  627. // reivisions の path を変更
  628. return Revision.updateRevisionListByPath(path, {path: newPagePath}, {})
  629. }).then(function(data) {
  630. debug('After ', pageData);
  631. pageData.path = newPagePath;
  632. if (createRedirectPage) {
  633. var body = 'redirect ' + newPagePath;
  634. return Page.create(path, body, user, {redirectTo: newPagePath}).then(resolve).catch(reject);
  635. } else {
  636. return resolve(data);
  637. }
  638. });
  639. });
  640. };
  641. pageSchema.statics.getHistories = function() {
  642. // TODO
  643. return;
  644. };
  645. pageSchema.statics.GRANT_PUBLIC = GRANT_PUBLIC;
  646. pageSchema.statics.GRANT_RESTRICTED = GRANT_RESTRICTED;
  647. pageSchema.statics.GRANT_SPECIFIED = GRANT_SPECIFIED;
  648. pageSchema.statics.GRANT_OWNER = GRANT_OWNER;
  649. pageSchema.statics.PAGE_GRANT_ERROR = PAGE_GRANT_ERROR;
  650. return mongoose.model('Page', pageSchema);
  651. };