admin-auth.vue 7.25 KB
Newer Older
1
<template lang='pug'>
NGPixel's avatar
NGPixel committed
2
  v-card(tile, :color='$vuetify.dark ? "grey darken-4" : "grey lighten-5"')
NGPixel's avatar
NGPixel committed
3
    .pa-3.pt-4
4
      .admin-header-icon: v-icon(size='80', color='grey lighten-2') lock_outline
NGPixel's avatar
NGPixel committed
5 6
      .headline.primary--text Authentication
      .subheading.grey--text Configure the authentication settings of your wiki
NGPixel's avatar
NGPixel committed
7
    v-tabs(:color='$vuetify.dark ? "primary" : "grey lighten-4"', fixed-tabs, :slider-color='$vuetify.dark ? "white" : "primary"', show-arrows)
NGPixel's avatar
NGPixel committed
8 9
      v-tab(key='settings'): v-icon settings
      v-tab(v-for='strategy in activeStrategies', :key='strategy.key') {{ strategy.title }}
10

NGPixel's avatar
NGPixel committed
11 12
      v-tab-item(key='settings', :transition='false', :reverse-transition='false')
        v-card.pa-3(flat, tile)
13 14
          .body-2.grey--text.text--darken-1 Select which authentication strategies to enable:
          .caption.grey--text.pb-2 Some strategies require additional configuration in their dedicated tab (when selected).
NGPixel's avatar
NGPixel committed
15
          v-form
16
            v-checkbox.my-0(
17 18 19 20 21
              v-for='strategy in strategies'
              v-model='strategy.isEnabled'
              :key='strategy.key'
              :label='strategy.title'
              color='primary'
NGPixel's avatar
NGPixel committed
22 23 24
              :disabled='strategy.key === `local`'
              hide-details
            )
25

NGPixel's avatar
NGPixel committed
26 27 28
      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
29 30 31 32 33 34
            .authlogo
              img(:src='strategy.logo', :alt='strategy.title')
            v-subheader.pl-0 {{strategy.title}}
            .caption {{strategy.description}}
            .caption: a(:href='strategy.website') {{strategy.website}}
            v-divider.mt-3
NGPixel's avatar
NGPixel committed
35 36
            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.
37 38 39
            template(v-else, v-for='cfg in strategy.config')
              v-select(
                v-if='cfg.value.type === "string" && cfg.value.enum'
40 41
                outline
                background-color='grey lighten-2'
42 43
                :items='cfg.value.enum'
                :key='cfg.key'
44
                :label='cfg.value.title'
45 46
                v-model='cfg.value.value'
                prepend-icon='settings_applications'
47 48 49
                :hint='cfg.value.hint ? cfg.value.hint : ""'
                persistent-hint
                :class='cfg.value.hint ? "mb-2" : ""'
50
              )
51
              v-switch.mb-3(
52 53
                v-else-if='cfg.value.type === "boolean"'
                :key='cfg.key'
54
                :label='cfg.value.title'
55 56 57
                v-model='cfg.value.value'
                color='primary'
                prepend-icon='settings_applications'
58 59
                :hint='cfg.value.hint ? cfg.value.hint : ""'
                persistent-hint
60 61 62
                )
              v-text-field(
                v-else
63 64
                outline
                background-color='grey lighten-2'
65
                :key='cfg.key'
66
                :label='cfg.value.title'
67 68
                v-model='cfg.value.value'
                prepend-icon='settings_applications'
69 70 71
                :hint='cfg.value.hint ? cfg.value.hint : ""'
                persistent-hint
                :class='cfg.value.hint ? "mb-2" : ""'
72
                )
73
            v-divider.mt-3
NGPixel's avatar
NGPixel committed
74
            v-subheader.pl-0 Registration
75 76 77 78 79 80 81
            .pr-3
              v-switch.ml-3(
                v-model='strategy.selfRegistration'
                label='Allow self-registration'
                color='primary'
                hint='Allow any user successfully authorized by the strategy to access the wiki.'
                persistent-hint
82
              )
