notification.html 12 KB

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