Explorar o código

apply to src/server/service

Yuki Takei %!s(int64=7) %!d(string=hai) anos
pai
achega
e478834a12

+ 19 - 20
src/server/service/config-loader.js

@@ -1,9 +1,9 @@
 const debug = require('debug')('growi:service:ConfigLoader');
 
 const TYPES = {
-  NUMBER:  { parse: (v) => parseInt(v) },
-  STRING:  { parse: (v) => v },
-  BOOLEAN: { parse: (v) => /^(true|1)$/i.test(v) }
+  NUMBER:  { parse: (v) => { return parseInt(v) } },
+  STRING:  { parse: (v) => { return v } },
+  BOOLEAN: { parse: (v) => { return /^(true|1)$/i.test(v) } },
 };
 
 /**
@@ -114,78 +114,77 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     ns:      'crowi',
     key:     'app:siteUrl',
     type:    TYPES.STRING,
-    default: null
+    default: null,
   },
   SAML_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS: {
     ns:      'crowi',
     key:     'security:passport-saml:useOnlyEnvVarsForSomeOptions',
     type:    TYPES.BOOLEAN,
-    default: false
+    default: false,
   },
   SAML_ENABLED: {
     ns:      'crowi',
     key:     'security:passport-saml:isEnabled',
     type:    TYPES.BOOLEAN,
-    default: null
+    default: null,
   },
   SAML_ENTRY_POINT: {
     ns:      'crowi',
     key:     'security:passport-saml:entryPoint',
     type:    TYPES.STRING,
-    default: null
+    default: null,
   },
   SAML_CALLBACK_URI: {
     ns:      'crowi',
     key:     'security:passport-saml:callbackUrl',
     type:    TYPES.STRING,
-    default: null
+    default: null,
   },
   SAML_ISSUER: {
     ns:      'crowi',
     key:     'security:passport-saml:issuer',
     type:    TYPES.STRING,
-    default: null
+    default: null,
   },
   SAML_ATTR_MAPPING_ID: {
     ns:      'crowi',
     key:     'security:passport-saml:attrMapId',
     type:    TYPES.STRING,
-    default: null
+    default: null,
   },
   SAML_ATTR_MAPPING_USERNAME: {
     ns:      'crowi',
     key:     'security:passport-saml:attrMapUsername',
     type:    TYPES.STRING,
-    default: null
+    default: null,
   },
   SAML_ATTR_MAPPING_MAIL: {
     ns:      'crowi',
     key:     'security:passport-saml:attrMapMail',
     type:    TYPES.STRING,
-    default: null
+    default: null,
   },
   SAML_ATTR_MAPPING_FIRST_NAME: {
     ns:      'crowi',
     key:     'security:passport-saml:attrMapFirstName',
     type:    TYPES.STRING,
-    default: null
+    default: null,
   },
   SAML_ATTR_MAPPING_LAST_NAME: {
     ns:      'crowi',
     key:     'security:passport-saml:attrMapLastName',
     type:    TYPES.STRING,
-    default: null
+    default: null,
   },
   SAML_CERT: {
     ns:      'crowi',
     key:     'security:passport-saml:cert',
     type:    TYPES.STRING,
-    default: null
-  }
+    default: null,
+  },
 };
 
 class ConfigLoader {
-
   constructor(configModel) {
     this.configModel = configModel;
   }
@@ -198,8 +197,8 @@ class ConfigLoader {
     const configFromEnvVars = this.loadFromEnvVars();
 
     // merge defaults
-    let mergedConfigFromDB = Object.assign({'crowi': this.configModel.getDefaultCrowiConfigsObject()}, configFromDB);
-    mergedConfigFromDB = Object.assign({'markdown': this.configModel.getDefaultMarkdownConfigsObject()}, mergedConfigFromDB);
+    let mergedConfigFromDB = Object.assign({ crowi: this.configModel.getDefaultCrowiConfigsObject() }, configFromDB);
+    mergedConfigFromDB = Object.assign({ markdown: this.configModel.getDefaultMarkdownConfigsObject() }, mergedConfigFromDB);
 
 
     // In getConfig API, only null is used as a value to indicate that a config is not set.
@@ -217,7 +216,7 @@ class ConfigLoader {
 
     return {
       fromDB: mergedConfigFromDB,
-      fromEnvVars: configFromEnvVars
+      fromEnvVars: configFromEnvVars,
     };
   }
 

+ 15 - 10
src/server/service/config-manager.js

@@ -11,11 +11,10 @@ const KEYS_FOR_SAML_USE_ONLY_ENV_OPTION = [
   'security:passport-saml:attrMapMail',
   'security:passport-saml:attrMapFirstName',
   'security:passport-saml:attrMapLastName',
-  'security:passport-saml:cert'
+  'security:passport-saml:cert',
 ];
 
 class ConfigManager {
-
   constructor(configModel) {
     this.configModel = configModel;
     this.configLoader = new ConfigLoader(this.configModel);
@@ -78,6 +77,7 @@ class ConfigManager {
    * With version 3.2.4 to 3.3.4, the system uses the auto-generated site URL only if the config is not set.
    * With version 3.3.5 and above, the system use only a value from the config.
    */
