feat: admin auth UI + fetch
This commit is contained in:
		| @@ -1,112 +1,103 @@ | ||||
| <template lang='pug'> | ||||
|   v-card(flat) | ||||
|     v-card(color='grey lighten-5') | ||||
|       .pa-3.pt-4 | ||||
|         .headline.primary--text Authentication | ||||
|         .subheading.grey--text Configure the authentication settings of your wiki | ||||
|       v-tabs(color='grey lighten-4', fixed-tabs, slider-color='primary', show-arrows) | ||||
|         v-tab(key='settings'): v-icon settings | ||||
|         v-tab(v-for='provider in activeProviders', :key='provider.key') {{ provider.title }} | ||||
|   v-card(tile, color='grey lighten-5') | ||||
|     .pa-3.pt-4 | ||||
|       .headline.primary--text Authentication | ||||
|       .subheading.grey--text Configure the authentication settings of your wiki | ||||
|     v-tabs(color='grey lighten-4', fixed-tabs, slider-color='primary', show-arrows) | ||||
|       v-tab(key='settings'): v-icon settings | ||||
|       v-tab(v-for='strategy in activeStrategies', :key='strategy.key') {{ strategy.title }} | ||||
|  | ||||
|         v-tab-item(key='settings', :transition='false', :reverse-transition='false') | ||||
|           v-card.pa-3 | ||||
|             .body-2.pb-2 Select which authentication providers to enable: | ||||
|             v-form | ||||
|               v-checkbox( | ||||
|                 v-for='(provider, n) in providers', | ||||
|                 v-model='auths', | ||||
|                 :key='provider.key', | ||||
|                 :label='provider.title', | ||||
|                 :value='provider.key', | ||||
|                 color='primary', | ||||
|                 :disabled='provider.key === `local`' | ||||
|                 hide-details | ||||
|               ) | ||||
|               v-divider | ||||
|               v-btn(color='primary') | ||||
|                 v-icon(left) chevron_right | ||||
|                 | Set Providers | ||||
|               v-btn(color='black', dark) | ||||
|                 v-icon(left) layers_clear | ||||
|                 | Flush Sessions | ||||
|               v-btn(icon, @click='refresh') | ||||
|                 v-icon.grey--text refresh | ||||
|       v-tab-item(key='settings', :transition='false', :reverse-transition='false') | ||||
|         v-card.pa-3(flat, tile) | ||||
|           v-subheader.pl-0.pb-2 Select which authentication strategies to enable: | ||||
|           v-form | ||||
|             v-checkbox( | ||||
|               v-for='strategy in strategies', | ||||
|               v-model='selectedStrategies', | ||||
|               :key='strategy.key', | ||||
|               :label='strategy.title', | ||||
|               :value='strategy.key', | ||||
|               color='primary', | ||||
|               :disabled='strategy.key === `local`' | ||||
|               hide-details | ||||
|             ) | ||||
|  | ||||
|         v-tab-item(v-for='(provider, n) in activeProviders', :key='provider.key', :transition='false', :reverse-transition='false') | ||||
|           v-card.pa-3 | ||||
|             v-form | ||||
|               v-subheader Provider Configuration | ||||
|               .body-1(v-if='!provider.props || provider.props.length < 1') This provider has no configuration options you can modify. | ||||
|               v-text-field(v-else, v-for='prop in provider.props', :key='prop', :label='prop', prepend-icon='mode_edit') | ||||
|               v-divider | ||||
|               v-subheader Registration | ||||
|               v-switch.ml-3( | ||||
|                 v-model='auths', | ||||
|                 label='Allow self-registration', | ||||
|                 :value='true', | ||||
|                 color='primary', | ||||
|                 hint='Allow any user successfully authorized by the provider to access the wiki.', | ||||
|                 persistent-hint | ||||
|               ) | ||||
|               v-text-field(label='Limit to specific email domains', prepend-icon='mail_outline') | ||||
|               v-text-field(label='Assign to group', prepend-icon='people') | ||||
|               v-divider | ||||
|               v-btn(color='primary') | ||||
|                 v-icon(left) chevron_right | ||||
|                 | Save Configuration | ||||
|       v-tab-item(v-for='(strategy, n) in activeStrategies', :key='strategy.key', :transition='false', :reverse-transition='false') | ||||
|         v-card.pa-3(flat, tile) | ||||
|           v-form | ||||
|             v-subheader.pl-0 Strategy Configuration | ||||
|             .body-1.ml-3(v-if='!strategy.config || strategy.config.length < 1') This strategy has no configuration options you can modify. | ||||
|             v-text-field(v-else, v-for='cfg in strategy.config', :key='cfg.key', :label='cfg.key', prepend-icon='settings_applications') | ||||
|             v-divider | ||||
|             v-subheader.pl-0 Registration | ||||
|             v-switch.ml-3( | ||||
|               v-model='auths', | ||||
|               label='Allow self-registration', | ||||
|               :value='true', | ||||
|               color='primary', | ||||
|               hint='Allow any user successfully authorized by the strategy to access the wiki.', | ||||
|               persistent-hint | ||||
|             ) | ||||
|             v-text-field.ml-3(label='Limit to specific email domains', prepend-icon='mail_outline') | ||||
|             v-text-field.ml-3(label='Assign to group', prepend-icon='people') | ||||
|  | ||||
|     v-divider.my-0 | ||||
|     v-card-actions.grey.lighten-4 | ||||
|       v-btn(color='primary') | ||||
|         v-icon(left) chevron_right | ||||
|         span Save | ||||
|       v-spacer | ||||
|       v-btn(icon, @click='refresh') | ||||
|         v-icon.grey--text refresh | ||||
|  | ||||
|     v-snackbar( | ||||
|       color='success' | ||||
|       top | ||||
|       v-model='refreshCompleted' | ||||
|     ) | ||||
|       v-icon.mr-3(dark) cached | ||||
|       | List of providers has been refreshed. | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
| import _ from 'lodash' | ||||
| import gql from 'graphql-tag' | ||||
|  | ||||
| import strategiesQuery from 'gql/admin-auth-query-strategies.gql' | ||||
| import strategiesSaveMutation from 'gql/admin-auth-mutation-save-strategies.gql' | ||||
|  | ||||
| export default { | ||||
|   data() { | ||||
|     return { | ||||
|       providers: [], | ||||
|       auths: ['local'], | ||||
|       refreshCompleted: false | ||||
|       strategies: [], | ||||
|       selectedStrategies: ['local'] | ||||
|     } | ||||
|   }, | ||||
|   computed: { | ||||
|     activeProviders() { | ||||
|       return _.filter(this.providers, 'isEnabled') | ||||
|     } | ||||
|   }, | ||||
|   apollo: { | ||||
|     providers: { | ||||
|       query: gql` | ||||
|         query { | ||||
|           authentication { | ||||
|             providers { | ||||
|               isEnabled | ||||
|               key | ||||
|               props | ||||
|               title | ||||
|               useForm | ||||
|               config { | ||||
|                 key | ||||
|                 value | ||||
|               } | ||||
|             } | ||||
|           } | ||||
|         } | ||||
|       `, | ||||
|       update: (data) => data.authentication.providers | ||||
|     activeStrategies() { | ||||
|       return _.filter(this.strategies, prv => _.includes(this.selectedStrategies, prv.key)) | ||||
|     } | ||||
|   }, | ||||
|   methods: { | ||||
|     async refresh() { | ||||
|       await this.$apollo.queries.providers.refetch() | ||||
|       this.refreshCompleted = true | ||||
|       await this.$apollo.queries.strategies.refetch() | ||||
|       this.$store.commit('showNotification', { | ||||
|         message: 'List of strategies has been refreshed.', | ||||
|         style: 'success', | ||||
|         icon: 'cached' | ||||
|       }) | ||||
|     }, | ||||
|     async saveProviders() { | ||||
|       this.$store.commit(`loadingStart`, 'admin-auth-savestrategies') | ||||
|       await this.$apollo.mutate({ | ||||
|         mutation: strategiesSaveMutation, | ||||
|         variables: { | ||||
|           strategies: this.auths | ||||
|         } | ||||
|       }) | ||||
|       this.$store.commit(`loadingStop`, 'admin-auth-savestrategies') | ||||
|     } | ||||
|   }, | ||||
|   apollo: { | ||||
|     strategies: { | ||||
|       query: strategiesQuery, | ||||
|       fetchPolicy: 'network-only', | ||||
|       update: (data) => data.authentication.strategies, | ||||
|       watchLoading (isLoading) { | ||||
|         this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-refresh') | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -132,6 +132,7 @@ export default { | ||||
|   apollo: { | ||||
|     info: { | ||||
|       query: systemInfoQuery, | ||||
|       fetchPolicy: 'network-only', | ||||
|       update: (data) => data.system.info, | ||||
|       watchLoading (isLoading) { | ||||
|         this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-system-refresh') | ||||
|   | ||||
| @@ -1,8 +1,10 @@ | ||||
| <template lang="pug"> | ||||
|   v-app | ||||
|     nav-header | ||||
|     .login(:class='{ "is-error": error }') | ||||
|     .login | ||||
|       .login-container(:class='{ "is-expanded": strategies.length > 1, "is-loading": isLoading }') | ||||
|         .login-mascot | ||||
|           img(src='/svg/henry-reading.svg', alt='Henry') | ||||
|         .login-providers(v-show='strategies.length > 1') | ||||
|           button(v-for='strategy in strategies', :class='{ "is-active": strategy.key === selectedStrategy }', @click='selectStrategy(strategy.key, strategy.useForm)', :title='strategy.title') | ||||
|             em(v-html='strategy.icon') | ||||
| @@ -160,7 +162,9 @@ export default { | ||||
|                   style: 'success', | ||||
|                   icon: 'check' | ||||
|                 }) | ||||
|                 window.location.replace('/') // TEMPORARY - USE RETURNURL | ||||
|                 _.delay(() => { | ||||
|                   window.location.replace('/') // TEMPORARY - USE RETURNURL | ||||
|                 }, 1000) | ||||
|               } | ||||
|               this.isLoading = false | ||||
|             } else { | ||||
| @@ -205,6 +209,9 @@ export default { | ||||
|                 style: 'success', | ||||
|                 icon: 'check' | ||||
|               }) | ||||
|               _.delay(() => { | ||||
|                 window.location.replace('/') // TEMPORARY - USE RETURNURL | ||||
|               }, 1000) | ||||
|               this.isLoading = false | ||||
|             } else { | ||||
|               throw new Error(respObj.responseResult.message) | ||||
| @@ -275,6 +282,20 @@ export default { | ||||
|       height: 25vh; | ||||
|     } | ||||
|  | ||||
|     &-mascot { | ||||
|       width: 200px; | ||||
|       height: 200px; | ||||
|       position: absolute; | ||||
|       top: -180px; | ||||
|       left: 50%; | ||||
|       margin-left: -100px; | ||||
|       z-index: 10; | ||||
|  | ||||
|       @include until($tablet) { | ||||
|         display: none; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     &-container { | ||||
|       position: relative; | ||||
|       display: flex; | ||||
| @@ -453,7 +474,7 @@ export default { | ||||
|         font-weight: 400; | ||||
|         color: mc('light-blue', '700'); | ||||
|         text-shadow: 1px 1px 0 #FFF; | ||||
|         padding: 0; | ||||
|         padding: 1rem 0 0 0; | ||||
|         margin: 0; | ||||
|       } | ||||
|  | ||||
|   | ||||
							
								
								
									
										12
									
								
								client/graph/admin-auth-mutation-save-strategies.gql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								client/graph/admin-auth-mutation-save-strategies.gql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| mutation($locale: String!, $autoUpdate: Boolean!, $namespacing: Boolean!, $namespaces: [String]!) { | ||||
|   localization { | ||||
|     updateLocale(locale: $locale, autoUpdate: $autoUpdate, namespacing: $namespacing, namespaces: $namespaces) { | ||||
|       responseResult { | ||||
|         succeeded | ||||
|         errorCode | ||||
|         slug | ||||
|         message | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										15
									
								
								client/graph/admin-auth-query-strategies.gql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								client/graph/admin-auth-query-strategies.gql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| query { | ||||
|   authentication { | ||||
|     strategies { | ||||
|       isEnabled | ||||
|       key | ||||
|       props | ||||
|       title | ||||
|       useForm | ||||
|       config { | ||||
|         key | ||||
|         value | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										87
									
								
								client/static/svg/henry-reading.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								client/static/svg/henry-reading.svg
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| After Width: | Height: | Size: 63 KiB | 
		Reference in New Issue
	
	Block a user