notification.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. {% extends '../layout/admin.html' %}
  2. {% block html_title %}通知設定 · {{ path }}{% endblock %}
  3. {% block content_head %}
  4. <div class="header-wrap">
  5. <header id="page-header">
  6. <h1 class="title" id="">通知設定</h1>
  7. </header>
  8. </div>
  9. {% endblock %}
  10. {% block content_main %}
  11. <div class="content-main">
  12. <div class="row">
  13. <div class="col-md-3">
  14. {% include './widget/menu.html' with {current: 'notification'} %}
  15. </div>
  16. <div class="col-md-9">
  17. {% set smessage = req.flash('successMessage') %}
  18. {% if smessage.length %}
  19. <div class="alert alert-success">
  20. {% for e in smessage %}
  21. {{ e }}<br>
  22. {% endfor %}
  23. </div>
  24. {% endif %}
  25. {% set emessage = req.flash('errorMessage') %}
  26. {% if emessage.length %}
  27. <div class="alert alert-danger">
  28. {% for e in emessage %}
  29. {{ e }}<br>
  30. {% endfor %}
  31. </div>
  32. {% endif %}
  33. <ul class="nav nav-tabs" role="tablist">
  34. <li class="active">
  35. <a href="#slack-app" data-toggle="tab" role="tab"><i class="fa fa-slack"></i> Slack App</a>
  36. </li>
  37. <li role="tab">
  38. <a href="#slack-incoming-webhooks" data-toggle="tab" role="tab"><i class="fa fa-slack"></i> Slack Incoming Webhooks</a>
  39. </li>
  40. </ul>
  41. <div class="tab-content">
  42. <div id="slack-app" class="tab-pane active" role="tabpanel" >
  43. <form action="/admin/notification/slackSetting" method="post" class="form-horizontal" id="appSettingForm" role="form">
  44. <fieldset>
  45. <legend>Slack App Configuration</legend>
  46. <p class="well text-warning">
  47. <i class="fa fa-warning"></i> NOT RECOMMENDED
  48. <br><br>
  49. This is the way that compatible with the official Crowi,<br>
  50. but not recommended in crowi-plus because it is too complex.
  51. <br><br>
  52. Please use <a href="#slack-incoming-webhooks" data-toggle="tab" onclick="activateTab('slack-incoming-webhooks')">Slack incomming webhooks Configuration</a> instead.
  53. </p>
  54. <div class="form-group">
  55. <label for="slackSetting[slack:clientId]" class="col-xs-3 control-label">clientId</label>
  56. <div class="col-xs-6">
  57. <input class="form-control" type="text" name="slackSetting[slack:clientId]" value="{{ slackSetting['slack:clientId'] }}">
  58. </div>
  59. </div>
  60. <div class="form-group">
  61. <label for="slackSetting[slack:clientSecret]" class="col-xs-3 control-label">clientSecret</label>
  62. <div class="col-xs-6">
  63. <input class="form-control" type="text" name="slackSetting[slack:clientSecret]" value="{{ slackSetting['slack:clientSecret'] }}">
  64. </div>
  65. </div>
  66. <div class="form-group">
  67. <div class="col-xs-offset-3 col-xs-6">
  68. <button type="submit" class="btn btn-primary">Submit</button>
  69. </div>
  70. </div>
  71. </fieldset>
  72. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  73. </form>
  74. {% if hasSlackConfig %}
  75. <div class="text-center">
  76. {% if hasSlackToken %}
  77. <p>Crowi and Slack is already <strong>connected</strong>. You can re-connect to refresh and overwirte the token with your Slack account.</p>
  78. <a class="btn btn-warning" href="/admin/notification/slackSetting/disconnect">
  79. <i class="fa fa-slack"></i> Disconnect from Slack
  80. </a>
  81. <a class="btn btn-default" href="{{ slackAuthUrl }}" target="_blank">
  82. <i class="fa fa-slack"></i> Reconnect to Slack
  83. </a>
  84. {% else %}
  85. <p>Slack clientId and clientSecret is configured. Now, you can connect with Slack.</p>
  86. <a class="btn btn-primary" href="{{ slackAuthUrl }}" target="_blank">
  87. <i class="fa fa-slack"></i> Connect to Slack
  88. </a>
  89. {% endif %}
  90. </div>
  91. {% endif %}
  92. {# {% if not hasSlackConfig %} #}
  93. <hr>
  94. <h3>
  95. <i class="fa fa-question-circle" aria-hidden="true"></i>
  96. <a href="#collapseHelpForApp" data-toggle="collapse">How to configure Slack App?</a>
  97. </h3>
  98. <ol id="collapseHelpForApp" class="collapse">
  99. <li>
  100. Register Slack App
  101. <ol>
  102. <li>
  103. Create App from <a href="https://api.slack.com/applications/new">this link</a>, and fill the form out as below:
  104. <dl class="dl-horizontal">
  105. <dt>App Name</dt> <dd><code>crowi-plus</code> </dd>
  106. <dt>Development Slack Team</dt> <dd>Select the team you want to notify to.</dd>
  107. </dl>
  108. </li>
  109. <li><strong>Save</strong> it.</li>
  110. </ol>
  111. </li>
  112. <li>
  113. Get App Credentials
  114. <ol>
  115. <li>Go To "Basic Information" page and make a note "Client ID" and "Client Secret".</li>
  116. </ol>
  117. </li>
  118. <li>
  119. Set Redirect URLs
  120. <ol>
  121. <li>Go to "OAuth &amp; Permissions" page.</li>
  122. <li>Add <code><script>document.write(location.origin);</script>/admin/notification/slackAuth</code> .</li>
  123. <li>Don't forget to <strong>save</strong>.</li>
  124. </ol>
  125. </li>
  126. <li>
  127. Set Permission Scopes to the App
  128. <ol>
  129. <li>Go to "OAuth &amp; Permissions" page and add "Send messages as crowi-plus"(<code>chat:write:bot</code>).</li>
  130. <li>Don't forget to <strong>save</strong>.</li>
  131. </ol>
  132. </li>
  133. <li>
  134. Create a bot user
  135. <ol>
  136. <li>Go to "Bot Users" page and add.</li>
  137. </ol>
  138. </li>
  139. <li>
  140. Install the app
  141. <ol>
  142. <li>Go to "Install App to Your Team" page and install.</li>
  143. </ol>
  144. </li>
  145. <li>
  146. (At Team) Approve the app
  147. <ol>
  148. <li>Go to the management Apps page for the team you installed the app and approve crowi-plus.</li>
  149. </ol>
  150. </li>
  151. <li>
  152. (At Team) Invite the bot to your team
  153. <ol>
  154. <li>Invite the user you created in <code>4. Add a bot user</code> to the channel you notify to.</li>
  155. </ol>
  156. </li>
  157. <li>
  158. (At crowi-plus) Input "clientId" and "clientSecret" and submit on this page.
  159. </li>
  160. <li>
  161. (At crowi-plus) Click "Connect to Slack" button to start OAuth process.
  162. </li>
  163. </ol>
  164. {# {% endif %} #}
  165. </div><!-- /#slack-app -->
  166. <div id="slack-incoming-webhooks" class="tab-pane" role="tabpanel">
  167. <form action="/admin/notification/slackIwhSetting" method="post" class="form-horizontal" id="appSettingForm" role="form">
  168. <fieldset>
  169. <legend>Slack Incoming Webhooks Configuration</legend>
  170. <div class="form-group">
  171. <label for="slackIwhSetting[slack:incomingWebhookUrl]" class="col-xs-3 control-label">Webhook URL</label>
  172. <div class="col-xs-6">
  173. <input class="form-control" type="text" name="slackIwhSetting[slack:incomingWebhookUrl]" value="{{ slackSetting['slack:incomingWebhookUrl'] }}">
  174. </div>
  175. </div>
  176. <div class="form-group">
  177. <label for="slackIwhSetting[slack:isIncomingWebhookPrioritized]" class="col-xs-3 control-label"></label>
  178. <div class="col-xs-6">
  179. <input type="checkbox" name="slackIwhSetting[slack:isIncomingWebhookPrioritized]" value="1"
  180. {% if slackSetting['slack:isIncomingWebhookPrioritized'] %}checked{% endif %}>
  181. Prioritize Incoming Webhook than Slack App
  182. </div>
  183. </div>
  184. <div class="form-group">
  185. <div class="col-xs-offset-3 col-xs-6">
  186. <button type="submit" class="btn btn-primary">Submit</button>
  187. </div>
  188. </div>
  189. </fieldset>
  190. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  191. </form>
  192. <hr>
  193. <h3>
  194. <i class="fa fa-question-circle" aria-hidden="true"></i>
  195. <a href="#collapseHelpForIwh" data-toggle="collapse">How to configure Incoming Webhooks?</a>
  196. </h3>
  197. <ol id="collapseHelpForIwh" class="collapse">
  198. <li>
  199. (At Team) Add a hook
  200. <ol>
  201. <li>Go to <a href="https://slack.com/services/new/incoming-webhook">Incoming Webhooks Configuration page</a>.</li>
  202. <li>Choose the default channel to post.</li>
  203. <li>Add.</li>
  204. </ol>
  205. </li>
  206. </ol>
  207. </div><!-- /#slack-incoming-webhooks -->
  208. </div><!-- /.tab-content -->
  209. <hr>
  210. <h4>Default Notification Settings for Patterns</h4>
  211. <table class="table table-bordered">
  212. <thead>
  213. <th>Pattern</th>
  214. <th>Channel</th>
  215. <th>Operation</th>
  216. </thead>
  217. <tbody class="admin-notif-list">
  218. <form id="slackNotificationForm">
  219. <tr>
  220. <td>
  221. <input class="form-control" type="text" name="pathPattern" value="" placeholder="e.g. /projects/xxx/MTG/*">
  222. <p class="help-block">
  223. Path name of wiki. Pattern expression with <code>*</code> can be used.
  224. </p>
  225. </td>
  226. <td>
  227. <input class="form-control form-inline" type="text" name="channel" value="" placeholder="e.g. project-xxx">
  228. <p class="help-block">
  229. Slack channel name. Without <code>#</code>.
  230. </p>
  231. </td>
  232. <td>
  233. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  234. <input type="submit" value="Add" class="btn btn-primary">
  235. </td>
  236. </tr>
  237. </form>
  238. {% for notif in settings %}
  239. <tr class="admin-notif-row" data-updatepost-id="{{ notif._id.toString() }}">
  240. <td>
  241. {{ notif.pathPattern }}
  242. </td>
  243. <td>
  244. {{ notif.channel }}
  245. </td>
  246. <td>
  247. <form class="admin-remove-updatepost">
  248. <input type="hidden" name="id" value="{{ notif._id.toString() }}">
  249. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  250. <input type="submit" value="Delete" class="btn btn-default">
  251. </form>
  252. </td>
  253. </tr>
  254. {% endfor %}
  255. </tbody>
  256. </table>
  257. </div>
  258. </div>
  259. <script>
  260. function activateTab(tab){
  261. $('.nav-tabs a[href="#' + tab + '"]').tab('show');
  262. };
  263. </script>
  264. </div>
  265. {% endblock content_main %}
  266. {% block content_footer %}
  267. {% endblock content_footer %}