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"> |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 3 | <template #modal-title> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 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 | > |
Yoshie Muranaka | bc0d61b | 2020-11-02 14:36:27 -0800 | [diff] [blame] | 117 | <template #first> |
| 118 | <b-form-select-option :value="null" disabled> |
| 119 | {{ $t('global.form.selectAnOption') }} |
| 120 | </b-form-select-option> |
| 121 | </template> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 122 | </b-form-select> |
| 123 | <b-form-invalid-feedback role="alert"> |
| 124 | <template v-if="!$v.form.privilege.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 125 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 126 | </template> |
| 127 | </b-form-invalid-feedback> |
| 128 | </b-form-group> |
| 129 | </b-col> |
| 130 | <b-col> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 131 | <b-form-group |
| 132 | :label="$t('pageLocalUserManagement.modal.userPassword')" |
| 133 | label-for="password" |
| 134 | > |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 135 | <b-form-text id="password-help-block"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 136 | {{ |
| 137 | $t('pageLocalUserManagement.modal.passwordMustBeBetween', { |
| 138 | min: passwordRequirements.minLength, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 139 | max: passwordRequirements.maxLength, |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 140 | }) |
| 141 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 142 | </b-form-text> |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 143 | <input-password-toggle> |
| 144 | <b-form-input |
| 145 | id="password" |
| 146 | v-model="form.password" |
| 147 | type="password" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 148 | data-test-id="localUserManagement-input-password" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 149 | aria-describedby="password-help-block" |
| 150 | :state="getValidationState($v.form.password)" |
Dixsie Wolmers | 5ea1678 | 2020-07-27 17:50:43 -0500 | [diff] [blame] | 151 | class="form-control-with-button" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 152 | @input="$v.form.password.$touch()" |
| 153 | /> |
| 154 | <b-form-invalid-feedback role="alert"> |
| 155 | <template v-if="!$v.form.password.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 156 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 157 | </template> |
| 158 | <template |
| 159 | v-if=" |
| 160 | !$v.form.password.minLength || !$v.form.password.maxLength |
| 161 | " |
| 162 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 163 | {{ |
| 164 | $t( |
| 165 | 'pageLocalUserManagement.modal.passwordMustBeBetween', |
| 166 | { |
| 167 | min: passwordRequirements.minLength, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 168 | max: passwordRequirements.maxLength, |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 169 | } |
| 170 | ) |
| 171 | }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 172 | </template> |
| 173 | </b-form-invalid-feedback> |
| 174 | </input-password-toggle> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 175 | </b-form-group> |
| 176 | <b-form-group |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 177 | :label="$t('pageLocalUserManagement.modal.confirmUserPassword')" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 178 | label-for="password-confirmation" |
| 179 | > |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 180 | <input-password-toggle> |
| 181 | <b-form-input |
| 182 | id="password-confirmation" |
| 183 | v-model="form.passwordConfirmation" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 184 | data-test-id="localUserManagement-input-passwordConfirmation" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 185 | type="password" |
| 186 | :state="getValidationState($v.form.passwordConfirmation)" |
Dixsie Wolmers | 5ea1678 | 2020-07-27 17:50:43 -0500 | [diff] [blame] | 187 | class="form-control-with-button" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 188 | @input="$v.form.passwordConfirmation.$touch()" |
| 189 | /> |
| 190 | <b-form-invalid-feedback role="alert"> |
| 191 | <template v-if="!$v.form.passwordConfirmation.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 192 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 193 | </template> |
| 194 | <template |
| 195 | v-else-if="!$v.form.passwordConfirmation.sameAsPassword" |
| 196 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 197 | {{ |
| 198 | $t('pageLocalUserManagement.modal.passwordsDoNotMatch') |
| 199 | }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 200 | </template> |
| 201 | </b-form-invalid-feedback> |
| 202 | </input-password-toggle> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 203 | </b-form-group> |
| 204 | </b-col> |
| 205 | </b-row> |
| 206 | </b-container> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 207 | </b-form> |
Sukanya Pandey | 1837503 | 2020-10-30 21:13:06 +0530 | [diff] [blame] | 208 | <template #modal-footer="{ cancel }"> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 209 | <b-button |
| 210 | variant="secondary" |
| 211 | data-test-id="localUserManagement-button-cancel" |
| 212 | @click="cancel()" |
| 213 | > |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 214 | {{ $t('global.action.cancel') }} |
| 215 | </b-button> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 216 | <b-button |
| 217 | form="form-user" |
| 218 | data-test-id="localUserManagement-button-submit" |
| 219 | type="submit" |
| 220 | variant="primary" |
| 221 | @click="onOk" |
| 222 | > |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 223 | <template v-if="newUser"> |
| 224 | {{ $t('pageLocalUserManagement.addUser') }} |
| 225 | </template> |
| 226 | <template v-else> |
| 227 | {{ $t('global.action.save') }} |
| 228 | </template> |
| 229 | </b-button> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 230 | </template> |
| 231 | </b-modal> |
| 232 | </template> |
| 233 | |
| 234 | <script> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 235 | import { |
| 236 | required, |
| 237 | maxLength, |
| 238 | minLength, |
| 239 | sameAs, |
| 240 | helpers, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 241 | requiredIf, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 242 | } from 'vuelidate/lib/validators'; |
SurenNeware | 6185909 | 2020-10-01 09:37:32 +0530 | [diff] [blame] | 243 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
| 244 | import InputPasswordToggle from '@/components/Global/InputPasswordToggle'; |
| 245 | import Alert from '@/components/Global/Alert'; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 246 | |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 247 | export default { |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 248 | components: { Alert, InputPasswordToggle }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 249 | mixins: [VuelidateMixin], |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 250 | props: { |
| 251 | user: { |
| 252 | type: Object, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 253 | default: null, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 254 | }, |
| 255 | passwordRequirements: { |
| 256 | type: Object, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 257 | required: true, |
| 258 | }, |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 259 | }, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 260 | data() { |
| 261 | return { |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 262 | originalUsername: '', |
| 263 | form: { |
| 264 | status: true, |
| 265 | username: '', |
Yoshie Muranaka | bc0d61b | 2020-11-02 14:36:27 -0800 | [diff] [blame] | 266 | privilege: null, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 267 | password: '', |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 268 | passwordConfirmation: '', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 269 | manualUnlock: false, |
| 270 | }, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 271 | }; |
| 272 | }, |
| 273 | computed: { |
| 274 | newUser() { |
| 275 | return this.user ? false : true; |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 276 | }, |
| 277 | accountSettings() { |
| 278 | return this.$store.getters['localUsers/accountSettings']; |
| 279 | }, |
| 280 | manualUnlockPolicy() { |
| 281 | return !this.accountSettings.accountLockoutDuration; |
Yoshie Muranaka | 038a9da | 2020-04-17 11:22:56 -0700 | [diff] [blame] | 282 | }, |
| 283 | privilegeTypes() { |
| 284 | return this.$store.getters['localUsers/accountRoles']; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 285 | }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 286 | }, |
| 287 | watch: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 288 | user: function (value) { |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 289 | if (value === null) return; |
| 290 | this.originalUsername = value.username; |
| 291 | this.form.username = value.username; |
| 292 | this.form.status = value.Enabled; |
| 293 | this.form.privilege = value.privilege; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 294 | }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 295 | }, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 296 | validations() { |
| 297 | return { |
| 298 | form: { |
| 299 | status: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 300 | required, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 301 | }, |
| 302 | username: { |
| 303 | required, |
| 304 | maxLength: maxLength(16), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 305 | pattern: helpers.regex('pattern', /^([a-zA-Z_][a-zA-Z0-9_]*)/), |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 306 | }, |
| 307 | privilege: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 308 | required, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 309 | }, |
| 310 | password: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 311 | required: requiredIf(function () { |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 312 | return this.requirePassword(); |
| 313 | }), |
| 314 | minLength: minLength(this.passwordRequirements.minLength), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 315 | maxLength: maxLength(this.passwordRequirements.maxLength), |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 316 | }, |
| 317 | passwordConfirmation: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 318 | required: requiredIf(function () { |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 319 | return this.requirePassword(); |
| 320 | }), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 321 | sameAsPassword: sameAs('password'), |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 322 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 323 | manualUnlock: {}, |
| 324 | }, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 325 | }; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 326 | }, |
| 327 | methods: { |
| 328 | handleSubmit() { |
| 329 | let userData = {}; |
| 330 | |
| 331 | if (this.newUser) { |
| 332 | this.$v.$touch(); |
| 333 | if (this.$v.$invalid) return; |
| 334 | userData.username = this.form.username; |
| 335 | userData.status = this.form.status; |
| 336 | userData.privilege = this.form.privilege; |
| 337 | userData.password = this.form.password; |
| 338 | } else { |
| 339 | if (this.$v.$invalid) return; |
| 340 | userData.originalUsername = this.originalUsername; |
| 341 | if (this.$v.form.status.$dirty) { |
| 342 | userData.status = this.form.status; |
| 343 | } |
| 344 | if (this.$v.form.username.$dirty) { |
| 345 | userData.username = this.form.username; |
| 346 | } |
| 347 | if (this.$v.form.privilege.$dirty) { |
| 348 | userData.privilege = this.form.privilege; |
| 349 | } |
| 350 | if (this.$v.form.password.$dirty) { |
| 351 | userData.password = this.form.password; |
| 352 | } |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 353 | if (this.$v.form.manualUnlock.$dirty) { |
| 354 | // If form manualUnlock control $dirty then |
| 355 | // set user Locked property to false |
| 356 | userData.locked = false; |
| 357 | } |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 358 | if (Object.entries(userData).length === 1) { |
| 359 | this.closeModal(); |
| 360 | return; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | this.$emit('ok', { isNewUser: this.newUser, userData }); |
| 365 | this.closeModal(); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 366 | }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 367 | closeModal() { |
| 368 | this.$nextTick(() => { |
| 369 | this.$refs.modal.hide(); |
| 370 | }); |
| 371 | }, |
| 372 | resetForm() { |
| 373 | this.form.originalUsername = ''; |
| 374 | this.form.status = true; |
| 375 | this.form.username = ''; |
Yoshie Muranaka | bc0d61b | 2020-11-02 14:36:27 -0800 | [diff] [blame] | 376 | this.form.privilege = null; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 377 | this.form.password = ''; |
| 378 | this.form.passwordConfirmation = ''; |
| 379 | this.$v.$reset(); |
Yoshie Muranaka | 791622b | 2020-04-17 13:55:16 -0700 | [diff] [blame] | 380 | this.$emit('hidden'); |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 381 | }, |
| 382 | requirePassword() { |
| 383 | if (this.newUser) return true; |
| 384 | if (this.$v.form.password.$dirty) return true; |
| 385 | if (this.$v.form.passwordConfirmation.$dirty) return true; |
| 386 | return false; |
| 387 | }, |
| 388 | onOk(bvModalEvt) { |
| 389 | // prevent modal close |
| 390 | bvModalEvt.preventDefault(); |
| 391 | this.handleSubmit(); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 392 | }, |
| 393 | }, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 394 | }; |
| 395 | </script> |