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

refactor `slack.hasSlackConfig`

* `hasSlackConfig` -> enable slack whatever the way
* `hasSlackAppConfig` -> clientId and clientSecret have been inputted
Yuki Takei 8 лет назад
Родитель
Сommit
b9ae514b26
4 измененных файлов с 19 добавлено и 10 удалено
  1. 6 1
      lib/models/config.js
  2. 10 6
      lib/routes/admin.js
  3. 1 1
      lib/util/slack.js
  4. 2 2
      lib/views/admin/notification.html

+ 6 - 1
lib/models/config.js

@@ -338,6 +338,11 @@ module.exports = function(crowi) {
   };
 
   configSchema.statics.hasSlackConfig = function(config)
+  {
+    return Config.hasSlackAppConfig(config) || Config.hasSlackIwhUrl(config);
+  };
+
+  configSchema.statics.hasSlackAppConfig = function(config)
   {
     if (!config.notification) {
       return false;
@@ -371,7 +376,7 @@ module.exports = function(crowi) {
 
   configSchema.statics.hasSlackToken = function(config)
   {
-    if (!this.hasSlackConfig(config)) {
+    if (!this.hasSlackAppConfig(config)) {
       return false;
     }
 

+ 10 - 6
lib/routes/admin.js

@@ -132,22 +132,23 @@ module.exports = function(crowi, app) {
     var config = crowi.getConfig();
     var UpdatePost = crowi.model('UpdatePost');
     var slackSetting = Config.setupCofigFormData('notification', config);
-    var hasSlackConfig = Config.hasSlackConfig(config);
+    var hasSlackAppConfig = Config.hasSlackAppConfig(config);
     var hasSlackIwhUrl = Config.hasSlackIwhUrl(config);
     var hasSlackToken = Config.hasSlackToken(config);
     var slack = crowi.slack;
     var slackAuthUrl = '';
 
-    if (!Config.hasSlackConfig(req.config)) {
+    if (!Config.hasSlackAppConfig(req.config)) {
       slackSetting['slack:clientId'] = '';
       slackSetting['slack:clientSecret'] = '';
     }
+    else {
+      slackAuthUrl = slack.getAuthorizeURL();
+    }
     if (!Config.hasSlackIwhUrl(req.config)) {
       slackSetting['slack:incomingWebhookUrl'] = '';
     }
 
-    slackAuthUrl = slack.getAuthorizeURL();
-
     if (req.session.slackSetting) {
       slackSetting = req.session.slackSetting;
       req.session.slackSetting = null;
@@ -158,7 +159,7 @@ module.exports = function(crowi, app) {
       return res.render('admin/notification', {
         settings,
         slackSetting,
-        hasSlackConfig,
+        hasSlackAppConfig,
         hasSlackIwhUrl,
         hasSlackToken,
         slackAuthUrl
@@ -177,6 +178,7 @@ module.exports = function(crowi, app) {
         req.flash('successMessage', ['Successfully Updated!']);
         req.session.slackSetting = null;
 
+        // Re-setup
         crowi.setupSlack().then(function() {
           return res.redirect('/admin/notification');
         });
@@ -192,7 +194,7 @@ module.exports = function(crowi, app) {
     var code = req.query.code;
     var config = crowi.getConfig();
 
-    if (!code || !Config.hasSlackConfig(req.config)) {
+    if (!code || !Config.hasSlackAppConfig(req.config)) {
       return res.redirect('/admin/notification');
     }
 
@@ -257,6 +259,8 @@ module.exports = function(crowi, app) {
       Config.updateNamespaceByArray('notification', slackIwhSetting, function(err, config) {
         Config.updateConfigCache('notification', config);
         req.flash('successMessage', ['Successfully Updated!']);
+
+        // Re-setup
         crowi.setupSlack().then(function() {
           return res.redirect('/admin/notification#slack-incoming-webhooks');
         });

+ 1 - 1
lib/util/slack.js

@@ -85,7 +85,7 @@ module.exports = function(crowi) {
   {
     var config = crowi.getConfig();
 
-    if (Config.hasSlackConfig(config)) {
+    if (Config.hasSlackAppConfig(config)) {
       slack.appController = Botkit.slackbot({debug: isDebugSlackbot});
       slack.appController.configureSlackApp({
         clientId: config.notification['slack:clientId'],

+ 2 - 2
lib/views/admin/notification.html

@@ -84,7 +84,7 @@
             <input type="hidden" name="_csrf" value="{{ csrf() }}">
           </form>
 
-          {% if hasSlackConfig %}
+          {% if hasSlackAppConfig %}
           <div class="text-center">
             {% if hasSlackToken %}
             <p>Crowi and Slack is already <strong>connected</strong>. You can re-connect to refresh and overwirte the token with your Slack account.</p>
@@ -104,7 +104,7 @@
 
           {% endif %}
 
-          {# {% if not hasSlackConfig %} #}
+          {# {% if not hasSlackAppConfig %} #}
           <hr>
           <h3>
             <i class="fa fa-question-circle" aria-hidden="true"></i>