Yuki Takei 7 лет назад
Родитель
Сommit
26b4d8b034

+ 10 - 9
src/server/models/config.js

@@ -1,6 +1,8 @@
 // disable no-return-await for model functions
 /* eslint-disable no-return-await */
 
+/* eslint-disable no-use-before-define */
+
 module.exports = function(crowi) {
   const mongoose = require('mongoose');
   const debug = require('debug')('growi:models:config');
@@ -13,10 +15,9 @@ module.exports = function(crowi) {
   const SECURITY_REGISTRATION_MODE_RESTRICTED = 'Resricted';
   const SECURITY_REGISTRATION_MODE_CLOSED = 'Closed';
 
-  let configSchema;
   let Config;
 
-  configSchema = new mongoose.Schema({
+  const configSchema = new mongoose.Schema({
     ns: { type: String, required: true, index: true },
     key: { type: String, required: true, index: true },
     value: { type: String, required: true },
@@ -312,7 +313,7 @@ module.exports = function(crowi) {
 
   configSchema.statics.isEnabledPassport = function(config) {
     // always true if growi installed cleanly
-    if (Object.keys(config.crowi).length == 0) {
+    if (Object.keys(config.crowi).length === 0) {
       return true;
     }
 
@@ -343,7 +344,7 @@ module.exports = function(crowi) {
   configSchema.statics.isUploadable = function(config) {
     const method = process.env.FILE_UPLOAD || 'aws';
 
-    if (method == 'aws' && (
+    if (method === 'aws' && (
       !config.crowi['aws:accessKeyId']
         || !config.crowi['aws:secretAccessKey']
         || !config.crowi['aws:region']
@@ -351,7 +352,7 @@ module.exports = function(crowi) {
       return false;
     }
 
-    return method != 'none';
+    return method !== 'none';
   };
 
   configSchema.statics.isGuestAllowedToRead = function(config) {
@@ -394,7 +395,7 @@ module.exports = function(crowi) {
   };
   configSchema.statics.isPublicWikiOnly = function(config) {
     const publicWikiOnly = process.env.PUBLIC_WIKI_ONLY;
-    if (publicWikiOnly === 'true' || publicWikiOnly == 1) {
+    if (publicWikiOnly === 'true' || publicWikiOnly === 1) {
       return true;
     }
     return false;
@@ -507,7 +508,7 @@ module.exports = function(crowi) {
     const key = 'customize:title';
     let customTitle = getValueForCrowiNS(config, key);
 
-    if (customTitle == null || customTitle.trim().length == 0) {
+    if (customTitle == null || customTitle.trim().length === 0) {
       customTitle = '{{page}} - {{sitename}}';
     }
 
@@ -603,7 +604,7 @@ module.exports = function(crowi) {
     const Config = this;
     const env = process.env;
 
-    const local_config = {
+    const localConfig = {
       crowi: {
         title: Config.appTitle(crowi),
         url: crowi.configManager.getSiteUrl(),
@@ -635,7 +636,7 @@ module.exports = function(crowi) {
       globalLang: Config.globalLang(config),
     };
 
-    return local_config;
+    return localConfig;
   };
 
   configSchema.statics.userUpperLimit = function(crowi) {

+ 18 - 14
src/server/models/external-account.js

@@ -23,6 +23,19 @@ schema.index({ providerType: 1, accountId: 1 }, { unique: true });
 schema.plugin(mongoosePaginate);
 schema.plugin(uniqueValidator);
 
+/**
+ * The Exception class thrown when User.username is duplicated when creating user
+ *
+ * @class DuplicatedUsernameException
+ */
+class DuplicatedUsernameException {
+  constructor(message, user) {
+    this.name = this.constructor.name;
+    this.message = message;
+    this.user = user;
+  }
+}
+
 /**
  * ExternalAccount Class
  *
@@ -75,7 +88,10 @@ class ExternalAccount {
    * @returns {Promise<ExternalAccount>}
    * @memberof ExternalAccount
    */
-  static findOrRegister(providerType, accountId, usernameToBeRegistered, nameToBeRegistered, mailToBeRegistered, isSameUsernameTreatedAsIdenticalUser, isSameEmailTreatedAsIdenticalUser) {
+  static findOrRegister(providerType, accountId,
+      usernameToBeRegistered, nameToBeRegistered, mailToBeRegistered,
+      isSameUsernameTreatedAsIdenticalUser, isSameEmailTreatedAsIdenticalUser) {
+    //
     return this.findOne({ providerType, accountId })
       .then((account) => {
         // ExternalAccount is found
@@ -105,6 +121,7 @@ class ExternalAccount {
               throw new DuplicatedUsernameException(`User '${usernameToBeRegistered}' already exists`, user);
             }
             if (nameToBeRegistered == null) {
+              // eslint-disable-next-line no-param-reassign
               nameToBeRegistered = '';
             }
 
@@ -156,19 +173,6 @@ class ExternalAccount {
   }
 }
 
-/**
- * The Exception class thrown when User.username is duplicated when creating user
- *
- * @class DuplicatedUsernameException
- */
-class DuplicatedUsernameException {
-  constructor(message, user) {
-    this.name = this.constructor.name;
-    this.message = message;
-    this.user = user;
-  }
-}
-
 module.exports = function(crowi) {
   ExternalAccount.crowi = crowi;
   schema.loadClass(ExternalAccount);

+ 2 - 1
src/server/models/revision.js

@@ -44,7 +44,7 @@ module.exports = function(crowi) {
     const User = crowi.model('User');
 
     if (!Array.isArray(ids)) {
-      return Promise.reject('The argument was not Array.');
+      return Promise.reject(new Error('The argument was not Array.'));
     }
 
     return new Promise(((resolve, reject) => {
@@ -107,6 +107,7 @@ module.exports = function(crowi) {
     const Revision = this;
 
     if (!options) {
+      // eslint-disable-next-line no-param-reassign
       options = {};
     }
     const format = options.format || 'markdown';

+ 2 - 3
src/server/models/tag.js

@@ -21,9 +21,8 @@ schema.plugin(mongoosePaginate);
  * @class Tag
  */
 class Tag {
-  async findOrCreate(tagName) {
-
-  }
+  // async findOrCreate(tagName) {
+  // }
 }
 
 module.exports = function() {

+ 8 - 7
src/server/models/updatePost.js

@@ -9,10 +9,8 @@ module.exports = function(crowi) {
   const mongoose = require('mongoose');
   const ObjectId = mongoose.Schema.Types.ObjectId;
 
-  let updatePostSchema;
-
   // TODO: slack 以外の対応
-  updatePostSchema = new mongoose.Schema({
+  const updatePostSchema = new mongoose.Schema({
     pathPattern: { type: String, required: true },
     patternPrefix:  { type: String, required: true },
     patternPrefix2: { type: String, required: true },
@@ -36,11 +34,11 @@ module.exports = function(crowi) {
 
     const pattern = pathPattern.split('/');
     pattern.shift();
-    if (pattern[0] && pattern[0] != '*') {
+    if (pattern[0] && pattern[0] !== '*') {
       patternPrefix[0] = pattern[0];
     }
 
-    if (pattern[1] && pattern[1] != '*') {
+    if (pattern[1] && pattern[1] !== '*') {
       patternPrefix[1] = pattern[1];
     }
     return patternPrefix;
@@ -70,11 +68,13 @@ module.exports = function(crowi) {
           { patternPrefix: prefixes[0], patternPrefix2: '*' },
           { patternPrefix: '*', patternPrefix2: prefixes[1] },
         ],
-      }).then((settings) => {
+      })
+      .then((settings) => {
         if (settings.length <= 0) {
           return resolve(settings);
         }
 
+        // eslint-disable-next-line no-param-reassign
         settings = settings.filter((setting) => {
           const patternRegex = UpdatePost.getRegExpByPattern(setting.pathPattern);
           return patternRegex.test(path);
@@ -87,7 +87,8 @@ module.exports = function(crowi) {
 
   updatePostSchema.statics.findAll = function(offset) {
     const UpdatePost = this;
-    var offset = offset || 0;
+    // eslint-disable-next-line no-param-reassign
+    offset = offset || 0;
 
     return new Promise(((resolve, reject) => {
       UpdatePost