Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 1 | <template> |
Yoshie Muranaka | 0b8cffd | 2020-06-23 08:44:54 -0700 | [diff] [blame] | 2 | <b-modal id="modal-user" ref="modal" @hidden="resetForm"> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 3 | <template v-slot:modal-title> |
| 4 | <template v-if="newUser"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 5 | {{ $t('pageLocalUserManagement.addUser') }} |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 6 | </template> |
| 7 | <template v-else> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 8 | {{ $t('pageLocalUserManagement.editUser') }} |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 9 | </template> |
| 10 | </template> |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 11 | <b-form id="form-user" novalidate @submit.prevent="handleSubmit"> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 12 | <b-container> |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 13 | <!-- Manual unlock form control --> |
| 14 | <b-row v-if="!newUser && manualUnlockPolicy && user.Locked"> |
| 15 | <b-col sm="9"> |
| 16 | <alert :show="true" variant="warning" small> |
| 17 | <template v-if="!$v.form.manualUnlock.$dirty"> |
| 18 | {{ $t('pageLocalUserManagement.modal.accountLocked') }} |
| 19 | </template> |
| 20 | <template v-else> |
| 21 | {{ |
| 22 | $t('pageLocalUserManagement.modal.clickSaveToUnlockAccount') |
| 23 | }} |
| 24 | </template> |
| 25 | </alert> |
| 26 | </b-col> |
| 27 | <b-col sm="3"> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame^] | 28 | <input |
| 29 | v-model="form.manualUnlock" |
| 30 | data-test-id="localUserManagement-input-manualUnlock" |
| 31 | type="hidden" |
| 32 | value="false" |
| 33 | /> |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 34 | <b-button |
| 35 | variant="primary" |
| 36 | :disabled="$v.form.manualUnlock.$dirty" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame^] | 37 | data-test-id="localUserManagement-button-manualUnlock" |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 38 | @click="$v.form.manualUnlock.$touch()" |
| 39 | > |
| 40 | {{ $t('pageLocalUserManagement.modal.unlock') }} |
| 41 | </b-button> |
| 42 | </b-col> |
| 43 | </b-row> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 44 | <b-row> |
| 45 | <b-col> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 46 | <b-form-group |
| 47 | :label="$t('pageLocalUserManagement.modal.accountStatus')" |
| 48 | > |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 49 | <b-form-radio |
| 50 | v-model="form.status" |
| 51 | name="user-status" |
| 52 | :value="true" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame^] | 53 | data-test-id="localUserManagement-radioButton-statusEnabled" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 54 | @input="$v.form.status.$touch()" |
| 55 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 56 | {{ $t('global.status.enabled') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 57 | </b-form-radio> |
| 58 | <b-form-radio |
| 59 | v-model="form.status" |
| 60 | name="user-status" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame^] | 61 | data-test-id="localUserManagement-radioButton-statusDisabled" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 62 | :value="false" |
| 63 | @input="$v.form.status.$touch()" |
| 64 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 65 | {{ $t('global.status.disabled') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 66 | </b-form-radio> |
| 67 | </b-form-group> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 68 | <b-form-group |
| 69 | :label="$t('pageLocalUserManagement.modal.username')" |
| 70 | label-for="username" |
| 71 | > |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 72 | <b-form-text id="username-help-block"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 73 | {{ $t('pageLocalUserManagement.modal.cannotStartWithANumber') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 74 | <br /> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 75 | {{ |
| 76 | $t( |
| 77 | 'pageLocalUserManagement.modal.noSpecialCharactersExceptUnderscore' |
| 78 | ) |
| 79 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 80 | </b-form-text> |
| 81 | <b-form-input |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 82 | id="username" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 83 | v-model="form.username" |
| 84 | type="text" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 85 | aria-describedby="username-help-block" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame^] | 86 | data-test-id="localUserManagement-input-username" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 87 | :state="getValidationState($v.form.username)" |
| 88 | :disabled="!newUser && originalUsername === 'root'" |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 89 | @input="$v.form.username.$touch()" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 90 | /> |
| 91 | <b-form-invalid-feedback role="alert"> |
| 92 | <template v-if="!$v.form.username.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 93 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 94 | </template> |
| 95 | <template v-else-if="!$v.form.username.maxLength"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 96 | {{ |
| 97 | $t('global.form.lengthMustBeBetween', { min: 1, max: 16 }) |
| 98 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 99 | </template> |
| 100 | <template v-else-if="!$v.form.username.pattern"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 101 | {{ $t('global.form.invalidFormat') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 102 | </template> |
| 103 | </b-form-invalid-feedback> |
| 104 | </b-form-group> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 105 | <b-form-group |
| 106 | :label="$t('pageLocalUserManagement.modal.privilege')" |
Yoshie Muranaka | a4b9e40 | 2020-03-06 14:59:46 -0800 | [diff] [blame] | 107 | label-for="privilege" |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 108 | > |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 109 | <b-form-select |
Yoshie Muranaka | a4b9e40 | 2020-03-06 14:59:46 -0800 | [diff] [blame] | 110 | id="privilege" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 111 | v-model="form.privilege" |
| 112 | :options="privilegeTypes" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame^] | 113 | data-test-id="localUserManagement-select-privilege" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 114 | :state="getValidationState($v.form.privilege)" |
| 115 | @input="$v.form.privilege.$touch()" |
| 116 | > |
| 117 | </b-form-select> |
| 118 | <b-form-invalid-feedback role="alert"> |
| 119 | <template v-if="!$v.form.privilege.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 120 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 121 | </template> |
| 122 | </b-form-invalid-feedback> |
| 123 | </b-form-group> |
| 124 | </b-col> |
| 125 | <b-col> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 126 | <b-form-group |
| 127 | :label="$t('pageLocalUserManagement.modal.userPassword')" |
| 128 | label-for="password" |
| 129 | > |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 130 | <b-form-text id="password-help-block"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 131 | {{ |
| 132 | $t('pageLocalUserManagement.modal.passwordMustBeBetween', { |
| 133 | min: passwordRequirements.minLength, |
| 134 | max: passwordRequirements.maxLength |
| 135 | }) |
| 136 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 137 | </b-form-text> |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 138 | <input-password-toggle> |
| 139 | <b-form-input |
| 140 | id="password" |
| 141 | v-model="form.password" |
| 142 | type="password" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame^] | 143 | data-test-id="localUserManagement-input-password" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 144 | aria-describedby="password-help-block" |
| 145 | :state="getValidationState($v.form.password)" |
| 146 | @input="$v.form.password.$touch()" |
| 147 | /> |
| 148 | <b-form-invalid-feedback role="alert"> |
| 149 | <template v-if="!$v.form.password.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 150 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 151 | </template> |
| 152 | <template |
| 153 | v-if=" |
| 154 | !$v.form.password.minLength || !$v.form.password.maxLength |
| 155 | " |
| 156 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 157 | {{ |
| 158 | $t( |
| 159 | 'pageLocalUserManagement.modal.passwordMustBeBetween', |
| 160 | { |
| 161 | min: passwordRequirements.minLength, |
| 162 | max: passwordRequirements.maxLength |
| 163 | } |
| 164 | ) |
| 165 | }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 166 | </template> |
| 167 | </b-form-invalid-feedback> |
| 168 | </input-password-toggle> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 169 | </b-form-group> |
| 170 | <b-form-group |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 171 | :label="$t('pageLocalUserManagement.modal.confirmUserPassword')" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 172 | label-for="password-confirmation" |
| 173 | > |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 174 | <input-password-toggle> |
| 175 | <b-form-input |
| 176 | id="password-confirmation" |
| 177 | v-model="form.passwordConfirmation" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame^] | 178 | data-test-id="localUserManagement-input-passwordConfirmation" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 179 | type="password" |
| 180 | :state="getValidationState($v.form.passwordConfirmation)" |
| 181 | @input="$v.form.passwordConfirmation.$touch()" |
| 182 | /> |
| 183 | <b-form-invalid-feedback role="alert"> |
| 184 | <template v-if="!$v.form.passwordConfirmation.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 185 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 186 | </template> |
| 187 | <template |
| 188 | v-else-if="!$v.form.passwordConfirmation.sameAsPassword" |
| 189 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 190 | {{ |
| 191 | $t('pageLocalUserManagement.modal.passwordsDoNotMatch') |
| 192 | }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 193 | </template> |
| 194 | </b-form-invalid-feedback> |
| 195 | </input-password-toggle> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 196 | </b-form-group> |
| 197 | </b-col> |
| 198 | </b-row> |
| 199 | </b-container> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 200 | </b-form> |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 201 | <template v-slot:modal-footer="{ ok, cancel }"> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame^] | 202 | <b-button |
| 203 | variant="secondary" |
| 204 | data-test-id="localUserManagement-button-cancel" |
| 205 | @click="cancel()" |
| 206 | > |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 207 | {{ $t('global.action.cancel') }} |
| 208 | </b-button> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame^] | 209 | <b-button |
| 210 | form="form-user" |
| 211 | data-test-id="localUserManagement-button-submit" |
| 212 | type="submit" |
| 213 | variant="primary" |
| 214 | @click="onOk" |
| 215 | > |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 216 | <template v-if="newUser"> |
| 217 | {{ $t('pageLocalUserManagement.addUser') }} |
| 218 | </template> |
| 219 | <template v-else> |
| 220 | {{ $t('global.action.save') }} |
| 221 | </template> |
| 222 | </b-button> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 223 | </template> |
| 224 | </b-modal> |
| 225 | </template> |
| 226 | |
| 227 | <script> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 228 | import { |
| 229 | required, |
| 230 | maxLength, |
| 231 | minLength, |
| 232 | sameAs, |
| 233 | helpers, |
| 234 | requiredIf |
| 235 | } from 'vuelidate/lib/validators'; |
| 236 | import VuelidateMixin from '../../../components/Mixins/VuelidateMixin.js'; |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 237 | import InputPasswordToggle from '../../../components/Global/InputPasswordToggle'; |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 238 | import Alert from '../../../components/Global/Alert'; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 239 | |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 240 | export default { |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 241 | components: { Alert, InputPasswordToggle }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 242 | mixins: [VuelidateMixin], |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 243 | props: { |
| 244 | user: { |
| 245 | type: Object, |
| 246 | default: null |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 247 | }, |
| 248 | passwordRequirements: { |
| 249 | type: Object, |
| 250 | required: true |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 251 | } |
| 252 | }, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 253 | data() { |
| 254 | return { |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 255 | originalUsername: '', |
| 256 | form: { |
| 257 | status: true, |
| 258 | username: '', |
| 259 | privilege: '', |
| 260 | password: '', |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 261 | passwordConfirmation: '', |
| 262 | manualUnlock: false |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 263 | } |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 264 | }; |
| 265 | }, |
| 266 | computed: { |
| 267 | newUser() { |
| 268 | return this.user ? false : true; |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 269 | }, |
| 270 | accountSettings() { |
| 271 | return this.$store.getters['localUsers/accountSettings']; |
| 272 | }, |
| 273 | manualUnlockPolicy() { |
| 274 | return !this.accountSettings.accountLockoutDuration; |
Yoshie Muranaka | 038a9da | 2020-04-17 11:22:56 -0700 | [diff] [blame] | 275 | }, |
| 276 | privilegeTypes() { |
| 277 | return this.$store.getters['localUsers/accountRoles']; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 278 | } |
| 279 | }, |
| 280 | watch: { |
| 281 | user: function(value) { |
| 282 | if (value === null) return; |
| 283 | this.originalUsername = value.username; |
| 284 | this.form.username = value.username; |
| 285 | this.form.status = value.Enabled; |
| 286 | this.form.privilege = value.privilege; |
| 287 | } |
| 288 | }, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 289 | validations() { |
| 290 | return { |
| 291 | form: { |
| 292 | status: { |
| 293 | required |
| 294 | }, |
| 295 | username: { |
| 296 | required, |
| 297 | maxLength: maxLength(16), |
| 298 | pattern: helpers.regex('pattern', /^([a-zA-Z_][a-zA-Z0-9_]*)/) |
| 299 | }, |
| 300 | privilege: { |
| 301 | required |
| 302 | }, |
| 303 | password: { |
| 304 | required: requiredIf(function() { |
| 305 | return this.requirePassword(); |
| 306 | }), |
| 307 | minLength: minLength(this.passwordRequirements.minLength), |
| 308 | maxLength: maxLength(this.passwordRequirements.maxLength) |
| 309 | }, |
| 310 | passwordConfirmation: { |
| 311 | required: requiredIf(function() { |
| 312 | return this.requirePassword(); |
| 313 | }), |
| 314 | sameAsPassword: sameAs('password') |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 315 | }, |
| 316 | manualUnlock: {} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 317 | } |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 318 | }; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 319 | }, |
| 320 | methods: { |
| 321 | handleSubmit() { |
| 322 | let userData = {}; |
| 323 | |
| 324 | if (this.newUser) { |
| 325 | this.$v.$touch(); |
| 326 | if (this.$v.$invalid) return; |
| 327 | userData.username = this.form.username; |
| 328 | userData.status = this.form.status; |
| 329 | userData.privilege = this.form.privilege; |
| 330 | userData.password = this.form.password; |
| 331 | } else { |
| 332 | if (this.$v.$invalid) return; |
| 333 | userData.originalUsername = this.originalUsername; |
| 334 | if (this.$v.form.status.$dirty) { |
| 335 | userData.status = this.form.status; |
| 336 | } |
| 337 | if (this.$v.form.username.$dirty) { |
| 338 | userData.username = this.form.username; |
| 339 | } |
| 340 | if (this.$v.form.privilege.$dirty) { |
| 341 | userData.privilege = this.form.privilege; |
| 342 | } |
| 343 | if (this.$v.form.password.$dirty) { |
| 344 | userData.password = this.form.password; |
| 345 | } |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 346 | if (this.$v.form.manualUnlock.$dirty) { |
| 347 | // If form manualUnlock control $dirty then |
| 348 | // set user Locked property to false |
| 349 | userData.locked = false; |
| 350 | } |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 351 | if (Object.entries(userData).length === 1) { |
| 352 | this.closeModal(); |
| 353 | return; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | this.$emit('ok', { isNewUser: this.newUser, userData }); |
| 358 | this.closeModal(); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 359 | }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 360 | closeModal() { |
| 361 | this.$nextTick(() => { |
| 362 | this.$refs.modal.hide(); |
| 363 | }); |
| 364 | }, |
| 365 | resetForm() { |
| 366 | this.form.originalUsername = ''; |
| 367 | this.form.status = true; |
| 368 | this.form.username = ''; |
| 369 | this.form.privilege = ''; |
| 370 | this.form.password = ''; |
| 371 | this.form.passwordConfirmation = ''; |
| 372 | this.$v.$reset(); |
Yoshie Muranaka | 791622b | 2020-04-17 13:55:16 -0700 | [diff] [blame] | 373 | this.$emit('hidden'); |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 374 | }, |
| 375 | requirePassword() { |
| 376 | if (this.newUser) return true; |
| 377 | if (this.$v.form.password.$dirty) return true; |
| 378 | if (this.$v.form.passwordConfirmation.$dirty) return true; |
| 379 | return false; |
| 380 | }, |
| 381 | onOk(bvModalEvt) { |
| 382 | // prevent modal close |
| 383 | bvModalEvt.preventDefault(); |
| 384 | this.handleSubmit(); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | }; |
| 388 | </script> |