Merge pull request #14713 from nextcloud/fix/admin-2fa-collapse-disable

Collapse 2FA admin detail settings if disabled
This commit is contained in:
Morris Jobke 2019-03-20 14:20:46 +01:00 committed by GitHub
commit 1c8779dc6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 93 additions and 65 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -11,17 +11,17 @@
<input type="checkbox" <input type="checkbox"
id="two-factor-enforced" id="two-factor-enforced"
class="checkbox" class="checkbox"
v-model="state.enforced" v-model="enforced">
v-on:change="saveChanges">
<label for="two-factor-enforced">{{ t('settings', 'Enforce two-factor authentication') }}</label> <label for="two-factor-enforced">{{ t('settings', 'Enforce two-factor authentication') }}</label>
</p> </p>
<template v-if="enforced">
<h3>{{ t('settings', 'Limit to groups') }}</h3> <h3>{{ t('settings', 'Limit to groups') }}</h3>
{{ t('settings', 'Enforcement of two-factor authentication can be set for certain groups only.') }} {{ t('settings', 'Enforcement of two-factor authentication can be set for certain groups only.') }}
<p> <p>
{{ t('settings', 'Two-factor authentication is enforced for all members of the following groups.') }} {{ t('settings', 'Two-factor authentication is enforced for all members of the following groups.') }}
</p> </p>
<p> <p>
<Multiselect v-model="state.enforcedGroups" <Multiselect v-model="enforcedGroups"
:options="groups" :options="groups"
:placeholder="t('settings', 'Enforced groups')" :placeholder="t('settings', 'Enforced groups')"
:disabled="loading" :disabled="loading"
@ -37,7 +37,7 @@
{{ t('settings', 'Two-factor authentication is not enforced for members of the following groups.') }} {{ t('settings', 'Two-factor authentication is not enforced for members of the following groups.') }}
</p> </p>
<p> <p>
<Multiselect v-model="state.excludedGroups" <Multiselect v-model="excludedGroups"
:options="groups" :options="groups"
:placeholder="t('settings', 'Excluded groups')" :placeholder="t('settings', 'Excluded groups')"
:disabled="loading" :disabled="loading"
@ -55,8 +55,10 @@
{{ t('settings', 'When groups are selected/excluded, they use the following logic to determine if a user has 2FA enforced: If no groups are selected, 2FA is enabled for everyone except members of the excluded groups. If groups are selected, 2FA is enabled for all members of these. If a user is both in a selected and excluded group, the selected takes precedence and 2FA is enforced.') }} {{ t('settings', 'When groups are selected/excluded, they use the following logic to determine if a user has 2FA enforced: If no groups are selected, 2FA is enabled for everyone except members of the excluded groups. If groups are selected, 2FA is enabled for all members of these. If a user is both in a selected and excluded group, the selected takes precedence and 2FA is enforced.') }}
</em> </em>
</p> </p>
</template>
<p> <p>
<button class="button primary" <button class="button primary"
v-if="dirty"
v-on:click="saveChanges" v-on:click="saveChanges"
:disabled="loading"> :disabled="loading">
{{ t('settings', 'Save changes') }} {{ t('settings', 'Save changes') }}
@ -67,6 +69,7 @@
<script> <script>
import Axios from 'nextcloud-axios' import Axios from 'nextcloud-axios'
import { mapState } from 'vuex'
import {Multiselect} from 'nextcloud-vue' import {Multiselect} from 'nextcloud-vue'
import _ from 'lodash' import _ from 'lodash'
@ -78,23 +81,45 @@
data () { data () {
return { return {
loading: false, loading: false,
dirty: false,
groups: [], groups: [],
loadingGroups: false, loadingGroups: false,
} }
}, },
computed: { computed: {
state: function() { enforced: {
return { get: function () {
enforced: this.$store.state.enforced, return this.$store.state.enforced
enforcedGroups: this.$store.state.enforcedGroups, },
excludedGroups: this.$store.state.excludedGroups, set: function (val) {
this.dirty = true
this.$store.commit('setEnforced', val)
} }
},
enforcedGroups: {
get: function () {
return this.$store.state.enforcedGroups
},
set: function (val) {
this.dirty = true
this.$store.commit('setEnforcedGroups', val)
} }
}, },
excludedGroups: {
get: function () {
return this.$store.state.excludedGroups
},
set: function (val) {
this.dirty = true
this.$store.commit('setExcludedGroups', val)
}
},
},
mounted () { mounted () {
// Groups are loaded dynamically, but the assigned ones *should* // Groups are loaded dynamically, but the assigned ones *should*
// be valid groups, so let's add them as initial state // be valid groups, so let's add them as initial state
this.groups = _.sortedUniq(_.uniq(this.state.enforcedGroups.concat(this.state.excludedGroups))) console.log(this.enforcedGroups)
this.groups = _.sortedUniq(_.uniq(this.enforcedGroups.concat(this.excludedGroups)))
// Populate the groups with a first set so the dropdown is not empty // Populate the groups with a first set so the dropdown is not empty
// when opening the page the first time // when opening the page the first time
@ -114,16 +139,19 @@
saveChanges () { saveChanges () {
this.loading = true this.loading = true
const oldState = this.state const data = {
enforced: this.enforced,
Axios.put(OC.generateUrl('/settings/api/admin/twofactorauth'), this.state) enforcedGroups: this.enforcedGroups,
excludedGroups: this.excludedGroups,
}
Axios.put(OC.generateUrl('/settings/api/admin/twofactorauth'), data)
.then(resp => resp.data) .then(resp => resp.data)
.then(state => this.state = state) .then(state => {
this.state = state
this.dirty = false
})
.catch(err => { .catch(err => {
console.error('could not save changes', err) console.error('could not save changes', err)
// Restore
this.state = oldState
}) })
.then(() => this.loading = false) .then(() => this.loading = false)
} }