user.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. /* eslint-disable no-use-before-define */
  2. import { allLocales } from '~/next-i18next.config';
  3. import { generateGravatarSrc } from '~/utils/gravatar';
  4. import loggerFactory from '~/utils/logger';
  5. const crypto = require('crypto');
  6. const debug = require('debug')('growi:models:user');
  7. const mongoose = require('mongoose');
  8. const mongoosePaginate = require('mongoose-paginate-v2');
  9. const uniqueValidator = require('mongoose-unique-validator');
  10. const ObjectId = mongoose.Schema.Types.ObjectId;
  11. const { omitInsecureAttributes } = require('./serializers/user-serializer');
  12. const logger = loggerFactory('growi:models:user');
  13. module.exports = function(crowi) {
  14. const STATUS_REGISTERED = 1;
  15. const STATUS_ACTIVE = 2;
  16. const STATUS_SUSPENDED = 3;
  17. const STATUS_DELETED = 4;
  18. const STATUS_INVITED = 5;
  19. const USER_FIELDS_EXCEPT_CONFIDENTIAL = '_id image isEmailPublished isGravatarEnabled googleId name username email introduction'
  20. + ' status lang createdAt lastLoginAt admin imageUrlCached';
  21. const PAGE_ITEMS = 50;
  22. let userEvent;
  23. // init event
  24. if (crowi != null) {
  25. userEvent = crowi.event('user');
  26. userEvent.on('activated', userEvent.onActivated);
  27. }
  28. const userSchema = new mongoose.Schema({
  29. userId: String,
  30. image: String,
  31. imageAttachment: { type: ObjectId, ref: 'Attachment' },
  32. imageUrlCached: String,
  33. isGravatarEnabled: { type: Boolean, default: false },
  34. isEmailPublished: { type: Boolean, default: true },
  35. googleId: String,
  36. name: { type: String },
  37. username: { type: String, required: true, unique: true },
  38. email: { type: String, unique: true, sparse: true },
  39. slackMemberId: { type: String, unique: true, sparse: true },
  40. // === Crowi settings
  41. // username: { type: String, index: true },
  42. // email: { type: String, required: true, index: true },
  43. // === crowi-plus (>= 2.1.0, <2.3.0) settings
  44. // email: { type: String, required: true, unique: true },
  45. introduction: String,
  46. password: String,
  47. apiToken: { type: String, index: true },
  48. lang: {
  49. type: String,
  50. enum: allLocales,
  51. default: 'en_US',
  52. },
  53. status: {
  54. type: Number, required: true, default: STATUS_ACTIVE, index: true,
  55. },
  56. lastLoginAt: { type: Date },
  57. admin: { type: Boolean, default: 0, index: true },
  58. isInvitationEmailSended: { type: Boolean, default: false },
  59. }, {
  60. timestamps: true,
  61. toObject: {
  62. transform: (doc, ret, opt) => {
  63. return omitInsecureAttributes(ret);
  64. },
  65. },
  66. });
  67. userSchema.plugin(mongoosePaginate);
  68. userSchema.plugin(uniqueValidator);
  69. function validateCrowi() {
  70. if (crowi == null) {
  71. throw new Error('"crowi" is null. Init User model with "crowi" argument first.');
  72. }
  73. }
  74. function decideUserStatusOnRegistration() {
  75. validateCrowi();
  76. const { configManager, aclService } = crowi;
  77. const isInstalled = configManager.getConfig('crowi', 'app:installed');
  78. if (!isInstalled) {
  79. return STATUS_ACTIVE; // is this ok?
  80. }
  81. // status decided depends on registrationMode
  82. const registrationMode = configManager.getConfig('crowi', 'security:registrationMode');
  83. switch (registrationMode) {
  84. case aclService.labels.SECURITY_REGISTRATION_MODE_OPEN:
  85. return STATUS_ACTIVE;
  86. case aclService.labels.SECURITY_REGISTRATION_MODE_RESTRICTED:
  87. case aclService.labels.SECURITY_REGISTRATION_MODE_CLOSED: // 一応
  88. return STATUS_REGISTERED;
  89. default:
  90. return STATUS_ACTIVE; // どっちにすんのがいいんだろうな
  91. }
  92. }
  93. function generateRandomEmail() {
  94. const randomstr = generateRandomTempPassword();
  95. return `change-it-${randomstr}@example.com`;
  96. }
  97. function generateRandomTempPassword() {
  98. const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!=-_';
  99. let password = '';
  100. const len = 12;
  101. for (let i = 0; i < len; i++) {
  102. const randomPoz = Math.floor(Math.random() * chars.length);
  103. password += chars.substring(randomPoz, randomPoz + 1);
  104. }
  105. return password;
  106. }
  107. function generatePassword(password) {
  108. validateCrowi();
  109. const hasher = crypto.createHash('sha256');
  110. hasher.update(crowi.env.PASSWORD_SEED + password);
  111. return hasher.digest('hex');
  112. }
  113. function generateApiToken(user) {
  114. const hasher = crypto.createHash('sha256');
  115. hasher.update((new Date()).getTime() + user._id);
  116. return hasher.digest('base64');
  117. }
  118. userSchema.methods.isPasswordSet = function() {
  119. if (this.password) {
  120. return true;
  121. }
  122. return false;
  123. };
  124. userSchema.methods.isPasswordValid = function(password) {
  125. return this.password === generatePassword(password);
  126. };
  127. userSchema.methods.setPassword = function(password) {
  128. this.password = generatePassword(password);
  129. return this;
  130. };
  131. userSchema.methods.isEmailSet = function() {
  132. if (this.email) {
  133. return true;
  134. }
  135. return false;
  136. };
  137. userSchema.methods.updateLastLoginAt = function(lastLoginAt, callback) {
  138. this.lastLoginAt = lastLoginAt;
  139. this.save((err, userData) => {
  140. return callback(err, userData);
  141. });
  142. };
  143. userSchema.methods.updateIsGravatarEnabled = async function(isGravatarEnabled) {
  144. this.isGravatarEnabled = isGravatarEnabled;
  145. await this.updateImageUrlCached();
  146. const userData = await this.save();
  147. return userData;
  148. };
  149. userSchema.methods.updatePassword = async function(password) {
  150. this.setPassword(password);
  151. const userData = await this.save();
  152. return userData;
  153. };
  154. userSchema.methods.updateApiToken = async function() {
  155. const self = this;
  156. self.apiToken = generateApiToken(this);
  157. const userData = await self.save();
  158. return userData;
  159. };
  160. // TODO: create UserService and transplant this method because image uploading depends on AttachmentService
  161. userSchema.methods.updateImage = async function(attachment) {
  162. this.imageAttachment = attachment;
  163. await this.updateImageUrlCached();
  164. return this.save();
  165. };
  166. // TODO: create UserService and transplant this method because image deletion depends on AttachmentService
  167. userSchema.methods.deleteImage = async function() {
  168. validateCrowi();
  169. // the 'image' field became DEPRECATED in v3.3.8
  170. this.image = undefined;
  171. if (this.imageAttachment != null) {
  172. const { attachmentService } = crowi;
  173. attachmentService.removeAttachment(this.imageAttachment._id);
  174. }
  175. this.imageAttachment = undefined;
  176. this.updateImageUrlCached();
  177. return this.save();
  178. };
  179. userSchema.methods.updateImageUrlCached = async function() {
  180. this.imageUrlCached = await this.generateImageUrlCached();
  181. };
  182. userSchema.methods.generateImageUrlCached = async function() {
  183. if (this.isGravatarEnabled) {
  184. return generateGravatarSrc(this.email);
  185. }
  186. if (this.image != null) {
  187. return this.image;
  188. }
  189. if (this.imageAttachment != null && this.imageAttachment._id != null) {
  190. const Attachment = crowi.model('Attachment');
  191. const imageAttachment = await Attachment.findById(this.imageAttachment);
  192. return imageAttachment.filePathProxied;
  193. }
  194. return '/images/icons/user.svg';
  195. };
  196. userSchema.methods.updateGoogleId = function(googleId, callback) {
  197. this.googleId = googleId;
  198. this.save((err, userData) => {
  199. return callback(err, userData);
  200. });
  201. };
  202. userSchema.methods.deleteGoogleId = function(callback) {
  203. return this.updateGoogleId(null, callback);
  204. };
  205. userSchema.methods.activateInvitedUser = async function(username, name, password) {
  206. this.setPassword(password);
  207. this.name = name;
  208. this.username = username;
  209. this.status = STATUS_ACTIVE;
  210. this.isEmailPublished = crowi.configManager.getConfig('crowi', 'customize:isEmailPublishedForNewUser');
  211. this.save((err, userData) => {
  212. userEvent.emit('activated', userData);
  213. if (err) {
  214. throw new Error(err);
  215. }
  216. return userData;
  217. });
  218. };
  219. userSchema.methods.removeFromAdmin = async function() {
  220. debug('Remove from admin', this);
  221. this.admin = 0;
  222. return this.save();
  223. };
  224. userSchema.methods.makeAdmin = async function() {
  225. debug('Admin', this);
  226. this.admin = 1;
  227. return this.save();
  228. };
  229. userSchema.methods.asyncMakeAdmin = async function(callback) {
  230. this.admin = 1;
  231. return this.save();
  232. };
  233. userSchema.methods.statusActivate = async function() {
  234. debug('Activate User', this);
  235. this.status = STATUS_ACTIVE;
  236. const userData = await this.save();
  237. return userEvent.emit('activated', userData);
  238. };
  239. userSchema.methods.statusSuspend = async function() {
  240. debug('Suspend User', this);
  241. this.status = STATUS_SUSPENDED;
  242. if (this.email === undefined || this.email === null) { // migrate old data
  243. this.email = '-';
  244. }
  245. if (this.name === undefined || this.name === null) { // migrate old data
  246. this.name = `-${Date.now()}`;
  247. }
  248. if (this.username === undefined || this.usename === null) { // migrate old data
  249. this.username = '-';
  250. }
  251. return this.save();
  252. };
  253. userSchema.methods.statusDelete = async function() {
  254. debug('Delete User', this);
  255. const now = new Date();
  256. const deletedLabel = `deleted_at_${now.getTime()}`;
  257. this.status = STATUS_DELETED;
  258. this.username = deletedLabel;
  259. this.password = '';
  260. this.name = '';
  261. this.email = `${deletedLabel}@deleted`;
  262. this.googleId = null;
  263. this.isGravatarEnabled = false;
  264. this.image = null;
  265. return this.save();
  266. };
  267. userSchema.statics.getUserStatusLabels = function() {
  268. const userStatus = {};
  269. userStatus[STATUS_REGISTERED] = 'Approval Pending';
  270. userStatus[STATUS_ACTIVE] = 'Active';
  271. userStatus[STATUS_SUSPENDED] = 'Suspended';
  272. userStatus[STATUS_DELETED] = 'Deleted';
  273. userStatus[STATUS_INVITED] = 'Invited';
  274. return userStatus;
  275. };
  276. userSchema.statics.isEmailValid = function(email, callback) {
  277. validateCrowi();
  278. const whitelist = crowi.configManager.getConfig('crowi', 'security:registrationWhiteList');
  279. if (Array.isArray(whitelist) && whitelist.length > 0) {
  280. return whitelist.some((allowedEmail) => {
  281. const re = new RegExp(`${allowedEmail}$`);
  282. return re.test(email);
  283. });
  284. }
  285. return true;
  286. };
  287. userSchema.statics.findUsers = function(options, callback) {
  288. const sort = options.sort || { status: 1, createdAt: 1 };
  289. this.find()
  290. .sort(sort)
  291. .skip(options.skip || 0)
  292. .limit(options.limit || 21)
  293. .exec((err, userData) => {
  294. callback(err, userData);
  295. });
  296. };
  297. userSchema.statics.findAllUsers = function(option) {
  298. // eslint-disable-next-line no-param-reassign
  299. option = option || {};
  300. const sort = option.sort || { createdAt: -1 };
  301. const fields = option.fields || {};
  302. let status = option.status || [STATUS_ACTIVE, STATUS_SUSPENDED];
  303. if (!Array.isArray(status)) {
  304. status = [status];
  305. }
  306. return this.find()
  307. .or(status.map((s) => { return { status: s } }))
  308. .select(fields)
  309. .sort(sort);
  310. };
  311. userSchema.statics.findUsersByIds = function(ids, option) {
  312. // eslint-disable-next-line no-param-reassign
  313. option = option || {};
  314. const sort = option.sort || { createdAt: -1 };
  315. const status = option.status || STATUS_ACTIVE;
  316. const fields = option.fields || {};
  317. return this.find({ _id: { $in: ids }, status })
  318. .select(fields)
  319. .sort(sort);
  320. };
  321. userSchema.statics.findAdmins = async function(option) {
  322. const sort = option?.sort ?? { createdAt: -1 };
  323. let status = option?.status ?? [STATUS_ACTIVE];
  324. if (!Array.isArray(status)) {
  325. status = [status];
  326. }
  327. return this.find({ admin: true, status: { $in: status } })
  328. .sort(sort);
  329. };
  330. userSchema.statics.findUserByUsername = function(username) {
  331. if (username == null) {
  332. return Promise.resolve(null);
  333. }
  334. return this.findOne({ username });
  335. };
  336. userSchema.statics.findUserByApiToken = function(apiToken) {
  337. if (apiToken == null) {
  338. return Promise.resolve(null);
  339. }
  340. return this.findOne({ apiToken });
  341. };
  342. userSchema.statics.findUserByGoogleId = function(googleId, callback) {
  343. if (googleId == null) {
  344. callback(null, null);
  345. }
  346. this.findOne({ googleId }, (err, userData) => {
  347. callback(err, userData);
  348. });
  349. };
  350. userSchema.statics.findUserByUsernameOrEmail = function(usernameOrEmail, password, callback) {
  351. this.findOne()
  352. .or([
  353. { username: usernameOrEmail },
  354. { email: usernameOrEmail },
  355. ])
  356. .exec((err, userData) => {
  357. callback(err, userData);
  358. });
  359. };
  360. userSchema.statics.findUserByEmailAndPassword = function(email, password, callback) {
  361. const hashedPassword = generatePassword(password);
  362. this.findOne({ email, password: hashedPassword }, (err, userData) => {
  363. callback(err, userData);
  364. });
  365. };
  366. userSchema.statics.isUserCountExceedsUpperLimit = async function() {
  367. const { configManager } = crowi;
  368. const userUpperLimit = configManager.getConfig('crowi', 'security:userUpperLimit');
  369. const activeUsers = await this.countListByStatus(STATUS_ACTIVE);
  370. if (userUpperLimit <= activeUsers) {
  371. return true;
  372. }
  373. return false;
  374. };
  375. userSchema.statics.countListByStatus = async function(status) {
  376. const User = this;
  377. const conditions = { status };
  378. // TODO count は非推奨。mongoose のバージョンアップ後に countDocuments に変更する。
  379. return User.count(conditions);
  380. };
  381. userSchema.statics.isRegisterableUsername = async function(username) {
  382. let usernameUsable = true;
  383. const userData = await this.findOne({ username });
  384. if (userData) {
  385. usernameUsable = false;
  386. }
  387. return usernameUsable;
  388. };
  389. userSchema.statics.isRegisterableEmail = async function(email) {
  390. let isEmailUsable = true;
  391. const userData = await this.findOne({ email });
  392. if (userData) {
  393. isEmailUsable = false;
  394. }
  395. return isEmailUsable;
  396. };
  397. userSchema.statics.isRegisterable = function(email, username, callback) {
  398. const User = this;
  399. let emailUsable = true;
  400. let usernameUsable = true;
  401. // username check
  402. this.findOne({ username }, (err, userData) => {
  403. if (userData) {
  404. usernameUsable = false;
  405. }
  406. // email check
  407. User.findOne({ email }, (err, userData) => {
  408. if (userData) {
  409. emailUsable = false;
  410. }
  411. if (!emailUsable || !usernameUsable) {
  412. return callback(false, { email: emailUsable, username: usernameUsable });
  413. }
  414. return callback(true, {});
  415. });
  416. });
  417. };
  418. userSchema.statics.resetPasswordByRandomString = async function(id) {
  419. const user = await this.findById(id);
  420. if (!user) {
  421. throw new Error('User not found');
  422. }
  423. const newPassword = generateRandomTempPassword();
  424. user.setPassword(newPassword);
  425. await user.save();
  426. return newPassword;
  427. };
  428. userSchema.statics.createUserByEmail = async function(email) {
  429. const configManager = crowi.configManager;
  430. const User = this;
  431. const newUser = new User();
  432. /* eslint-disable newline-per-chained-call */
  433. const tmpUsername = `temp_${Math.random().toString(36).slice(-16)}`;
  434. const password = Math.random().toString(36).slice(-16);
  435. /* eslint-enable newline-per-chained-call */
  436. newUser.username = tmpUsername;
  437. newUser.email = email;
  438. newUser.setPassword(password);
  439. newUser.status = STATUS_INVITED;
  440. const globalLang = configManager.getConfig('crowi', 'app:globalLang');
  441. if (globalLang != null) {
  442. newUser.lang = globalLang;
  443. }
  444. try {
  445. const newUserData = await newUser.save();
  446. return {
  447. email,
  448. password,
  449. user: newUserData,
  450. };
  451. }
  452. catch (err) {
  453. return {
  454. email,
  455. };
  456. }
  457. };
  458. userSchema.statics.createUsersByEmailList = async function(emailList) {
  459. const User = this;
  460. // check exists and get list of try to create
  461. const existingUserList = await User.find({ email: { $in: emailList }, userStatus: { $ne: STATUS_DELETED } });
  462. const existingEmailList = existingUserList.map((user) => { return user.email });
  463. const creationEmailList = emailList.filter((email) => { return existingEmailList.indexOf(email) === -1 });
  464. const createdUserList = [];
  465. const failedToCreateUserEmailList = [];
  466. for (const email of creationEmailList) {
  467. try {
  468. // eslint-disable-next-line no-await-in-loop
  469. const createdUser = await this.createUserByEmail(email);
  470. createdUserList.push(createdUser);
  471. }
  472. catch (err) {
  473. logger.error(err);
  474. failedToCreateUserEmailList.push({
  475. email,
  476. reason: err.message,
  477. });
  478. }
  479. }
  480. return { createdUserList, existingEmailList, failedToCreateUserEmailList };
  481. };
  482. userSchema.statics.createUserByEmailAndPasswordAndStatus = async function(name, username, email, password, lang, status, callback) {
  483. const User = this;
  484. const newUser = new User();
  485. // check user upper limit
  486. const isUserCountExceedsUpperLimit = await User.isUserCountExceedsUpperLimit();
  487. if (isUserCountExceedsUpperLimit) {
  488. const err = new UserUpperLimitException();
  489. return callback(err);
  490. }
  491. // check email duplication because email must be unique
  492. const count = await this.count({ email });
  493. if (count > 0) {
  494. // eslint-disable-next-line no-param-reassign
  495. email = generateRandomEmail();
  496. }
  497. newUser.name = name;
  498. newUser.username = username;
  499. newUser.email = email;
  500. if (password != null) {
  501. newUser.setPassword(password);
  502. }
  503. const configManager = crowi.configManager;
  504. // Default email show/hide is up to the administrator
  505. newUser.isEmailPublished = configManager.getConfig('crowi', 'customize:isEmailPublishedForNewUser');
  506. const globalLang = configManager.getConfig('crowi', 'app:globalLang');
  507. if (globalLang != null) {
  508. newUser.lang = globalLang;
  509. }
  510. if (lang != null) {
  511. newUser.lang = lang;
  512. }
  513. newUser.status = status || decideUserStatusOnRegistration();
  514. newUser.save((err, userData) => {
  515. if (err) {
  516. logger.error('createUserByEmailAndPasswordAndStatus failed: ', err);
  517. return callback(err);
  518. }
  519. if (userData.status === STATUS_ACTIVE) {
  520. userEvent.emit('activated', userData);
  521. }
  522. return callback(err, userData);
  523. });
  524. };
  525. /**
  526. * A wrapper function of createUserByEmailAndPasswordAndStatus with callback
  527. *
  528. */
  529. userSchema.statics.createUserByEmailAndPassword = function(name, username, email, password, lang, callback) {
  530. this.createUserByEmailAndPasswordAndStatus(name, username, email, password, lang, undefined, callback);
  531. };
  532. /**
  533. * A wrapper function of createUserByEmailAndPasswordAndStatus
  534. *
  535. * @return {Promise<User>}
  536. */
  537. userSchema.statics.createUser = function(name, username, email, password, lang, status) {
  538. const User = this;
  539. return new Promise((resolve, reject) => {
  540. User.createUserByEmailAndPasswordAndStatus(name, username, email, password, lang, status, (err, userData) => {
  541. if (err) {
  542. return reject(err);
  543. }
  544. return resolve(userData);
  545. });
  546. });
  547. };
  548. userSchema.statics.getUsernameByPath = function(path) {
  549. let username = null;
  550. const match = path.match(/^\/user\/([^/]+)\/?/);
  551. if (match) {
  552. username = match[1];
  553. }
  554. return username;
  555. };
  556. userSchema.statics.updateIsInvitationEmailSended = async function(id) {
  557. const user = await this.findById(id);
  558. if (user == null) {
  559. throw new Error('User not found');
  560. }
  561. if (user.status !== 5) {
  562. throw new Error('The status of the user is not "invited"');
  563. }
  564. user.isInvitationEmailSended = true;
  565. user.save();
  566. };
  567. userSchema.statics.findUserBySlackMemberId = async function(slackMemberId) {
  568. const user = this.findOne({ slackMemberId });
  569. if (user == null) {
  570. throw new Error('User not found');
  571. }
  572. return user;
  573. };
  574. userSchema.statics.findUsersBySlackMemberIds = async function(slackMemberIds) {
  575. const users = this.find({ slackMemberId: { $in: slackMemberIds } });
  576. if (users.length === 0) {
  577. throw new Error('No user found');
  578. }
  579. return users;
  580. };
  581. userSchema.statics.findUserByUsernameRegexWithTotalCount = async function(username, status, option) {
  582. const opt = option || {};
  583. const sortOpt = opt.sortOpt || { username: 1 };
  584. const offset = opt.offset || 0;
  585. const limit = opt.limit || 10;
  586. const conditions = { username: { $regex: username, $options: 'i' }, status: { $in: status } };
  587. const users = await this.find(conditions)
  588. .sort(sortOpt)
  589. .skip(offset)
  590. .limit(limit);
  591. const totalCount = (await this.find(conditions).distinct('username')).length;
  592. return { users, totalCount };
  593. };
  594. class UserUpperLimitException {
  595. constructor() {
  596. this.name = this.constructor.name;
  597. }
  598. }
  599. userSchema.statics.STATUS_REGISTERED = STATUS_REGISTERED;
  600. userSchema.statics.STATUS_ACTIVE = STATUS_ACTIVE;
  601. userSchema.statics.STATUS_SUSPENDED = STATUS_SUSPENDED;
  602. userSchema.statics.STATUS_DELETED = STATUS_DELETED;
  603. userSchema.statics.STATUS_INVITED = STATUS_INVITED;
  604. userSchema.statics.USER_FIELDS_EXCEPT_CONFIDENTIAL = USER_FIELDS_EXCEPT_CONFIDENTIAL;
  605. userSchema.statics.PAGE_ITEMS = PAGE_ITEMS;
  606. return mongoose.model('User', userSchema);
  607. };