Skip to content

Commit 1c8779d

Browse files
authored
Merge pull request #14713 from nextcloud/fix/admin-2fa-collapse-disable
Collapse 2FA admin detail settings if disabled
2 parents 69f1871 + 3311d95 commit 1c8779d

File tree

5 files changed

+93
-65
lines changed

5 files changed

+93
-65
lines changed

settings/js/vue-1.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings/js/vue-2.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings/js/vue-settings-admin-security.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings/js/vue-settings-admin-security.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings/src/components/AdminTwoFactor.vue

Lines changed: 84 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,54 @@
1111
<input type="checkbox"
1212
id="two-factor-enforced"
1313
class="checkbox"
14-
v-model="state.enforced"
15-
v-on:change="saveChanges">
14+
v-model="enforced">
1615
<label for="two-factor-enforced">{{ t('settings', 'Enforce two-factor authentication') }}</label>
1716
</p>
18-
<h3>{{ t('settings', 'Limit to groups') }}</h3>
19-
{{ t('settings', 'Enforcement of two-factor authentication can be set for certain groups only.') }}
20-
<p>
21-
{{ t('settings', 'Two-factor authentication is enforced for all members of the following groups.') }}
22-
</p>
23-
<p>
24-
<Multiselect v-model="state.enforcedGroups"
25-
:options="groups"
26-
:placeholder="t('settings', 'Enforced groups')"
27-
:disabled="loading"
28-
:multiple="true"
29-
:searchable="true"
30-
@search-change="searchGroup"
31-
:loading="loadingGroups"
32-
:show-no-options="false"
33-
:close-on-select="false">
34-
</Multiselect>
35-
</p>
36-
<p>
37-
{{ t('settings', 'Two-factor authentication is not enforced for members of the following groups.') }}
38-
</p>
39-
<p>
40-
<Multiselect v-model="state.excludedGroups"
41-
:options="groups"
42-
:placeholder="t('settings', 'Excluded groups')"
43-
:disabled="loading"
44-
:multiple="true"
45-
:searchable="true"
46-
@search-change="searchGroup"
47-
:loading="loadingGroups"
48-
:show-no-options="false"
49-
:close-on-select="false">
50-
</Multiselect>
51-
</p>
52-
<p>
53-
<em>
54-
<!-- this text is also found in the documentation. update it there as well if it ever changes -->
55-
{{ 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.') }}
56-
</em>
57-
</p>
17+
<template v-if="enforced">
18+
<h3>{{ t('settings', 'Limit to groups') }}</h3>
19+
{{ t('settings', 'Enforcement of two-factor authentication can be set for certain groups only.') }}
20+
<p>
21+
{{ t('settings', 'Two-factor authentication is enforced for all members of the following groups.') }}
22+
</p>
23+
<p>
24+
<Multiselect v-model="enforcedGroups"
25+
:options="groups"
26+
:placeholder="t('settings', 'Enforced groups')"
27+
:disabled="loading"
28+
:multiple="true"
29+
:searchable="true"
30+
@search-change="searchGroup"
31+
:loading="loadingGroups"
32+
:show-no-options="false"
33+
:close-on-select="false">
34+
</Multiselect>
35+
</p>
36+
<p>
37+
{{ t('settings', 'Two-factor authentication is not enforced for members of the following groups.') }}
38+
</p>
39+
<p>
40+
<Multiselect v-model="excludedGroups"
41+
:options="groups"
42+
:placeholder="t('settings', 'Excluded groups')"
43+
:disabled="loading"
44+
:multiple="true"
45+
:searchable="true"
46+
@search-change="searchGroup"
47+
:loading="loadingGroups"
48+
:show-no-options="false"
49+
:close-on-select="false">
50+
</Multiselect>
51+
</p>
52+
<p>
53+
<em>
54+
<!-- this text is also found in the documentation. update it there as well if it ever changes -->
55+
{{ 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.') }}
56+
</em>
57+
</p>
58+
</template>
5859
<p>
5960
<button class="button primary"
61+
v-if="dirty"
6062
v-on:click="saveChanges"
6163
:disabled="loading">
6264
{{ t('settings', 'Save changes') }}
@@ -67,6 +69,7 @@
6769

6870
<script>
6971
import Axios from 'nextcloud-axios'
72+
import { mapState } from 'vuex'
7073
import {Multiselect} from 'nextcloud-vue'
7174
import _ from 'lodash'
7275
@@ -78,23 +81,45 @@
7881
data () {
7982
return {
8083
loading: false,
84+
dirty: false,
8185
groups: [],
8286
loadingGroups: false,
8387
}
8488
},
8589
computed: {
86-
state: function() {
87-
return {
88-
enforced: this.$store.state.enforced,
89-
enforcedGroups: this.$store.state.enforcedGroups,
90-
excludedGroups: this.$store.state.excludedGroups,
90+
enforced: {
91+
get: function () {
92+
return this.$store.state.enforced
93+
},
94+
set: function (val) {
95+
this.dirty = true
96+
this.$store.commit('setEnforced', val)
9197
}
92-
}
98+
},
99+
enforcedGroups: {
100+
get: function () {
101+
return this.$store.state.enforcedGroups
102+
},
103+
set: function (val) {
104+
this.dirty = true
105+
this.$store.commit('setEnforcedGroups', val)
106+
}
107+
},
108+
excludedGroups: {
109+
get: function () {
110+
return this.$store.state.excludedGroups
111+
},
112+
set: function (val) {
113+
this.dirty = true
114+
this.$store.commit('setExcludedGroups', val)
115+
}
116+
},
93117
},
94118
mounted () {
95119
// Groups are loaded dynamically, but the assigned ones *should*
96120
// be valid groups, so let's add them as initial state
97-
this.groups = _.sortedUniq(_.uniq(this.state.enforcedGroups.concat(this.state.excludedGroups)))
121+
console.log(this.enforcedGroups)
122+
this.groups = _.sortedUniq(_.uniq(this.enforcedGroups.concat(this.excludedGroups)))
98123
99124
// Populate the groups with a first set so the dropdown is not empty
100125
// when opening the page the first time
@@ -114,16 +139,19 @@
114139
saveChanges () {
115140
this.loading = true
116141
117-
const oldState = this.state
118-
119-
Axios.put(OC.generateUrl('/settings/api/admin/twofactorauth'), this.state)
142+
const data = {
143+
enforced: this.enforced,
144+
enforcedGroups: this.enforcedGroups,
145+
excludedGroups: this.excludedGroups,
146+
}
147+
Axios.put(OC.generateUrl('/settings/api/admin/twofactorauth'), data)
120148
.then(resp => resp.data)
121-
.then(state => this.state = state)
149+
.then(state => {
150+
this.state = state
151+
this.dirty = false
152+
})
122153
.catch(err => {
123154
console.error('could not save changes', err)
124-
125-
// Restore
126-
this.state = oldState
127155
})
128156
.then(() => this.loading = false)
129157
}

0 commit comments

Comments
 (0)