notification.html 11 KB

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