83
              v-combobox.ml-3.mt-3(
84 85 86
                label='Limit to specific email domains'
                v-model='strategy.domainWhitelist'
                prepend-icon='mail_outline'
87 88
                outline
                background-color='grey lighten-2'
89 90 91 92 93 94
                persistent-hint
                deletable-chips
                clearable
                multiple
                chips
                )
95 96 97
              v-autocomplete.ml-3(
                outline
                background-color='grey lighten-2'
98 99 100 101 102 103 104 105 106 107 108 109 110
                :items='groups'
                item-text='name'
                item-value='id'
                label='Assign to group'
                v-model='strategy.autoEnrollGroups'
                prepend-icon='people'
                hint='Automatically assign new users to these groups.'
                persistent-hint
                deletable-chips
                clearable
                multiple
                chips
                )
NGPixel's avatar
NGPixel committed
111

NGPixel's avatar
NGPixel committed
112
    v-card-chin
113
      v-btn(color='primary', @click='save')
NGPixel's avatar
NGPixel committed
114
        v-icon(left) chevron_right
115
        span Apply Configuration
NGPixel's avatar
NGPixel committed
116 117 118
      v-spacer
      v-btn(icon, @click='refresh')
        v-icon.grey--text refresh
119

120 121 122
</template>

<script>
123
import _ from 'lodash'
NGPixel's avatar
NGPixel committed
124

125
import groupsQuery from 'gql/admin/auth/auth-query-groups.gql'
126 127
import strategiesQuery from 'gql/admin/auth/auth-query-strategies.gql'
import strategiesSaveMutation from 'gql/admin/auth/auth-mutation-save-strategies.gql'
128

129
export default {
130 131 132
  filters: {
    startCase(val) { return _.startCase(val) }
  },
133 134
  data() {
    return {
135 136
      groups: [],
      strategies: []
137
    }
138
  },
139
  computed: {
NGPixel's avatar
NGPixel committed
140
    activeStrategies() {
141
      return _.filter(this.strategies, 'isEnabled')
142 143
    }
  },
NGPixel's avatar
NGPixel committed
144 145 146 147 148 149 150 151 152
  methods: {
    async refresh() {
      await this.$apollo.queries.strategies.refetch()
      this.$store.commit('showNotification', {
        message: 'List of strategies has been refreshed.',
        style: 'success',
        icon: 'cached'
      })
    },
153
    async save() {
NGPixel's avatar
NGPixel committed
154 155 156 157
      this.$store.commit(`loadingStart`, 'admin-auth-savestrategies')
      await this.$apollo.mutate({
        mutation: strategiesSaveMutation,
        variables: {
158 159 160 161 162 163 164
          strategies: this.strategies.map(str => _.pick(str, [
            'isEnabled',
            'key',
            'config',
            'selfRegistration',
            'domainWhitelist',
            'autoEnrollGroups'
165
          ])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: cfg.value.value}))}))
166
        }
NGPixel's avatar
NGPixel committed
167
      })
168
      this.$store.commit('showNotification', {
169
        message: 'Authentication configuration saved successfully.',
170 171 172
        style: 'success',
        icon: 'check'
      })
NGPixel's avatar
NGPixel committed
173
      this.$store.commit(`loadingStop`, 'admin-auth-savestrategies')
174
    }
175
  },
NGPixel's avatar
NGPixel committed
176 177 178 179
  apollo: {
    strategies: {
      query: strategiesQuery,
      fetchPolicy: 'network-only',
180
      update: (data) => _.cloneDeep(data.authentication.strategies).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.parse(cfg.value)}))})),
NGPixel's avatar
NGPixel committed
181 182 183
      watchLoading (isLoading) {
        this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-refresh')
      }
184 185 186 187 188 189 190 191
    },
    groups: {
      query: groupsQuery,
      fetchPolicy: 'network-only',
      update: (data) => data.groups.list,
      watchLoading (isLoading) {
        this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-auth-groups-refresh')
      }
192
    }
193 194 195 196
  }
}
</script>

197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
<style lang='scss' scoped>

.authlogo {
  width: 250px;
  height: 85px;
  float:right;
  display: flex;
  justify-content: flex-end;
  align-items: center;

  img {
    max-width: 100%;
    max-height: 50px;
  }
}
212 213

</style>