notification.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 hasSlackWebClientConfig %}
  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 hasSlackWebClientConfig %} #}
  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 Workspace</dt> <dd>Select the workspace 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.</li>
  130. <li>Add "Send messages as crowi-plus"(<code>chat:write:bot</code>).</li>
  131. <li>Don't forget to <strong>save</strong>.</li>
  132. </ol>
  133. </li>
  134. <li>
  135. Create a bot user
  136. <ol>
  137. <li>Go to "Bot Users" page and add.</li>
  138. </ol>
  139. </li>
  140. <li>
  141. Install the app
  142. <ol>
  143. <li>Go to "Install App to Your Workspace" page and install.</li>
  144. </ol>
  145. </li>
  146. <li>
  147. (At Workspace) Approve the app
  148. <ol>
  149. <li>Go to the management Apps page for the workspace you installed the app and approve crowi-plus.</li>
  150. </ol>
  151. </li>
  152. <li>
  153. (At Workspace) Invite the bot to your workspace
  154. <ol>
  155. <li>Invite the user you created in <code>4. Add a bot user</code> to the channel you notify to.</li>
  156. </ol>
  157. </li>
  158. <li>
  159. (At crowi-plus) Input "clientId" and "clientSecret" and submit on this page.
  160. </li>
  161. <li>
  162. (At crowi-plus) Click "Connect to Slack" button to start OAuth process.
  163. </li>
  164. </ol>
  165. {# {% endif %} #}
  166. </div><!-- /#slack-app -->
  167. <div id="slack-incoming-webhooks" class="tab-pane" role="tabpanel">
  168. <form action="/admin/notification/slackIwhSetting" method="post" class="form-horizontal" id="appSettingForm" role="form">
  169. <fieldset>
  170. <legend>Slack Incoming Webhooks Configuration</legend>
  171. <div class="form-group">
  172. <label for="slackIwhSetting[slack:incomingWebhookUrl]" class="col-xs-3 control-label">Webhook URL</label>
  173. <div class="col-xs-9">
  174. <input class="form-control" type="text" name="slackIwhSetting[slack:incomingWebhookUrl]" value="{{ slackSetting['slack:incomingWebhookUrl'] }}">
  175. </div>
  176. </div>
  177. <div class="form-group">
  178. <label for="slackIwhSetting[slack:isIncomingWebhookPrioritized]" class="col-xs-3 control-label"></label>
  179. <div class="col-xs-9">
  180. <input type="checkbox" name="slackIwhSetting[slack:isIncomingWebhookPrioritized]" value="1"
  181. {% if slackSetting['slack:isIncomingWebhookPrioritized'] %}checked{% endif %}>
  182. Prioritize Incoming Webhook than Slack App
  183. <p class="help-block">Check this option and crowi-plus use Incoming Webhooks even if Slack App settings are enabled.</p>
  184. </div>
  185. </div>
  186. <div class="form-group">
  187. <div class="col-xs-offset-3 col-xs-6">
  188. <button type="submit" class="btn btn-primary">Submit</button>
  189. </div>
  190. </div>
  191. </fieldset>
  192. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  193. </form>
  194. <hr>
  195. <h3>
  196. <i class="fa fa-question-circle" aria-hidden="true"></i>
  197. <a href="#collapseHelpForIwh" data-toggle="collapse">How to configure Incoming Webhooks?</a>
  198. </h3>
  199. <ol id="collapseHelpForIwh" class="collapse">
  200. <li>
  201. (At Workspace) Add a hook
  202. <ol>
  203. <li>Go to <a href="https://slack.com/services/new/incoming-webhook">Incoming Webhooks Configuration page</a>.</li>
  204. <li>Choose the default channel to post.</li>
  205. <li>Add.</li>
  206. </ol>
  207. </li>
  208. <li>
  209. (At crowi-plus) Set Webhook URL
  210. <ol>
  211. <li>Input "Webhook URL" and submit on this page.</li>
  212. </ol>
  213. </li>
  214. </ol>
  215. </div><!-- /#slack-incoming-webhooks -->
  216. </div><!-- /.tab-content -->
  217. <hr>
  218. <h4>Default Notification Settings for Patterns</h4>
  219. <table class="table table-bordered">
  220. <thead>
  221. <th>Pattern</th>
  222. <th>Channel</th>
  223. <th>Operation</th>
  224. </thead>
  225. <tbody class="admin-notif-list">
  226. <form id="slackNotificationForm">
  227. <tr>
  228. <td>
  229. <input class="form-control" type="text" name="pathPattern" value="" placeholder="e.g. /projects/xxx/MTG/*">
  230. <p class="help-block">
  231. Path name of wiki. Pattern expression with <code>*</code> can be used.
  232. </p>
  233. </td>
  234. <td>
  235. <input class="form-control form-inline" type="text" name="channel" value="" placeholder="e.g. project-xxx">
  236. <p class="help-block">
  237. Slack channel name. Without <code>#</code>.
  238. </p>
  239. </td>
  240. <td>
  241. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  242. <input type="submit" value="Add" class="btn btn-primary">
  243. </td>
  244. </tr>
  245. </form>
  246. {% for notif in settings %}
  247. <tr class="admin-notif-row" data-updatepost-id="{{ notif._id.toString() }}">
  248. <td>
  249. {{ notif.pathPattern }}
  250. </td>
  251. <td>
  252. {{ notif.channel }}
  253. </td>
  254. <td>
  255. <form class="admin-remove-updatepost">
  256. <input type="hidden" name="id" value="{{ notif._id.toString() }}">
  257. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  258. <input type="submit" value="Delete" class="btn btn-default">
  259. </form>
  260. </td>
  261. </tr>
  262. {% endfor %}
  263. </tbody>
  264. </table>
  265. </div>
  266. </div>
  267. <script>
  268. window.addEventListener('load', function(e) {
  269. // hash on page
  270. if (location.hash) {
  271. if (location.hash == '#slack-incoming-webhooks') {
  272. activateTab('slack-incoming-webhooks');
  273. }
  274. }
  275. });
  276. function activateTab(tab){
  277. $('.nav-tabs a[href="#' + tab + '"]').tab('show');
  278. };
  279. </script>
  280. </div>
  281. {% endblock content_main %}
  282. {% block content_footer %}
  283. {% endblock content_footer %}