Răsfoiți Sursa

abolish hasSlackConfig

mizozobu 6 ani în urmă
părinte
comite
5eee2148d1

+ 3 - 4
src/server/crowi/index.js

@@ -82,9 +82,11 @@ Crowi.prototype.init = async function() {
 
 
   // customizeService depends on AppService and XssService
   // customizeService depends on AppService and XssService
   // passportService depends on appService
   // passportService depends on appService
+  // slack depends on setUpSlacklNotification
   await Promise.all([
   await Promise.all([
     this.setUpApp(),
     this.setUpApp(),
     this.setUpXss(),
     this.setUpXss(),
+    this.setUpSlacklNotification(),
   ]);
   ]);
 
 
   await Promise.all([
   await Promise.all([
@@ -95,7 +97,6 @@ Crowi.prototype.init = async function() {
     this.setupSlack(),
     this.setupSlack(),
     this.setupCsrf(),
     this.setupCsrf(),
     this.setUpGlobalNotification(),
     this.setUpGlobalNotification(),
-    this.setUpSlacklNotification(),
     this.setUpFileUpload(),
     this.setUpFileUpload(),
     this.setUpAcl(),
     this.setUpAcl(),
     this.setUpCustomize(),
     this.setUpCustomize(),
@@ -327,11 +328,9 @@ Crowi.prototype.setupMailer = function() {
 
 
 Crowi.prototype.setupSlack = function() {
 Crowi.prototype.setupSlack = function() {
   const self = this;
   const self = this;
-  const config = this.getConfig();
-  const Config = this.model('Config');
 
 
   return new Promise(((resolve, reject) => {
   return new Promise(((resolve, reject) => {
-    if (Config.hasSlackConfig(config)) {
+    if (this.slackNotificationService.hasSlackConfig()) {
       self.slack = require('../util/slack')(self);
       self.slack = require('../util/slack')(self);
     }
     }
 
 

+ 1 - 5
src/server/models/config.js

@@ -390,10 +390,6 @@ module.exports = function(crowi) {
     }
     }
   };
   };
 
 
-  configSchema.statics.hasSlackConfig = function(config) {
-    return Config.hasSlackToken(config) || Config.hasSlackIwhUrl(config);
-  };
-
   /**
   /**
    * for Slack Incoming Webhooks
    * for Slack Incoming Webhooks
    */
    */
@@ -441,7 +437,7 @@ module.exports = function(crowi) {
       attrWhiteList: crowi.xssService.getAttrWhiteList(),
       attrWhiteList: crowi.xssService.getAttrWhiteList(),
       highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
       highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
       isSavedStatesOfTabChanges: crowi.configManager.getConfig('crowi', 'customize:isSavedStatesOfTabChanges'),
       isSavedStatesOfTabChanges: crowi.configManager.getConfig('crowi', 'customize:isSavedStatesOfTabChanges'),
-      hasSlackConfig: crowi.configManager.getConfig('crowi', 'customize:behavior'),
+      hasSlackConfig: crowi.slackNotificationService.hasSlackConfig(),
       env: {
       env: {
         PLANTUML_URI: env.PLANTUML_URI || null,
         PLANTUML_URI: env.PLANTUML_URI || null,
         BLOCKDIAG_URI: env.BLOCKDIAG_URI || null,
         BLOCKDIAG_URI: env.BLOCKDIAG_URI || null,

+ 2 - 2
src/server/routes/admin.js

@@ -14,7 +14,7 @@ module.exports = function(crowi, app) {
   const GlobalNotificationMailSetting = models.GlobalNotificationMailSetting;
   const GlobalNotificationMailSetting = models.GlobalNotificationMailSetting;
   const GlobalNotificationSlackSetting = models.GlobalNotificationSlackSetting; // eslint-disable-line no-unused-vars
   const GlobalNotificationSlackSetting = models.GlobalNotificationSlackSetting; // eslint-disable-line no-unused-vars
 
 
-  const { configManager } = crowi;
+  const { configManager, slackNotificationService } = crowi;
 
 
   const recommendedWhitelist = require('@commons/service/xss/recommended-whitelist');
   const recommendedWhitelist = require('@commons/service/xss/recommended-whitelist');
   const PluginUtils = require('../plugins/plugin-utils');
   const PluginUtils = require('../plugins/plugin-utils');
@@ -270,7 +270,7 @@ module.exports = function(crowi, app) {
   actions.notification.slackAuth = function(req, res) {
   actions.notification.slackAuth = function(req, res) {
     const code = req.query.code;
     const code = req.query.code;
 
 
-    if (!code || !Config.hasSlackConfig(req.config)) {
+    if (!code || !slackNotificationService.hasSlackConfig()) {
       return res.redirect('/admin/notification');
       return res.redirect('/admin/notification');
     }
     }
 
 

+ 2 - 3
src/server/routes/page.js

@@ -8,7 +8,6 @@ module.exports = function(crowi, app) {
 
 
   const Page = crowi.model('Page');
   const Page = crowi.model('Page');
   const User = crowi.model('User');
   const User = crowi.model('User');
-  const Config = crowi.model('Config');
   const config = crowi.getConfig();
   const config = crowi.getConfig();
   const Bookmark = crowi.model('Bookmark');
   const Bookmark = crowi.model('Bookmark');
   const PageTagRelation = crowi.model('PageTagRelation');
   const PageTagRelation = crowi.model('PageTagRelation');
@@ -17,7 +16,7 @@ module.exports = function(crowi, app) {
   const ApiResponse = require('../util/apiResponse');
   const ApiResponse = require('../util/apiResponse');
   const getToday = require('../util/getToday');
   const getToday = require('../util/getToday');
 
 
-  const configManager = crowi.configManager;
+  const { configManager, slackNotificationService } = crowi;
   const interceptorManager = crowi.getInterceptorManager();
   const interceptorManager = crowi.getInterceptorManager();
   const globalNotificationService = crowi.getGlobalNotificationService();
   const globalNotificationService = crowi.getGlobalNotificationService();
 
 
@@ -99,7 +98,7 @@ module.exports = function(crowi, app) {
         logger.error('Error occured in updating slack channels: ', err);
         logger.error('Error occured in updating slack channels: ', err);
       });
       });
 
 
-    if (Config.hasSlackConfig(config)) {
+    if (slackNotificationService.hasSlackConfig(config)) {
       const promises = slackChannels.split(',').map((chan) => {
       const promises = slackChannels.split(',').map((chan) => {
         return crowi.slack.postPage(page, user, chan, updateOrCreate, previousRevision);
         return crowi.slack.postPage(page, user, chan, updateOrCreate, previousRevision);
       });
       });

+ 0 - 22
src/server/service/notification.js

@@ -1,22 +0,0 @@
-
-
-function Notification(crowi) {
-  this.crowi = crowi;
-  this.config = crowi.getConfig();
-}
-
-Notification.prototype.hasSlackConfig = function() {
-  if (!this.config.notification.slack) {
-    return false;
-  }
-
-  // var config = ;
-};
-
-Notification.prototype.noitfyByEmail = function() {
-};
-
-Notification.prototype.noitfyByChat = function() {
-};
-
-module.exports = Notification;

+ 1 - 1
src/server/service/slack-notification.js

@@ -12,7 +12,7 @@ class SlackNotificationService {
     let hasSlackToken = false;
     let hasSlackToken = false;
     let hasSlackIwhUrl = false;
     let hasSlackIwhUrl = false;
 
 
-    if (this.configObject.notification) {
+    if (this.configManager.configObject.notification) {
       hasSlackToken = !!this.configManager.getConfig('notification', 'slack:token');
       hasSlackToken = !!this.configManager.getConfig('notification', 'slack:token');
       hasSlackIwhUrl = !!this.configManager.getConfig('notification', 'slack:incomingWebhookUrl');
       hasSlackIwhUrl = !!this.configManager.getConfig('notification', 'slack:incomingWebhookUrl');
     }
     }

+ 1 - 0
src/server/util/slack.js

@@ -11,6 +11,7 @@ module.exports = function(crowi) {
   const config = crowi.getConfig();
   const config = crowi.getConfig();
   const Config = crowi.model('Config');
   const Config = crowi.model('Config');
   const Slack = require('slack-node');
   const Slack = require('slack-node');
+  const { slackNotificationService } = crowi;
 
 
   const slack = {};
   const slack = {};