|
11 | 11 | <input type="checkbox" |
12 | 12 | id="two-factor-enforced" |
13 | 13 | class="checkbox" |
14 | | - v-model="state.enforced" |
15 | | - v-on:change="saveChanges"> |
| 14 | + v-model="enforced"> |
16 | 15 | <label for="two-factor-enforced">{{ t('settings', 'Enforce two-factor authentication') }}</label> |
17 | 16 | </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> |
58 | 59 | <p> |
59 | 60 | <button class="button primary" |
| 61 | + v-if="dirty" |
60 | 62 | v-on:click="saveChanges" |
61 | 63 | :disabled="loading"> |
62 | 64 | {{ t('settings', 'Save changes') }} |
|
67 | 69 |
|
68 | 70 | <script> |
69 | 71 | import Axios from 'nextcloud-axios' |
| 72 | + import { mapState } from 'vuex' |
70 | 73 | import {Multiselect} from 'nextcloud-vue' |
71 | 74 | import _ from 'lodash' |
72 | 75 |
|
|
78 | 81 | data () { |
79 | 82 | return { |
80 | 83 | loading: false, |
| 84 | + dirty: false, |
81 | 85 | groups: [], |
82 | 86 | loadingGroups: false, |
83 | 87 | } |
84 | 88 | }, |
85 | 89 | 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) |
91 | 97 | } |
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 | + }, |
93 | 117 | }, |
94 | 118 | mounted () { |
95 | 119 | // Groups are loaded dynamically, but the assigned ones *should* |
96 | 120 | // 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))) |
98 | 123 |
|
99 | 124 | // Populate the groups with a first set so the dropdown is not empty |
100 | 125 | // when opening the page the first time |
|
114 | 139 | saveChanges () { |
115 | 140 | this.loading = true |
116 | 141 |
|
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) |
120 | 148 | .then(resp => resp.data) |
121 | | - .then(state => this.state = state) |
| 149 | + .then(state => { |
| 150 | + this.state = state |
| 151 | + this.dirty = false |
| 152 | + }) |
122 | 153 | .catch(err => { |
123 | 154 | console.error('could not save changes', err) |
124 | | -
|
125 | | - // Restore |
126 | | - this.state = oldState |
127 | 155 | }) |
128 | 156 | .then(() => this.loading = false) |
129 | 157 | } |
|
0 commit comments