sou 7 лет назад
Родитель
Сommit
a4904b85dd
3 измененных файлов с 25 добавлено и 17 удалено
  1. 4 1
      lib/form/comment.js
  2. 17 16
      lib/routes/comment.js
  3. 4 0
      resource/js/components/PageComment/CommentForm.js

+ 4 - 1
lib/form/comment.js

@@ -8,5 +8,8 @@ module.exports = form(
   field('commentForm.revision_id').trim().required(),
   field('commentForm.revision_id').trim().required(),
   field('commentForm.comment').trim().required(),
   field('commentForm.comment').trim().required(),
   field('commentForm.comment_position').trim().toInt(),
   field('commentForm.comment_position').trim().toInt(),
-  field('commentForm.is_markdown').trim().toBooleanStrict()
+  field('commentForm.is_markdown').trim().toBooleanStrict(),
+
+  field('slackNotificationForm.isNotification').trim().toBooleanStrict(),
+  field('slackNotificationForm.notifSlackChannel').trim(),
 );
 );

+ 17 - 16
lib/routes/comment.js

@@ -52,18 +52,19 @@ module.exports = function(crowi, app) {
    * @apiParam {Number} comment_position=-1 Line number of the comment
    * @apiParam {Number} comment_position=-1 Line number of the comment
    */
    */
   api.add = async function(req, res) {
   api.add = async function(req, res) {
-    const form = req.form.commentForm;
+    const commentForm = req.form.commentForm;
+    const slackNotificationForm = req.form.slackNotificationForm;
 
 
     if (!req.form.isValid) {
     if (!req.form.isValid) {
       // return res.json(ApiResponse.error('Invalid comment.'));
       // return res.json(ApiResponse.error('Invalid comment.'));
       return res.json(ApiResponse.error('コメントを入力してください。'));
       return res.json(ApiResponse.error('コメントを入力してください。'));
     }
     }
 
 
-    const pageId = form.page_id;
-    const revisionId = form.revision_id;
-    const comment = form.comment;
-    const position = form.comment_position || -1;
-    const isMarkdown = form.is_markdown;
+    const pageId = commentForm.page_id;
+    const revisionId = commentForm.revision_id;
+    const comment = commentForm.comment;
+    const position = commentForm.comment_position || -1;
+    const isMarkdown = commentForm.is_markdown;
 
 
     const createdComment = await Comment.create(pageId, req.user._id, revisionId, comment, position, isMarkdown)
     const createdComment = await Comment.create(pageId, req.user._id, revisionId, comment, position, isMarkdown)
       .catch(function(err) {
       .catch(function(err) {
@@ -77,16 +78,16 @@ module.exports = function(crowi, app) {
     });
     });
 
 
     // slack notification
     // slack notification
-    // if (form.slackOn) {
-    const slackNotify = new slack(crowi);
-    const user = await User.findUserByUsername(req.user.username);
-    const path = page.path;
-    // const channels = form.channel;
-    const channels = 'general';
-    channels.split(',').map(function(chan) {
-      slackNotify.postComment(createdComment, user, chan, path);
-    });
-    // }
+    if (slackNotificationForm.isNotification) {
+      const slackNotify = new slack(crowi);
+      const user = await User.findUserByUsername(req.user.username);
+      const path = page.path;
+      const channels = slackNotificationForm.notifSlackChannel;
+
+      channels.split(',').map(function(chan) {
+        slackNotify.postComment(createdComment, user, chan, path);
+      });
+    }
 
 
     return res.json(ApiResponse.success({comment: createdComment}));
     return res.json(ApiResponse.success({comment: createdComment}));
   };
   };

+ 4 - 0
resource/js/components/PageComment/CommentForm.js

@@ -127,6 +127,10 @@ export default class CommentForm extends React.Component {
         page_id: this.props.pageId,
         page_id: this.props.pageId,
         revision_id: this.props.revisionId,
         revision_id: this.props.revisionId,
         is_markdown: this.state.isMarkdown,
         is_markdown: this.state.isMarkdown,
+      },
+      slackNotificationForm: {
+        isNotification: this.state.isNotification,
+        notifSlackChannel: this.state.notifSlackChannel,
       }
       }
     })
     })
       .then((res) => {
       .then((res) => {