Просмотр исходного кода

remove slackNotificationService

Yuki Takei 4 лет назад
Родитель
Сommit
a6146cac30

+ 2 - 14
packages/app/src/server/crowi/index.js

@@ -46,7 +46,6 @@ function Crowi() {
   this.passportService = null;
   this.globalNotificationService = null;
   this.userNotificationService = null;
-  this.slackNotificationService = null;
   this.xssService = null;
   this.aclService = null;
   this.appService = null;
@@ -94,12 +93,12 @@ Crowi.prototype.init = async function() {
 
   // customizeService depends on AppService and XssService
   // passportService depends on appService
-  // slack depends on setUpSlacklNotification
+  // slack depends on setupSlackIntegrationService
   // export and import depends on setUpGrowiBridge
   await Promise.all([
     this.setUpApp(),
     this.setUpXss(),
-    this.setUpSlacklNotification(),
+    this.setupSlackIntegrationService(),
     this.setUpGrowiBridge(),
   ]);
 
@@ -122,7 +121,6 @@ Crowi.prototype.init = async function() {
     this.setupImport(),
     this.setupPageService(),
     this.setupSyncPageStatusService(),
-    this.setupSlackIntegrationService(),
   ]);
 
   // globalNotification depends on slack and mailer
@@ -532,16 +530,6 @@ Crowi.prototype.setUpUserNotification = async function() {
   }
 };
 
-/**
- * setup SlackNotificationService
- */
-Crowi.prototype.setUpSlacklNotification = async function() {
-  const SlackNotificationService = require('../service/slack-notification');
-  if (this.slackNotificationService == null) {
-    this.slackNotificationService = new SlackNotificationService(this.configManager);
-  }
-};
-
 /**
  * setup XssService
  */

+ 1 - 1
packages/app/src/server/models/config.ts

@@ -216,7 +216,7 @@ schema.statics.getLocalconfig = function(crowi) {
     isSavedStatesOfTabChanges: crowi.configManager.getConfig('crowi', 'customize:isSavedStatesOfTabChanges'),
     isEnabledAttachTitleHeader: crowi.configManager.getConfig('crowi', 'customize:isEnabledAttachTitleHeader'),
     customizeScript: crowi.configManager.getConfig('crowi', 'customize:script'),
-    hasSlackConfig: crowi.slackNotificationService.hasSlackConfig(),
+    hasSlackConfig: crowi.slackIntegrationService.hasSlackConfig(),
     env: {
       PLANTUML_URI: env.PLANTUML_URI || null,
       BLOCKDIAG_URI: env.BLOCKDIAG_URI || null,

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

@@ -14,7 +14,7 @@ module.exports = function(crowi, app) {
   const {
     configManager,
     aclService,
-    slackNotificationService,
+    slackIntegrationService,
     exportService,
   } = crowi;
 
@@ -160,7 +160,7 @@ module.exports = function(crowi, app) {
     const code = req.query.code;
     const { t } = req;
 
-    if (!code || !slackNotificationService.hasSlackConfig()) {
+    if (!code || !slackIntegrationService.hasSlackConfig()) {
       return res.redirect('/admin/notification');
     }
 

+ 13 - 0
packages/app/src/server/service/slack-integration.ts

@@ -16,12 +16,15 @@ export class SlackIntegrationService implements S2sMessageHandlable {
 
   crowi!: any;
 
+  configManager!: ConfigManager;
+
   s2sMessagingService!: S2sMessagingService;
 
   lastLoadedAt?: Date;
 
   constructor(crowi) {
     this.crowi = crowi;
+    this.configManager = crowi.configManager;
     this.s2sMessagingService = crowi.s2sMessagingService;
 
     this.initialize();
@@ -70,6 +73,16 @@ export class SlackIntegrationService implements S2sMessageHandlable {
     }
   }
 
+  hasSlackConfig(): boolean {
+    // for legacy util
+    const hasSlackToken = !!this.configManager.getConfig('notification', 'slack:token');
+    const hasSlackIwhUrl = !!this.configManager.getConfig('notification', 'slack:incomingWebhookUrl');
+    // for slackbot
+    const hasSlackbotType = !!this.configManager.getConfig('crowi', 'slackbot:currentBotType');
+
+    return hasSlackToken || hasSlackIwhUrl || hasSlackbotType;
+  }
+
   /**
    * Handle /commands endpoint
    */

+ 0 - 25
packages/app/src/server/service/slack-notification.js

@@ -1,25 +0,0 @@
-import loggerFactory from '~/utils/logger';
-
-const logger = loggerFactory('growi:service:SlackNotification'); // eslint-disable-line no-unused-vars
-/**
- * the service class of SlackNotificationService
- */
-class SlackNotificationService {
-
-  constructor(configManager) {
-    this.configManager = configManager;
-  }
-
-  hasSlackConfig() {
-    // for legacy util
-    const hasSlackToken = !!this.configManager.getConfig('notification', 'slack:token');
-    const hasSlackIwhUrl = !!this.configManager.getConfig('notification', 'slack:incomingWebhookUrl');
-    // for slackbot
-    const hasSlackbotType = !!this.configManager.getConfig('crowi', 'slackbot:currentBotType');
-
-    return hasSlackToken || hasSlackIwhUrl || hasSlackbotType;
-  }
-
-}
-
-module.exports = SlackNotificationService;

+ 3 - 3
packages/app/src/server/service/user-notification/index.js

@@ -25,7 +25,7 @@ class UserNotificationService {
    */
   async fire(page, user, slackChannelsStr, mode, option, comment = {}) {
     const {
-      slackNotificationService, slackLegacy, slack,
+      slackIntegrationService, slackLegacy, slack,
     } = this.crowi;
 
     const opt = option || {};
@@ -33,8 +33,8 @@ class UserNotificationService {
 
     await page.updateSlackChannels(slackChannelsStr);
 
-    if (!slackNotificationService.hasSlackConfig()) {
-      throw new Error('slackNotificationService has not been set up');
+    if (!slackIntegrationService.hasSlackConfig()) {
+      throw new Error('slackIntegrationService has not been set up');
     }
 
     // "dev,slacktest" => [dev,slacktest]