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,52 +11,54 @@
<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>
<h3>{{ t('settings', 'Limit to groups') }}</h3> <template v-if="enforced">
{{ t('settings', 'Enforcement of two-factor authentication can be set for certain groups only.') }} <h3>{{ t('settings', 'Limit to groups') }}</h3>
<p> {{ t('settings', 'Enforcement of two-factor authentication can be set for certain groups only.') }}
{{ t('settings', 'Two-factor authentication is enforced for all members of the following groups.') }} <p>
</p> {{ t('settings', 'Two-factor authentication is enforced for all members of the following groups.') }}
<p> </p>
<Multiselect v-model="state.enforcedGroups" <p>
:options="groups" <Multiselect v-model="enforcedGroups"
:placeholder="t('settings', 'Enforced groups')" :options="groups"
:disabled="loading" :placeholder="t('settings', 'Enforced groups')"
:multiple="true" :disabled="loading"
:searchable="true" :multiple="true"
@search-change="searchGroup" :searchable="true"
:loading="loadingGroups" @search-change="searchGroup"
:show-no-options="false" :loading="loadingGroups"
:close-on-select="false"> :show-no-options="false"
</Multiselect> :close-on-select="false">
</p> </Multiselect>
<p> </p>
{{ t('settings', 'Two-factor authentication is not enforced for members of the following groups.') }} <p>
</p> {{ t('settings', 'Two-factor authentication is not enforced for members of the following groups.') }}
<p> </p>
<Multiselect v-model="state.excludedGroups" <p>
:options="groups" <Multiselect v-model="excludedGroups"
:placeholder="t('settings', 'Excluded groups')" :options="groups"
:disabled="loading" :placeholder="t('settings', 'Excluded groups')"
:multiple="true" :disabled="loading"
:searchable="true" :multiple="true"
@search-change="searchGroup" :searchable="true"
:loading="loadingGroups" @search-change="searchGroup"
:show-no-options="false" :loading="loadingGroups"
:close-on-select="false"> :show-no-options="false"
</Multiselect> :close-on-select="false">
</p> </Multiselect>
<p> </p>
<em> <p>
<!-- this text is also found in the documentation. update it there as well if it ever changes --> <em>
{{ 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.') }} <!-- this text is also found in the documentation. update it there as well if it ever changes -->
</em> {{ 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.') }}
</p> </em>
</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)
} }