notification.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. {% extends '../layout/admin.html' %}
  2. {% block html_title %}{{ t('Notification settings') }} · {{ path }}{% 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">Submit</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 too complex.
  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:clientId]" class="col-xs-3 control-label">clientId</label>
  109. <div class="col-xs-6">
  110. <input class="form-control" type="text" name="slackSetting[slack:clientId]" value="{{ slackSetting['slack:clientId'] }}">
  111. </div>
  112. </div>
  113. <div class="form-group">
  114. <label for="slackSetting[slack:clientSecret]" class="col-xs-3 control-label">clientSecret</label>
  115. <div class="col-xs-6">
  116. <input class="form-control" type="text" name="slackSetting[slack:clientSecret]" value="{{ slackSetting['slack:clientSecret'] }}">
  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">Submit</button>
  122. </div>
  123. </div>
  124. </fieldset>
  125. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  126. </form>
  127. {% if hasSlackWebClientConfig %}
  128. <div class="text-center">
  129. {% if hasSlackToken %}
  130. <p>Crowi and Slack is already <strong>connected</strong>. You can re-connect to refresh and overwirte the token with your Slack account.</p>
  131. <a class="btn btn-warning btn-rounded" href="/admin/notification/slackSetting/disconnect">
  132. <i class="icon-power"></i> Disconnect from Slack
  133. </a>
  134. <a class="btn btn-success btn-outline btn-rounded" href="{{ slackAuthUrl }}" target="_blank">
  135. <i class="icon-login"></i> Reconnect to Slack
  136. </a>
  137. {% else %}
  138. <p>Slack clientId and clientSecret is configured. Now, you can connect with Slack.</p>
  139. <a class="btn btn-primary btn-outline2 btn-rounded" href="{{ slackAuthUrl }}" target="_blank">
  140. <i class="icon-login"></i> Connect to Slack
  141. </a>
  142. {% endif %}
  143. </div>
  144. {% endif %}
  145. {# {% if not hasSlackWebClientConfig %} #}
  146. <hr>
  147. <h3>
  148. <i class="icon-question" aria-hidden="true"></i>
  149. <a href="#collapseHelpForApp" data-toggle="collapse">How to configure Slack App?</a>
  150. </h3>
  151. <ol id="collapseHelpForApp" class="collapse">
  152. <li>
  153. Register Slack App
  154. <ol>
  155. <li>
  156. Create App from <a href="https://api.slack.com/applications/new">this link</a>, and fill the form out as below:
  157. <dl class="dl-horizontal">
  158. <dt>App Name</dt> <dd><code>growi</code> </dd>
  159. <dt>Development Slack Workspace</dt> <dd>Select the workspace you want to notify to.</dd>
  160. </dl>
  161. </li>
  162. <li><strong>Save</strong> it.</li>
  163. </ol>
  164. </li>
  165. <li>
  166. Get App Credentials
  167. <ol>
  168. <li>Go To "Basic Information" page and make a note "Client ID" and "Client Secret".</li>
  169. </ol>
  170. </li>
  171. <li>
  172. Set Redirect URLs
  173. <ol>
  174. <li>Go to "OAuth &amp; Permissions" page.</li>
  175. <li>Add <code><script>document.write(location.origin);</script>/admin/notification/slackAuth</code> .</li>
  176. <li>Don't forget to <strong>save</strong>.</li>
  177. </ol>
  178. </li>
  179. <li>
  180. Set Permission Scopes to the App
  181. <ol>
  182. <li>Go to "OAuth &amp; Permissions" page.</li>
  183. <li>Add "Send messages as GROWI"(<code>chat:write:bot</code>).</li>
  184. <li>Don't forget to <strong>save</strong>.</li>
  185. </ol>
  186. </li>
  187. <li>
  188. Create a bot user
  189. <ol>
  190. <li>Go to "Bot Users" page and add.</li>
  191. </ol>
  192. </li>
  193. <li>
  194. Install the app
  195. <ol>
  196. <li>Go to "Install App to Your Workspace" page and install.</li>
  197. </ol>
  198. </li>
  199. <li>
  200. (At Workspace) Approve the app
  201. <ol>
  202. <li>Go to the management Apps page for the workspace you installed the app and approve "growi".</li>
  203. </ol>
  204. </li>
  205. <li>
  206. (At Workspace) Invite the bot to your workspace
  207. <ol>
  208. <li>Invite the user you created in <code>4. Add a bot user</code> to the channel you notify to.</li>
  209. </ol>
  210. </li>
  211. <li>
  212. (At GROWI admin page) Input "clientId" and "clientSecret" and submit on this page.
  213. </li>
  214. <li>
  215. (At GROWI admin page) Click "Connect to Slack" button to start OAuth process.
  216. </li>
  217. </ol>
  218. {# {% endif %} #}
  219. </div><!-- /#slack-app -->
  220. </div><!-- /.tab-content -->
  221. <hr>
  222. <h4>Default Notification Settings for Patterns</h4>
  223. <table class="table table-bordered">
  224. <thead>
  225. <th>Pattern</th>
  226. <th>Channel</th>
  227. <th>Operation</th>
  228. </thead>
  229. <tbody class="admin-notif-list">
  230. <form id="slackNotificationForm">
  231. <tr>
  232. <td>
  233. <input class="form-control" type="text" name="pathPattern" value="" placeholder="e.g. /projects/xxx/MTG/*">
  234. <p class="help-block">
  235. Path name of wiki. Pattern expression with <code>*</code> can be used.
  236. </p>
  237. </td>
  238. <td>
  239. <input class="form-control form-inline" type="text" name="channel" value="" placeholder="e.g. project-xxx">
  240. <p class="help-block">
  241. Slack channel name. Without <code>#</code>.
  242. </p>
  243. </td>
  244. <td>
  245. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  246. <input type="submit" value="Add" class="btn btn-primary">
  247. </td>
  248. </tr>
  249. </form>
  250. {% for notif in settings %}
  251. <tr class="admin-notif-row" data-updatepost-id="{{ notif._id.toString() }}">
  252. <td>
  253. {{ notif.pathPattern }}
  254. </td>
  255. <td>
  256. {{ notif.channel }}
  257. </td>
  258. <td>
  259. <form class="admin-remove-updatepost">
  260. <input type="hidden" name="id" value="{{ notif._id.toString() }}">
  261. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  262. <input type="submit" value="Delete" class="btn btn-default">
  263. </form>
  264. </td>
  265. </tr>
  266. {% endfor %}
  267. </tbody>
  268. </table>
  269. </div>
  270. </div>
  271. <script>
  272. window.addEventListener('load', function(e) {
  273. // hash on page
  274. if (location.hash) {
  275. if (location.hash == '#slack-app') {
  276. activateTab('slack-app');
  277. }
  278. }
  279. });
  280. function activateTab(tab){
  281. $('.nav-tabs a[href="#' + tab + '"]').tab('show');
  282. };
  283. </script>
  284. </div>
  285. {% endblock content_main %}
  286. {% block content_footer %}
  287. {% endblock content_footer %}