notification.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. {% extends '../layout/admin.html' %}
  2. {% block html_title %}{{ customTitle(t('Notification settings')) }}{% endblock %}
  3. {% block content_header %}
  4. <div class="header-wrap">
  5. <header id="page-header">
  6. <h1 class="title" id="">{{ t('Notification settings') }}</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-incoming-webhooks" data-toggle="tab" role="tab"><i class="icon-settings"></i> Slack Incoming Webhooks</a>
  36. </li>
  37. <li role="tab">
  38. <a href="#slack-app" data-toggle="tab" role="tab"><i class="icon-settings"></i> Slack App</a>
  39. </li>
  40. </ul>
  41. <div class="tab-content m-t-15">
  42. <div id="slack-incoming-webhooks" class="tab-pane active" role="tabpanel">
  43. <form action="/admin/notification/slackIwhSetting" method="post" class="form-horizontal" id="appSettingForm" role="form">
  44. <fieldset>
  45. <legend>Slack Incoming Webhooks Configuration</legend>
  46. <div class="form-group">
  47. <label for="slackIwhSetting[slack:incomingWebhookUrl]" class="col-xs-3 control-label">Webhook URL</label>
  48. <div class="col-xs-9">
  49. <input class="form-control" type="text" name="slackIwhSetting[slack:incomingWebhookUrl]" value="{{ slackSetting['slack:incomingWebhookUrl'] }}">
  50. </div>
  51. </div>
  52. <div class="form-group">
  53. <label for="slackIwhSetting[slack:isIncomingWebhookPrioritized]" class="col-xs-3 control-label"></label>
  54. <div class="col-xs-9">
  55. <div class="checkbox checkbox-info">
  56. <input type="checkbox" id ="cbPrioritizeIWH" name="slackIwhSetting[slack:isIncomingWebhookPrioritized]" value="1"
  57. {% if slackSetting['slack:isIncomingWebhookPrioritized'] %}checked{% endif %}>
  58. <label for="cbPrioritizeIWH">
  59. Prioritize Incoming Webhook than Slack App
  60. </label>
  61. </div>
  62. <p class="help-block">Check this option and GROWI use Incoming Webhooks even if Slack App settings are enabled.</p>
  63. </div>
  64. </div>
  65. <div class="form-group">
  66. <div class="col-xs-offset-3 col-xs-6">
  67. <button type="submit" class="btn btn-primary">Save</button>
  68. </div>
  69. </div>
  70. </fieldset>
  71. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  72. </form>
  73. <hr>
  74. <h3>
  75. <i class="icon-question" aria-hidden="true"></i>
  76. <a href="#collapseHelpForIwh" data-toggle="collapse">How to configure Incoming Webhooks?</a>
  77. </h3>
  78. <ol id="collapseHelpForIwh" class="collapse">
  79. <li>
  80. (At Workspace) Add a hook
  81. <ol>
  82. <li>Go to <a href="https://slack.com/services/new/incoming-webhook">Incoming Webhooks Configuration page</a>.</li>
  83. <li>Choose the default channel to post.</li>
  84. <li>Add.</li>
  85. </ol>
  86. </li>
  87. <li>
  88. (At GROWI admin page) Set Webhook URL
  89. <ol>
  90. <li>Input "Webhook URL" and submit on this page.</li>
  91. </ol>
  92. </li>
  93. </ol>
  94. </div><!-- /#slack-incoming-webhooks -->
  95. <div id="slack-app" class="tab-pane" role="tabpanel" >
  96. <form action="/admin/notification/slackSetting" method="post" class="form-horizontal" id="appSettingForm" role="form">
  97. <fieldset>
  98. <legend>Slack App Configuration</legend>
  99. <p class="well">
  100. <i class="icon-fw icon-exclamation text-danger"></i><span class="text-danger">NOT RECOMMENDED</span>
  101. <br><br>
  102. This is the way that compatible with Crowi,<br>
  103. but not recommended in GROWI because it is <strong>too complex</strong>.
  104. <br><br>
  105. Please use <a href="#slack-incoming-webhooks" data-toggle="tab" onclick="activateTab('slack-incoming-webhooks')">Slack incomming webhooks Configuration</a> instead.
  106. </p>
  107. <div class="form-group">
  108. <label for="slackSetting[slack:token]" class="col-xs-3 control-label">OAuth Access Token</label>
  109. <div class="col-xs-6">
  110. <input class="form-control" type="text" name="slackSetting[slack:token]" value="{{ slackSetting['slack:token'] || '' }}">
  111. </div>
  112. </div>
  113. <div class="form-group">
  114. <div class="col-xs-offset-3 col-xs-6">
  115. <button type="submit" class="btn btn-primary">Save</button>
  116. </div>
  117. </div>
  118. </fieldset>
  119. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  120. </form>
  121. <hr>
  122. <h3>
  123. <i class="icon-question" aria-hidden="true"></i>
  124. <a href="#collapseHelpForApp" data-toggle="collapse">How to configure Slack App?</a>
  125. </h3>
  126. <ol id="collapseHelpForApp" class="collapse">
  127. <li>
  128. Register Slack App
  129. <ol>
  130. <li>
  131. Create App from <a href="https://api.slack.com/applications/new">this link</a>, and fill the form out as below:
  132. <dl class="dl-horizontal">
  133. <dt>App Name</dt> <dd><code>growi</code> </dd>
  134. <dt>Development Slack Workspace</dt> <dd>Select the workspace you want to notify to.</dd>
  135. </dl>
  136. </li>
  137. <li><strong>Save</strong> it.</li>
  138. </ol>
  139. </li>
  140. <li>
  141. Set Permission Scopes to the App
  142. <ol>
  143. <li>Go to "OAuth &amp; Permissions" page.</li>
  144. <li>Add "Send messages as GROWI"(<code>chat:write:bot</code>).</li>
  145. <li>Don't forget to <strong>save</strong>.</li>
  146. </ol>
  147. </li>
  148. <li>
  149. Create a bot user
  150. <ol>
  151. <li>Go to "Bot Users" page and add.</li>
  152. </ol>
  153. </li>
  154. <li>
  155. Install the app
  156. <ol>
  157. <li>Go to "Install App to Your Workspace" page and install.</li>
  158. <li>Go to "OAuth &amp; Permissions" page and copy <code>OAuth Access Token</code>.</li>
  159. </ol>
  160. </li>
  161. <li>
  162. (At this page) Set OAuth Access Token
  163. <ol>
  164. <li>Input "OAuth Access Token".</li>
  165. <li>Don't forget to <strong>save</strong>.</li>
  166. </ol>
  167. </li>
  168. </ol>
  169. </div><!-- /#slack-app -->
  170. </div><!-- /.tab-content -->
  171. <hr>
  172. <h4>Default Notification Settings for Patterns</h4>
  173. <table class="table table-bordered">
  174. <thead>
  175. <th>Pattern</th>
  176. <th>Channel</th>
  177. <th>Operation</th>
  178. </thead>
  179. <tbody class="admin-notif-list">
  180. <form id="slackNotificationForm">
  181. <tr>
  182. <td>
  183. <input class="form-control" type="text" name="pathPattern" value="" placeholder="e.g. /projects/xxx/MTG/*">
  184. <p class="help-block">
  185. Path name of wiki. Pattern expression with <code>*</code> can be used.
  186. </p>
  187. </td>
  188. <td>
  189. <input class="form-control form-inline" type="text" name="channel" value="" placeholder="e.g. project-xxx">
  190. <p class="help-block">
  191. Slack channel name. Without <code>#</code>.
  192. </p>
  193. </td>
  194. <td>
  195. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  196. <input type="submit" value="Add" class="btn btn-primary">
  197. </td>
  198. </tr>
  199. </form>
  200. {% for notif in settings %}
  201. <tr class="admin-notif-row" data-updatepost-id="{{ notif._id.toString() }}">
  202. <td>
  203. {{ notif.pathPattern }}
  204. </td>
  205. <td>
  206. {{ notif.channel }}
  207. </td>
  208. <td>
  209. <form class="admin-remove-updatepost">
  210. <input type="hidden" name="id" value="{{ notif._id.toString() }}">
  211. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  212. <input type="submit" value="Delete" class="btn btn-default">
  213. </form>
  214. </td>
  215. </tr>
  216. {% endfor %}
  217. </tbody>
  218. </table>
  219. </div>
  220. </div>
  221. <script>
  222. window.addEventListener('load', function(e) {
  223. // hash on page
  224. if (location.hash) {
  225. if (location.hash == '#slack-app') {
  226. activateTab('slack-app');
  227. }
  228. }
  229. });
  230. function activateTab(tab){
  231. $('.nav-tabs a[href="#' + tab + '"]').tab('show');
  232. };
  233. </script>
  234. </div>
  235. {% endblock content_main %}
  236. {% block content_footer %}
  237. {% endblock content_footer %}