user.js 21 KB

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