You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
7.2 KiB

  1. <template lang='pug'>
  2. v-card(tile, :color='$vuetify.dark ? "grey darken-4" : "grey lighten-5"')
  3. .pa-3.pt-4
  4. .headline.primary--text Authentication
  5. .subheading.grey--text Configure the authentication settings of your wiki
  6. v-tabs(:color='$vuetify.dark ? "primary" : "grey lighten-4"', fixed-tabs, :slider-color='$vuetify.dark ? "white" : "primary"', show-arrows)
  7. v-tab(key='settings'): v-icon settings
  8. v-tab(v-for='strategy in activeStrategies', :key='strategy.key') {{ strategy.title }}
  9. v-tab-item(key='settings', :transition='false', :reverse-transition='false')
  10. v-card.pa-3(flat, tile)
  11. .body-2.grey--text.text--darken-1 Select which authentication strategies to enable:
  12. .caption.grey--text.pb-2 Some strategies require additional configuration in their dedicated tab (when selected).
  13. v-form
  14. v-checkbox.my-1(
  15. v-for='strategy in strategies'
  16. v-model='strategy.isEnabled'
  17. :key='strategy.key'
  18. :label='strategy.title'
  19. color='primary'
  20. :disabled='strategy.key === `local`'
  21. hide-details
  22. )
  23. v-tab-item(v-for='(strategy, n) in activeStrategies', :key='strategy.key', :transition='false', :reverse-transition='false')
  24. v-card.pa-3(flat, tile)
  25. v-form
  26. .authlogo
  27. img(:src='strategy.logo', :alt='strategy.title')
  28. v-subheader.pl-0 {{strategy.title}}
  29. .caption {{strategy.description}}
  30. .caption: a(:href='strategy.website') {{strategy.website}}
  31. v-divider.mt-3
  32. v-subheader.pl-0 Strategy Configuration
  33. .body-1.ml-3(v-if='!strategy.config || strategy.config.length < 1') This strategy has no configuration options you can modify.
  34. template(v-else, v-for='cfg in strategy.config')
  35. v-select(
  36. v-if='cfg.value.type === "string" && cfg.value.enum'
  37. outline
  38. background-color='grey lighten-2'
  39. :items='cfg.value.enum'
  40. :key='cfg.key'
  41. :label='cfg.value.title'
  42. v-model='cfg.value.value'
  43. prepend-icon='settings_applications'
  44. :hint='cfg.value.hint ? cfg.value.hint : ""'
  45. persistent-hint
  46. :class='cfg.value.hint ? "mb-2" : ""'
  47. )
  48. v-switch(
  49. v-else-if='cfg.value.type === "boolean"'
  50. :key='cfg.key'
  51. :label='cfg.value.title'
  52. v-model='cfg.value.value'
  53. color='primary'
  54. prepend-icon='settings_applications'
  55. :hint='cfg.value.hint ? cfg.value.hint : ""'
  56. persistent-hint
  57. )
  58. v-text-field(
  59. v-else
  60. outline
  61. background-color='grey lighten-2'
  62. :key='cfg.key'
  63. :label='cfg.value.title'
  64. v-model='cfg.value.value'
  65. prepend-icon='settings_applications'
  66. :hint='cfg.value.hint ? cfg.value.hint : ""'
  67. persistent-hint
  68. :class='cfg.value.hint ? "mb-2" : ""'
  69. )
  70. v-divider.mt-3
  71. v-subheader.pl-0 Registration
  72. .pr-3
  73. v-switch.ml-3(
  74. v-model='strategy.selfRegistration'
  75. label='Allow self-registration'
  76. color='primary'
  77. hint='Allow any user successfully authorized by the strategy to access the wiki.'
  78. persistent-hint
  79. )
  80. v-combobox.ml-3.mt-3(
  81. label='Limit to specific email domains'
  82. v-model='strategy.domainWhitelist'
  83. prepend-icon='mail_outline'
  84. outline
  85. background-color='grey lighten-2'
  86. persistent-hint
  87. deletable-chips
  88. clearable
  89. multiple
  90. chips
  91. )
  92. v-autocomplete.ml-3(
  93. outline
  94. background-color='grey lighten-2'
  95. :items='groups'
  96. item-text='name'
  97. item-value='id'
  98. label='Assign to group'
  99. v-model='strategy.autoEnrollGroups'
  100. prepend-icon='people'
  101. hint='Automatically assign new users to these groups.'
  102. persistent-hint
  103. deletable-chips
  104. clearable
  105. multiple
  106. chips
  107. )
  108. v-card-chin
  109. v-btn(color='primary', @click='save')
  110. v-icon(left) chevron_right
  111. span Apply Configuration
  112. v-spacer
  113. v-btn(icon, @click='refresh')
  114. v-icon.grey--text refresh
  115. </template>
  116. <script>
  117. import _ from 'lodash'
  118. import groupsQuery from 'gql/admin/auth/auth-query-groups.gql'
  119. import strategiesQuery from 'gql/admin/auth/auth-query-strategies.gql'
  120. import strategiesSaveMutation from 'gql/admin/auth/auth-mutation-save-strategies.gql'
  121. export default {
  122. filters: {
  123. startCase(val) { return _.startCase(val) }
  124. },
  125. data() {
  126. return {
  127. groups: [],
  128. strategies: []
  129. }
  130. },
  131. computed: {
  132. activeStrategies() {
  133. return _.filter(this.strategies, 'isEnabled')
  134. }
  135. },
  136. methods: {
  137. async refresh() {
  138. await this.$apollo.queries.strategies.refetch()
  139. this.$store.commit('showNotification', {
  140. message: 'List of strategies has been refreshed.',
  141. style: 'success',
  142. icon: 'cached'
  143. })
  144. },
  145. async save() {
  146. this.$store.commit(`loadingStart`, 'admin-auth-savestrategies')
  147. await this.$apollo.mutate({
  148. mutation: strategiesSaveMutation,
  149. variables: {
  150. strategies: this.strategies.map(str => _.pick(str, [
  151. 'isEnabled',
  152. 'key',
  153. 'config',
  154. 'selfRegistration',
  155. 'domainWhitelist',
  156. 'autoEnrollGroups'
  157. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: cfg.value.value}))}))
  158. }
  159. })
  160. this.$store.commit('showNotification', {
  161. message: 'Authentication configuration saved successfully.',
  162. style: 'success',
  163. icon: 'check'
  164. })
  165. this.$store.commit(`loadingStop`, 'admin-auth-savestrategies')
  166. }
  167. },
  168. apollo: {
  169. strategies: {
  170. query: strategiesQuery,
  171. fetchPolicy: 'network-only',
  172. update: (data) => _.cloneDeep(data.authentication.strategies).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.parse(cfg.value)}))})),
  173. watchLoading (isLoading) {
  174. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-refresh')
  175. }
  176. },
  177. groups: {
  178. query: groupsQuery,
  179. fetchPolicy: 'network-only',
  180. update: (data) => data.groups.list,
  181. watchLoading (isLoading) {
  182. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-groups-refresh')
  183. }
  184. }
  185. }
  186. }
  187. </script>
  188. <style lang='scss' scoped>
  189. .authlogo {
  190. width: 250px;
  191. height: 85px;
  192. float:right;
  193. display: flex;
  194. justify-content: flex-end;
  195. align-items: center;
  196. img {
  197. max-width: 100%;
  198. max-height: 50px;
  199. }
  200. }
  201. </style>