notification.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. <ul class="nav nav-tabs">
  18. <li class="active"><a href="#slack" data-toggle="tab"><i class="fa fa-slack"></i> Slack App</a></li>
  19. </ul>
  20. <br>
  21. {% set smessage = req.flash('successMessage') %}
  22. {% if smessage.length %}
  23. <div class="alert alert-success">
  24. {% for e in smessage %}
  25. {{ e }}<br>
  26. {% endfor %}
  27. </div>
  28. {% endif %}
  29. {% set emessage = req.flash('errorMessage') %}
  30. {% if emessage.length %}
  31. <div class="alert alert-danger">
  32. {% for e in emessage %}
  33. {{ e }}<br>
  34. {% endfor %}
  35. </div>
  36. {% endif %}
  37. <form action="/admin/notification/slackSetting" method="post" class="form-horizontal" id="appSettingForm" role="form">
  38. <fieldset>
  39. <legend>Slack App Configuration</legend>
  40. <p class="well text-warning">
  41. <i class="fa fa-warning"></i> NOT RECOMMENDED
  42. <br><br>
  43. This is the way that compatible to the official Crowi,<br>
  44. but not recommended in crowi-plus because it is too complex.
  45. <br><br>
  46. Please use <a href="#">(TBD) Slack incomming web hook Configuration</a> instead.
  47. </p>
  48. <div class="form-group">
  49. <label for="slackSetting[slack:clientId]" class="col-xs-3 control-label">clientId</label>
  50. <div class="col-xs-6">
  51. <input class="form-control" type="text" name="slackSetting[slack:clientId]" value="{{ slackSetting['slack:clientId'] }}">
  52. </div>
  53. </div>
  54. <div class="form-group">
  55. <label for="slackSetting[slack:clientSecret]" class="col-xs-3 control-label">clientSecret</label>
  56. <div class="col-xs-6">
  57. <input class="form-control" type="text" name="slackSetting[slack:clientSecret]" value="{{ slackSetting['slack:clientSecret'] }}">
  58. </div>
  59. </div>
  60. <div class="form-group">
  61. <div class="col-xs-offset-3 col-xs-6">
  62. <button type="submit" class="btn btn-primary">Submit</button>
  63. </div>
  64. </div>
  65. </fieldset>
  66. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  67. </form>
  68. {% if hasSlackConfig %}
  69. <div class="text-center">
  70. {% if hasSlackToken %}
  71. <p>Crowi and Slack is already <strong>connected</strong>. You can re-connect to refresh and overwirte the token with your Slack account.</p>
  72. <a class="btn btn-warning" href="/admin/notification/slackSetting/disconnect">
  73. <i class="fa fa-slack"></i> Disconnect from Slack
  74. </a>
  75. <a class="btn btn-default" href="{{ slackAuthUrl }}" target="_blank">
  76. <i class="fa fa-slack"></i> Reconnect to Slack
  77. </a>
  78. {% else %}
  79. <p>Slack clientId and clientSecret is configured. Now, you can connect with Slack.</p>
  80. <a class="btn btn-primary" href="{{ slackAuthUrl }}" target="_blank">
  81. <i class="fa fa-slack"></i> Connect to Slack
  82. </a>
  83. {% endif %}
  84. </div>
  85. <hr>
  86. <h4>Default Notification Settings for Patterns</h4>
  87. <table class="table table-bordered">
  88. <thead>
  89. <th>Pattern</th>
  90. <th>Channel</th>
  91. <th>Operation</th>
  92. </thead>
  93. <tbody class="admin-notif-list">
  94. <form id="slackNotificationForm">
  95. <tr>
  96. <td>
  97. <input class="form-control" type="text" name="pathPattern" value="" placeholder="e.g. /projects/xxx/MTG/*">
  98. <p class="help-block">
  99. Path name of wiki. Pattern expression with <code>*</code> can be used.
  100. </p>
  101. </td>
  102. <td>
  103. <input class="form-control form-inline" type="text" name="channel" value="" placeholder="e.g. project-xxx">
  104. <p class="help-block">
  105. Slack channel name. Without <code>#</code>.
  106. </p>
  107. </td>
  108. <td>
  109. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  110. <input type="submit" value="Add" class="btn btn-primary">
  111. </td>
  112. </tr>
  113. </form>
  114. {% for notif in settings %}
  115. <tr class="admin-notif-row" data-updatepost-id="{{ notif._id.toString() }}">
  116. <td>
  117. {{ notif.pathPattern }}
  118. </td>
  119. <td>
  120. {{ notif.channel }}
  121. </td>
  122. <td>
  123. <form class="admin-remove-updatepost">
  124. <input type="hidden" name="id" value="{{ notif._id.toString() }}">
  125. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  126. <input type="submit" value="Delete" class="btn btn-default">
  127. </form>
  128. </td>
  129. </tr>
  130. {% endfor %}
  131. </tbody>
  132. </table>
  133. {% endif %}
  134. {# {% if not hasSlackConfig %} #}
  135. <hr>
  136. <h3>How to configure Slack app</h3>
  137. <ol>
  138. <li>
  139. Register Slack App
  140. <ol>
  141. <li>
  142. Create App from <a href="https://api.slack.com/applications/new">this link</a>, and fill the form out as below:
  143. <dl class="dl-horizontal">
  144. <dt>App Name</dt> <dd><code>crowi-plus</code> </dd>
  145. <dt>Development Slack Team</dt> <dd>Select the team you want to notify to.</dd>
  146. </dl>
  147. </li>
  148. <li><strong>Save</strong> it.</li>
  149. </ol>
  150. </li>
  151. <li>
  152. Get App Credentials
  153. <ol>
  154. <li>Go To "Basic Information" page and make a note "Client ID" and "Client Secret".</li>
  155. </ol>
  156. </li>
  157. <li>
  158. Set Redirect URLs
  159. <ol>
  160. <li>Go to "OAuth &amp; Permissions" page.</li>
  161. <li>Add <code><script>document.write(location.origin);</script>/admin/notification/slackAuth</code> .</li>
  162. <li>Don't forget to <strong>save</strong>.</li>
  163. </ol>
  164. </li>
  165. <li>
  166. Set Permission Scopes to the App
  167. <ol>
  168. <li>Go to "OAuth &amp; Permissions" page and add "Send messages as crowi-plus"(<code>chat:write:bot</code>).</li>
  169. <li>Don't forget to <strong>save</strong>.</li>
  170. </ol>
  171. </li>
  172. <li>
  173. Create a bot user
  174. <ol>
  175. <li>Go to "Bot Users" page and add.</li>
  176. </ol>
  177. </li>
  178. <li>
  179. Install the app
  180. <ol>
  181. <li>Go to "Install App to Your Team" page and install.</li>
  182. </ol>
  183. </li>
  184. <li>
  185. (At Team) Approve the app
  186. <ol>
  187. <li>Go to the management Apps page for the team you installed the app and approve crowi-plus.</li>
  188. </ol>
  189. </li>
  190. <li>
  191. (At Team) Invite the bot to your team
  192. <ol>
  193. <li>Invite the user you created in <code>4. Add a bot user</code> to the channel you notify to.</li>
  194. </ol>
  195. </li>
  196. <li>
  197. (At crowi-plus) Input "clientId" and "clientSecret" and submit on this page.
  198. </li>
  199. <li>
  200. (At crowi-plus) Click "Connect to Slack" button to start OAuth process.
  201. </li>
  202. </ol>
  203. {# {% endif %} #}
  204. </div>
  205. </div>
  206. </div>
  207. {% endblock content_main %}
  208. {% block content_footer %}
  209. {% endblock content_footer %}