2
0

admin-auth.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. v-subheader.pl-0 Strategy Configuration
  27. .body-1.ml-3(v-if='!strategy.config || strategy.config.length < 1') This strategy has no configuration options you can modify.
  28. template(v-else, v-for='cfg in strategy.config')
  29. v-select(
  30. v-if='cfg.value.type === "string" && cfg.value.enum'
  31. :items='cfg.value.enum'
  32. :key='cfg.key'
  33. :label='cfg.key | startCase'
  34. v-model='cfg.value.value'
  35. prepend-icon='settings_applications'
  36. )
  37. v-switch(
  38. v-else-if='cfg.value.type === "boolean"'
  39. :key='cfg.key'
  40. :label='cfg.key | startCase'
  41. v-model='cfg.value.value'
  42. color='primary'
  43. prepend-icon='settings_applications'
  44. )
  45. v-text-field(
  46. v-else
  47. :key='cfg.key'
  48. :label='cfg.key | startCase'
  49. v-model='cfg.value.value'
  50. prepend-icon='settings_applications'
  51. )
  52. v-divider
  53. v-subheader.pl-0 Registration
  54. .pr-3
  55. v-switch.ml-3(
  56. v-model='strategy.selfRegistration'
  57. label='Allow self-registration'
  58. color='primary'
  59. hint='Allow any user successfully authorized by the strategy to access the wiki.'
  60. persistent-hint
  61. )
  62. v-select.ml-3(
  63. label='Limit to specific email domains'
  64. v-model='strategy.domainWhitelist'
  65. prepend-icon='mail_outline'
  66. persistent-hint
  67. deletable-chips
  68. clearable
  69. multiple
  70. chips
  71. tags
  72. )
  73. v-select.ml-3(
  74. :items='groups'
  75. item-text='name'
  76. item-value='id'
  77. label='Assign to group'
  78. v-model='strategy.autoEnrollGroups'
  79. prepend-icon='people'
  80. hint='Automatically assign new users to these groups.'
  81. persistent-hint
  82. deletable-chips
  83. autocomplete
  84. clearable
  85. multiple
  86. chips
  87. )
  88. v-card-chin
  89. v-btn(color='primary', @click='save')
  90. v-icon(left) chevron_right
  91. span Apply Configuration
  92. v-spacer
  93. v-btn(icon, @click='refresh')
  94. v-icon.grey--text refresh
  95. </template>
  96. <script>
  97. import _ from 'lodash'
  98. import groupsQuery from 'gql/admin/auth/auth-query-groups.gql'
  99. import strategiesQuery from 'gql/admin/auth/auth-query-strategies.gql'
  100. import strategiesSaveMutation from 'gql/admin/auth/auth-mutation-save-strategies.gql'
  101. export default {
  102. filters: {
  103. startCase(val) { return _.startCase(val) }
  104. },
  105. data() {
  106. return {
  107. groups: [],
  108. strategies: []
  109. }
  110. },
  111. computed: {
  112. activeStrategies() {
  113. return _.filter(this.strategies, 'isEnabled')
  114. }
  115. },
  116. methods: {
  117. async refresh() {
  118. await this.$apollo.queries.strategies.refetch()
  119. this.$store.commit('showNotification', {
  120. message: 'List of strategies has been refreshed.',
  121. style: 'success',
  122. icon: 'cached'
  123. })
  124. },
  125. async save() {
  126. this.$store.commit(`loadingStart`, 'admin-auth-savestrategies')
  127. await this.$apollo.mutate({
  128. mutation: strategiesSaveMutation,
  129. variables: {
  130. strategies: this.strategies.map(str => _.pick(str, [
  131. 'isEnabled',
  132. 'key',
  133. 'config',
  134. 'selfRegistration',
  135. 'domainWhitelist',
  136. 'autoEnrollGroups'
  137. ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: cfg.value.value}))}))
  138. }
  139. })
  140. this.$store.commit('showNotification', {
  141. message: 'Authentication configuration saved successfully.',
  142. style: 'success',
  143. icon: 'check'
  144. })
  145. this.$store.commit(`loadingStop`, 'admin-auth-savestrategies')
  146. }
  147. },
  148. apollo: {
  149. strategies: {
  150. query: strategiesQuery,
  151. fetchPolicy: 'network-only',
  152. update: (data) => _.cloneDeep(data.authentication.strategies).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.parse(cfg.value)}))})),
  153. watchLoading (isLoading) {
  154. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-refresh')
  155. }
  156. },
  157. groups: {
  158. query: groupsQuery,
  159. fetchPolicy: 'network-only',
  160. update: (data) => data.groups.list,
  161. watchLoading (isLoading) {
  162. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-groups-refresh')
  163. }
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang='scss'>
  169. </style>