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.

215 lines
7.9 KiB

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