+  /* eslint-disable no-else-return */
   getSiteUrl() {
     const siteUrl = this.getConfig('crowi', 'app:siteUrl');
     if (siteUrl != null) {
@@ -87,6 +87,7 @@ class ConfigManager {
       return '[The site URL is not set. Please set it!]';
     }
   }
+  /* eslint-enable no-else-return */
 
   /**
    * update configs in the same namespace
@@ -107,14 +108,14 @@ class ConfigManager {
    * ```
    */
   async updateConfigsInTheSameNamespace(namespace, configs) {
-    let queries = [];
+    const queries = [];
     for (const key of Object.keys(configs)) {
       queries.push({
         updateOne: {
-          filter: { ns: namespace, key: key },
-          update: { ns: namespace, key: key, value: this.convertInsertValue(configs[key]) },
-          upsert: true
-        }
+          filter: { ns: namespace, key },
+          update: { ns: namespace, key, value: this.convertInsertValue(configs[key]) },
+          upsert: true,
+        },
       });
     }
     await this.configModel.bulkWrite(queries);
@@ -135,21 +136,23 @@ class ConfigManager {
       return undefined;
     }
 
-    if (this.configExistsInDB(namespace, key) && !this.configExistsInEnvVars(namespace, key) ) {
+    if (this.configExistsInDB(namespace, key) && !this.configExistsInEnvVars(namespace, key)) {
       return this.configObject.fromDB[namespace][key];
     }
 
-    if (!this.configExistsInDB(namespace, key) && this.configExistsInEnvVars(namespace, key) ) {
+    if (!this.configExistsInDB(namespace, key) && this.configExistsInEnvVars(namespace, key)) {
       return this.configObject.fromEnvVars[namespace][key];
     }
 
-    if (this.configExistsInDB(namespace, key) && this.configExistsInEnvVars(namespace, key) ) {
+    if (this.configExistsInDB(namespace, key) && this.configExistsInEnvVars(namespace, key)) {
+      /* eslint-disable no-else-return */
       if (this.configObject.fromDB[namespace][key] !== null) {
         return this.configObject.fromDB[namespace][key];
       }
       else {
         return this.configObject.fromEnvVars[namespace][key];
       }
+      /* eslint-enable no-else-return */
     }
   }
 
@@ -158,6 +161,7 @@ class ConfigManager {
    * this searches only from configs loaded from the environment variables.
    * For the other configs, this searches as the same way to defaultSearch.
    */
+  /* eslint-disable no-else-return */
   searchInSAMLUseOnlyEnvMode(namespace, key) {
     if (namespace === 'crowi' && KEYS_FOR_SAML_USE_ONLY_ENV_OPTION.includes(key)) {
       return this.searchOnlyFromEnvVarConfigs(namespace, key);
@@ -166,6 +170,7 @@ class ConfigManager {
       return this.defaultSearch(namespace, key);
     }
   }
+  /* eslint-enable no-else-return */
 
   /**
    * search a specified config from configs loaded from the database

+ 3 - 5
src/server/service/file-uploader/aws.js

@@ -5,7 +5,6 @@ const urljoin = require('url-join');
 const aws = require('aws-sdk');
 
 module.exports = function(crowi) {
-
   const lib = {};
 
   function getAwsConfig() {
@@ -14,7 +13,7 @@ module.exports = function(crowi) {
       accessKeyId: config.crowi['aws:accessKeyId'],
       secretAccessKey: config.crowi['aws:secretAccessKey'],
       region: config.crowi['aws:region'],
-      bucket: config.crowi['aws:bucket']
+      bucket: config.crowi['aws:bucket'],
     };
   }
 
@@ -30,14 +29,14 @@ module.exports = function(crowi) {
     aws.config.update({
       accessKeyId: awsConfig.accessKeyId,
       secretAccessKey: awsConfig.secretAccessKey,
-      region: awsConfig.region
+      region: awsConfig.region,
     });
 
     return new aws.S3();
   }
 
   function getFilePathOnStorage(attachment) {
-    if (attachment.filePath != null) {  // backward compatibility for v3.3.x or below
+    if (attachment.filePath != null) { // backward compatibility for v3.3.x or below
       return attachment.filePath;
     }
 
@@ -118,4 +117,3 @@ module.exports = function(crowi) {
 
   return lib;
 };
-

+ 7 - 8
src/server/service/file-uploader/gridfs.js

@@ -3,15 +3,13 @@ const mongoose = require('mongoose');
 const util = require('util');
 
 module.exports = function(crowi) {
-  'use strict';
-
   const lib = {};
 
   // instantiate mongoose-gridfs
   const gridfs = require('mongoose-gridfs')({
     collection: 'attachmentFiles',
     model: 'AttachmentFile',
-    mongooseConnection: mongoose.connection
+    mongooseConnection: mongoose.connection,
   });
 
   // obtain a model
@@ -24,13 +22,13 @@ module.exports = function(crowi) {
   lib.deleteFile = async function(attachment) {
     let filenameValue = attachment.fileName;
 
-    if (attachment.filePath != null) {  // backward compatibility for v3.3.x or below
+    if (attachment.filePath != null) { // backward compatibility for v3.3.x or below
       filenameValue = attachment.filePath;
     }
 
     const attachmentFile = await AttachmentFile.findOne({ filename: filenameValue });
 
-    AttachmentFile.unlinkById(attachmentFile._id, function(error, unlinkedFile) {
+    AttachmentFile.unlinkById(attachmentFile._id, (error, unlinkedFile) => {
       if (error) {
         throw new Error(error);
       }
@@ -70,9 +68,10 @@ module.exports = function(crowi) {
     return AttachmentFile.promisifiedWrite(
       {
         filename: attachment.fileName,
-        contentType: attachment.fileFormat
+        contentType: attachment.fileFormat,
       },
-      fileStream);
+      fileStream,
+    );
   };
 
   /**
@@ -84,7 +83,7 @@ module.exports = function(crowi) {
   lib.findDeliveryFile = async function(attachment) {
     let filenameValue = attachment.fileName;
 
-    if (attachment.filePath != null) {  // backward compatibility for v3.3.x or below
+    if (attachment.filePath != null) { // backward compatibility for v3.3.x or below
       filenameValue = attachment.filePath;
     }
 

+ 0 - 2
src/server/service/file-uploader/index.js

@@ -8,7 +8,6 @@ const envToModuleMappings = {
 };
 
 class FileUploaderFactory {
-
   getUploader(crowi) {
     if (this.uploader == null) {
       const method = envToModuleMappings[process.env.FILE_UPLOAD] || 'aws';
@@ -18,7 +17,6 @@ class FileUploaderFactory {
 
     return this.uploader;
   }
-
 }
 
 const factory = new FileUploaderFactory();

+ 1 - 5
src/server/service/file-uploader/local.js

@@ -6,14 +6,12 @@ const mkdir = require('mkdirp');
 const streamToPromise = require('stream-to-promise');
 
 module.exports = function(crowi) {
-  'use strict';
-
   const lib = {};
   const basePath = path.posix.join(crowi.publicDir, 'uploads');
 
   function getFilePathOnStorage(attachment) {
     let filePath;
-    if (attachment.filePath != null) {  // backward compatibility for v3.3.x or below
+    if (attachment.filePath != null) { // backward compatibility for v3.3.x or below
       filePath = path.posix.join(basePath, attachment.filePath);
     }
     else {
@@ -78,5 +76,3 @@ module.exports = function(crowi) {
 
   return lib;
 };
-
-

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 7 - 13
src/server/service/file-uploader/none.js


+ 18 - 19
src/server/service/global-notification.js

@@ -4,7 +4,6 @@ const path = require('path');
  * the service class of GlobalNotificationSetting
  */
 class GlobalNotificationService {
-
   constructor(crowi) {
     this.crowi = crowi;
     this.config = crowi.getConfig();
@@ -16,7 +15,7 @@ class GlobalNotificationService {
   }
 
   notifyByMail(notification, mailOption) {
-    this.mailer.send(Object.assign(mailOption, {to: notification.toEmail}));
+    this.mailer.send(Object.assign(mailOption, { to: notification.toEmail }));
   }
 
   notifyBySlack(notification, slackOption) {
@@ -24,7 +23,7 @@ class GlobalNotificationService {
   }
 
   sendNotification(notifications, option) {
-    notifications.forEach(notification => {
+    notifications.forEach((notification) => {
       if (notification.__t === 'mail') {
         this.notifyByMail(notification, option.mail);
       }
@@ -41,7 +40,7 @@ class GlobalNotificationService {
    */
   async notifyPageCreate(page) {
     const notifications = await this.GlobalNotification.findSettingByPathAndEvent(page.path, 'pageCreate');
-    const lang = 'en-US'; //FIXME
+    const lang = 'en-US'; // FIXME
     const option = {
       mail: {
         subject: `#pageCreate - ${page.creator.username} created ${page.path}`,
@@ -50,7 +49,7 @@ class GlobalNotificationService {
           appTitle: this.appTitle,
           path: page.path,
           username: page.creator.username,
-        }
+        },
       },
       slack: {},
     };
@@ -67,7 +66,7 @@ class GlobalNotificationService {
    */
   async notifyPageEdit(page) {
     const notifications = await this.GlobalNotification.findSettingByPathAndEvent(page.path, 'pageEdit');
-    const lang = 'en-US'; //FIXME
+    const lang = 'en-US'; // FIXME
     const option = {
       mail: {
         subject: `#pageEdit - ${page.creator.username} edited ${page.path}`,
@@ -76,7 +75,7 @@ class GlobalNotificationService {
           appTitle: this.appTitle,
           path: page.path,
           username: page.creator.username,
-        }
+        },
       },
       slack: {},
     };
@@ -93,16 +92,16 @@ class GlobalNotificationService {
    */
   async notifyPageDelete(page) {
     const notifications = await this.GlobalNotification.findSettingByPathAndEvent(page.path, 'pageDelete');
-    const lang = 'en-US'; //FIXME
+    const lang = 'en-US'; // FIXME
     const option = {
       mail: {
-        subject: `#pageDelete - ${page.creator.username} deleted ${page.path}`,  //FIXME
+        subject: `#pageDelete - ${page.creator.username} deleted ${page.path}`, // FIXME
         template: `../../locales/${lang}/notifications/pageDelete.txt`,
         vars: {
           appTitle: this.appTitle,
           path: page.path,
           username: page.creator.username,
-        }
+        },
       },
       slack: {},
     };
@@ -117,17 +116,17 @@ class GlobalNotificationService {
    */
   async notifyPageMove(page, oldPagePath, user) {
     const notifications = await this.GlobalNotification.findSettingByPathAndEvent(page.path, 'pageMove');
-    const lang = 'en-US'; //FIXME
+    const lang = 'en-US'; // FIXME
     const option = {
       mail: {
-        subject: `#pageMove - ${user.username} moved ${page.path} to ${page.path}`, //FIXME
+        subject: `#pageMove - ${user.username} moved ${page.path} to ${page.path}`, // FIXME
         template: `../../locales/${lang}/notifications/pageMove.txt`,
         vars: {
           appTitle: this.appTitle,
           oldPath: oldPagePath,
           newPath: page.path,
           username: user.username,
-        }
+        },
       },
       slack: {},
     };
@@ -142,7 +141,7 @@ class GlobalNotificationService {
    */
   async notifyPageLike(page, user) {
     const notifications = await this.GlobalNotification.findSettingByPathAndEvent(page.path, 'pageLike');
-    const lang = 'en-US'; //FIXME
+    const lang = 'en-US'; // FIXME
     const option = {
       mail: {
         subject: `#pageLike - ${user.username} liked ${page.path}`,
@@ -151,7 +150,7 @@ class GlobalNotificationService {
           appTitle: this.appTitle,
           path: page.path,
           username: page.creator.username,
-        }
+        },
       },
       slack: {},
     };
@@ -167,18 +166,18 @@ class GlobalNotificationService {
    */
   async notifyComment(comment, path) {
     const notifications = await this.GlobalNotification.findSettingByPathAndEvent(path, 'comment');
-    const lang = 'en-US'; //FIXME
-    const user = await this.User.findOne({_id: comment.creator});
+    const lang = 'en-US'; // FIXME
+    const user = await this.User.findOne({ _id: comment.creator });
     const option = {
       mail: {
         subject: `#comment - ${user.username} commented on ${path}`,
         template: `../../locales/${lang}/notifications/comment.txt`,
         vars: {
           appTitle: this.appTitle,
-          path: path,
+          path,
           username: user.username,
           comment: comment.comment,
-        }
+        },
       },
       slack: {},
     };

+ 3 - 3
src/server/service/notification.js

@@ -1,4 +1,4 @@
-'use strict';
+
 
 function Notification(crowi) {
   this.crowi = crowi;
@@ -6,11 +6,11 @@ function Notification(crowi) {
 }
 
 Notification.prototype.hasSlackConfig = function() {
-  if (!this.config.notification['slack']) {
+  if (!this.config.notification.slack) {
     return false;
   }
 
-  //var config = ;
+  // var config = ;
 };
 
 Notification.prototype.noitfyByEmail = function() {

+ 53 - 51
src/server/service/passport.js

@@ -12,9 +12,9 @@ const SamlStrategy = require('passport-saml').Strategy;
  * the service class of Passport
  */
 class PassportService {
-
   // see '/lib/form/login.js'
   static get USERNAME_FIELD() { return 'loginForm[username]' }
+
   static get PASSWORD_FIELD() { return 'loginForm[password]' }
 
   constructor(crowi) {
@@ -65,7 +65,7 @@ class PassportService {
       'security:passport-saml:cert',
       'security:passport-saml:attrMapId',
       'security:passport-saml:attrMapUsername',
-      'security:passport-saml:attrMapMail'
+      'security:passport-saml:attrMapMail',
     ];
   }
 
@@ -110,7 +110,7 @@ class PassportService {
           }
           return done(null, user);
         });
-      }
+      },
     ));
 
     this.isLocalStrategySetup = true;
@@ -150,7 +150,7 @@ class PassportService {
 
     debug('LdapStrategy: setting up..');
 
-    passport.use(new LdapStrategy(this.getLdapConfigurationFunc(config, {passReqToCallback: true}),
+    passport.use(new LdapStrategy(this.getLdapConfigurationFunc(config, { passReqToCallback: true }),
       (req, ldapAccountInfo, done) => {
         debug('LDAP authentication has succeeded', ldapAccountInfo);
 
@@ -158,8 +158,7 @@ class PassportService {
         req.ldapAccountInfo = ldapAccountInfo;
 
         done(null, ldapAccountInfo);
-      }
-    ));
+      }));
 
     this.isLdapStrategySetup = true;
     debug('LdapStrategy: setup is done');
@@ -175,6 +174,7 @@ class PassportService {
     const config = this.crowi.config;
     return config.crowi['security:passport-ldap:attrMapUsername'] || 'uid';
   }
+
   /**
    * return attribute name for mapping to name of Crowi DB
    *
@@ -185,6 +185,7 @@ class PassportService {
     const config = this.crowi.config;
     return config.crowi['security:passport-ldap:attrMapName'] || '';
   }
+
   /**
    * return attribute name for mapping to name of Crowi DB
    *
@@ -217,6 +218,8 @@ class PassportService {
    * @memberof PassportService
    */
   getLdapConfigurationFunc(config, opts) {
+    /* eslint-disable no-multi-spaces */
+
     // get configurations
     const isUserBind          = config.crowi['security:passport-ldap:isUserBind'];
     const serverUrl           = config.crowi['security:passport-ldap:serverUrl'];
@@ -226,13 +229,14 @@ class PassportService {
     const groupSearchBase     = config.crowi['security:passport-ldap:groupSearchBase'];
     const groupSearchFilter   = config.crowi['security:passport-ldap:groupSearchFilter'];
     const groupDnProperty     = config.crowi['security:passport-ldap:groupDnProperty'] || 'uid';
+    /* eslint-enable no-multi-spaces */
 
     // parse serverUrl
     // see: https://regex101.com/r/0tuYBB/1
     const match = serverUrl.match(/(ldaps?:\/\/[^/]+)\/(.*)?/);
     if (match == null || match.length < 1) {
       debug('LdapStrategy: serverUrl is invalid');
-      return (req, callback) => { callback({ message: 'serverUrl is invalid'}) };
+      return (req, callback) => { callback({ message: 'serverUrl is invalid' }) };
     }
     const url = match[1];
     const searchBase = match[2] || '';
@@ -257,13 +261,16 @@ class PassportService {
       }
 
       // user bind
-      const fixedBindDN = (isUserBind) ?
-        bindDN.replace(/{{username}}/, loginForm.username):
-        bindDN;
+      const fixedBindDN = (isUserBind)
+        ? bindDN.replace(/{{username}}/, loginForm.username)
+        : bindDN;
       const fixedBindCredentials = (isUserBind) ? loginForm.password : bindCredentials;
       let serverOpt = {
-        url, bindDN: fixedBindDN, bindCredentials: fixedBindCredentials,
-        searchBase, searchFilter,
+        url,
+        bindDN: fixedBindDN,
+        bindCredentials: fixedBindCredentials,
+        searchBase,
+        searchFilter,
         attrMapUsername: this.getLdapAttrNameMappedToUsername(),
         attrMapName: this.getLdapAttrNameMappedToName(),
       };
@@ -313,17 +320,16 @@ class PassportService {
       clientId: config.crowi['security:passport-google:clientId'] || process.env.OAUTH_GOOGLE_CLIENT_ID,
       clientSecret: config.crowi['security:passport-google:clientSecret'] || process.env.OAUTH_GOOGLE_CLIENT_SECRET,
       callbackURL: (this.crowi.configManager.getConfig('crowi', 'app:siteUrl') != null)
-        ? urljoin(this.crowi.configManager.getSiteUrl(), '/passport/google/callback')                       // auto-generated with v3.2.4 and above
-        : config.crowi['security:passport-google:callbackUrl'] || process.env.OAUTH_GOOGLE_CALLBACK_URI,    // DEPRECATED: backward compatible with v3.2.3 and below
+        ? urljoin(this.crowi.configManager.getSiteUrl(), '/passport/google/callback') // auto-generated with v3.2.4 and above
+        : config.crowi['security:passport-google:callbackUrl'] || process.env.OAUTH_GOOGLE_CALLBACK_URI, // DEPRECATED: backward compatible with v3.2.3 and below
       skipUserProfile: false,
-    }, function(accessToken, refreshToken, profile, done) {
-      if (profile) {
-        return done(null, profile);
-      }
-      else {
+    }, ((accessToken, refreshToken, profile, done) => {
+        if (profile) {
+          return done(null, profile);
+        }
+
         return done(null, false);
-      }
-    }));
+      })));
 
     this.isGoogleStrategySetup = true;
     debug('GoogleStrategy: setup is done');
@@ -360,17 +366,16 @@ class PassportService {
       clientID: config.crowi['security:passport-github:clientId'] || process.env.OAUTH_GITHUB_CLIENT_ID,
       clientSecret: config.crowi['security:passport-github:clientSecret'] || process.env.OAUTH_GITHUB_CLIENT_SECRET,
       callbackURL: (this.crowi.configManager.getConfig('crowi', 'app:siteUrl') != null)
-        ? urljoin(this.crowi.configManager.getSiteUrl(), '/passport/github/callback')                       // auto-generated with v3.2.4 and above
-        : config.crowi['security:passport-github:callbackUrl'] || process.env.OAUTH_GITHUB_CALLBACK_URI,    // DEPRECATED: backward compatible with v3.2.3 and below
+        ? urljoin(this.crowi.configManager.getSiteUrl(), '/passport/github/callback') // auto-generated with v3.2.4 and above
+        : config.crowi['security:passport-github:callbackUrl'] || process.env.OAUTH_GITHUB_CALLBACK_URI, // DEPRECATED: backward compatible with v3.2.3 and below
       skipUserProfile: false,
-    }, function(accessToken, refreshToken, profile, done) {
-      if (profile) {
-        return done(null, profile);
-      }
-      else {
+    }, ((accessToken, refreshToken, profile, done) => {
+        if (profile) {
+          return done(null, profile);
+        }
+
         return done(null, false);
-      }
-    }));
+      })));
 
     this.isGitHubStrategySetup = true;
     debug('GitHubStrategy: setup is done');
@@ -407,17 +412,16 @@ class PassportService {
       consumerKey: config.crowi['security:passport-twitter:consumerKey'] || process.env.OAUTH_TWITTER_CONSUMER_KEY,
       consumerSecret: config.crowi['security:passport-twitter:consumerSecret'] || process.env.OAUTH_TWITTER_CONSUMER_SECRET,
       callbackURL: (this.crowi.configManager.getConfig('crowi', 'app:siteUrl') != null)
-        ? urljoin(this.crowi.configManager.getSiteUrl(), '/passport/twitter/callback')                       // auto-generated with v3.2.4 and above
-        : config.crowi['security:passport-twitter:callbackUrl'] || process.env.OAUTH_TWITTER_CALLBACK_URI,   // DEPRECATED: backward compatible with v3.2.3 and below
+        ? urljoin(this.crowi.configManager.getSiteUrl(), '/passport/twitter/callback') // auto-generated with v3.2.4 and above
+        : config.crowi['security:passport-twitter:callbackUrl'] || process.env.OAUTH_TWITTER_CALLBACK_URI, // DEPRECATED: backward compatible with v3.2.3 and below
       skipUserProfile: false,
-    }, function(accessToken, refreshToken, profile, done) {
-      if (profile) {
-        return done(null, profile);
-      }
-      else {
+    }, ((accessToken, refreshToken, profile, done) => {
+        if (profile) {
+          return done(null, profile);
+        }
+
         return done(null, false);
-      }
-    }));
+      })));
 
     this.isTwitterStrategySetup = true;
     debug('TwitterStrategy: setup is done');
@@ -440,7 +444,6 @@ class PassportService {
       throw new Error('SamlStrategy has already been set up');
     }
 
-    const config = this.crowi.config;
     const configManager = this.crowi.configManager;
     const isSamlEnabled = configManager.getConfig('crowi', 'security:passport-saml:isEnabled');
 
@@ -453,18 +456,17 @@ class PassportService {
     passport.use(new SamlStrategy({
       entryPoint: configManager.getConfig('crowi', 'security:passport-saml:entryPoint'),
       callbackUrl: (this.crowi.configManager.getConfig('crowi', 'app:siteUrl') != null)
-        ? urljoin(this.crowi.configManager.getSiteUrl(), '/passport/saml/callback')  // auto-generated with v3.2.4 and above
-        : configManager.getConfig('crowi', 'security:passport-saml:callbackUrl'),    // DEPRECATED: backward compatible with v3.2.3 and below
+        ? urljoin(this.crowi.configManager.getSiteUrl(), '/passport/saml/callback') // auto-generated with v3.2.4 and above
+        : configManager.getConfig('crowi', 'security:passport-saml:callbackUrl'), // DEPRECATED: backward compatible with v3.2.3 and below
       issuer: configManager.getConfig('crowi', 'security:passport-saml:issuer'),
       cert: configManager.getConfig('crowi', 'security:passport-saml:cert'),
-    }, function(profile, done) {
-      if (profile) {
-        return done(null, profile);
-      }
-      else {
+    }, ((profile, done) => {
+        if (profile) {
+          return done(null, profile);
+        }
+
         return done(null, false);
-      }
-    }));
+      })));
 
     this.isSamlStrategySetup = true;
     debug('SamlStrategy: setup is done');
@@ -509,10 +511,10 @@ class PassportService {
 
     const User = this.crowi.model('User');
 
-    passport.serializeUser(function(user, done) {
+    passport.serializeUser((user, done) => {
       done(null, user.id);
     });
-    passport.deserializeUser(async function(id, done) {
+    passport.deserializeUser(async(id, done) => {
       try {
         const user = await User.findById(id).populate(User.IMAGE_POPULATION);
         if (user == null) {

+ 8 - 9
src/server/service/rest-qiita-API.js

@@ -4,9 +4,9 @@ function getAxios(team, token) {
     headers: {
       'Content-Type': 'application/json',
       'X-Requested-With': 'XMLHttpRequest',
-      'authorization': `Bearer ${token}`
+      authorization: `Bearer ${token}`,
     },
-    responseType: 'json'
+    responseType: 'json',
   });
 }
 
@@ -16,7 +16,6 @@ function getAxios(team, token) {
  */
 
 class RestQiitaAPIService {
-
   constructor(crowi) {
     this.crowi = crowi;
     this.config = crowi.getConfig();
@@ -43,11 +42,11 @@ class RestQiitaAPIService {
    */
   async restAPI(path) {
     return this.axios.get(path)
-      .then(function(res) {
+      .then((res) => {
         const data = res.data;
         const total = res.headers['total-count'];
 
-        return {data, total};
+        return { data, total };
       });
   }
 
@@ -69,15 +68,15 @@ class RestQiitaAPIService {
    * get Qiita pages
    * @memberof RestQiitaAPI
    * @param {string} pageNum
-   * @param {string} per_page
+   * @param {string} perPage
    */
-  async getQiitaPages(pageNum, per_page) {
-    const res = await this.restAPI(`/items?page=${pageNum}&per_page=${per_page}`);
+  async getQiitaPages(pageNum, perPage) {
+    const res = await this.restAPI(`/items?page=${pageNum}&per_page=${perPage}`);
     const pages = res.data;
     const total = res.total;
 
     if (pages.length > 0) {
-      return {pages, total};
+      return { pages, total };
     }
   }
 }

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio