admin-auth.vue 7.2 KB

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