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"> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 5 | {{ $t('pageUserManagement.addUser') }} |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 6 | </template> |
| 7 | <template v-else> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 8 | {{ $t('pageUserManagement.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"> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 18 | {{ $t('pageUserManagement.modal.accountLocked') }} |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 19 | </template> |
| 20 | <template v-else> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 21 | {{ $t('pageUserManagement.modal.clickSaveToUnlockAccount') }} |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 22 | </template> |
| 23 | </alert> |
| 24 | </b-col> |
| 25 | <b-col sm="3"> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 26 | <input |
| 27 | v-model="form.manualUnlock" |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 28 | data-test-id="userManagement-input-manualUnlock" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 29 | type="hidden" |
| 30 | value="false" |
| 31 | /> |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 32 | <b-button |
| 33 | variant="primary" |
| 34 | :disabled="$v.form.manualUnlock.$dirty" |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 35 | data-test-id="userManagement-button-manualUnlock" |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 36 | @click="$v.form.manualUnlock.$touch()" |
| 37 | > |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 38 | {{ $t('pageUserManagement.modal.unlock') }} |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 39 | </b-button> |
| 40 | </b-col> |
| 41 | </b-row> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 42 | <b-row> |
| 43 | <b-col> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 44 | <b-form-group :label="$t('pageUserManagement.modal.accountStatus')"> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 45 | <b-form-radio |
| 46 | v-model="form.status" |
| 47 | name="user-status" |
| 48 | :value="true" |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 49 | data-test-id="userManagement-radioButton-statusEnabled" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 50 | @input="$v.form.status.$touch()" |
| 51 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 52 | {{ $t('global.status.enabled') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 53 | </b-form-radio> |
| 54 | <b-form-radio |
| 55 | v-model="form.status" |
| 56 | name="user-status" |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 57 | data-test-id="userManagement-radioButton-statusDisabled" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 58 | :value="false" |
Sivaprabu Ganesan | 2897447 | 2023-01-05 18:52:51 +0530 | [diff] [blame] | 59 | :disabled="!newUser && originalUsername === disabled" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 60 | @input="$v.form.status.$touch()" |
| 61 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 62 | {{ $t('global.status.disabled') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 63 | </b-form-radio> |
| 64 | </b-form-group> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 65 | <b-form-group |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 66 | :label="$t('pageUserManagement.modal.username')" |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 67 | label-for="username" |
| 68 | > |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 69 | <b-form-text id="username-help-block"> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 70 | {{ $t('pageUserManagement.modal.cannotStartWithANumber') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 71 | <br /> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 72 | {{ |
| 73 | $t( |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 74 | 'pageUserManagement.modal.noSpecialCharactersExceptUnderscore' |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 75 | ) |
| 76 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 77 | </b-form-text> |
| 78 | <b-form-input |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 79 | id="username" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 80 | v-model="form.username" |
| 81 | type="text" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 82 | aria-describedby="username-help-block" |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 83 | data-test-id="userManagement-input-username" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 84 | :state="getValidationState($v.form.username)" |
Sivaprabu Ganesan | 2897447 | 2023-01-05 18:52:51 +0530 | [diff] [blame] | 85 | :disabled="!newUser && originalUsername === disabled" |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 86 | @input="$v.form.username.$touch()" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 87 | /> |
| 88 | <b-form-invalid-feedback role="alert"> |
| 89 | <template v-if="!$v.form.username.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 90 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 91 | </template> |
| 92 | <template v-else-if="!$v.form.username.maxLength"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 93 | {{ |
| 94 | $t('global.form.lengthMustBeBetween', { min: 1, max: 16 }) |
| 95 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 96 | </template> |
| 97 | <template v-else-if="!$v.form.username.pattern"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 98 | {{ $t('global.form.invalidFormat') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 99 | </template> |
| 100 | </b-form-invalid-feedback> |
| 101 | </b-form-group> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 102 | <b-form-group |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 103 | :label="$t('pageUserManagement.modal.privilege')" |
Yoshie Muranaka | a4b9e40 | 2020-03-06 14:59:46 -0800 | [diff] [blame] | 104 | label-for="privilege" |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 105 | > |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 106 | <b-form-select |
Yoshie Muranaka | a4b9e40 | 2020-03-06 14:59:46 -0800 | [diff] [blame] | 107 | id="privilege" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 108 | v-model="form.privilege" |
| 109 | :options="privilegeTypes" |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 110 | data-test-id="userManagement-select-privilege" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 111 | :state="getValidationState($v.form.privilege)" |
| 112 | @input="$v.form.privilege.$touch()" |
| 113 | > |
Yoshie Muranaka | bc0d61b | 2020-11-02 14:36:27 -0800 | [diff] [blame] | 114 | <template #first> |
| 115 | <b-form-select-option :value="null" disabled> |
| 116 | {{ $t('global.form.selectAnOption') }} |
| 117 | </b-form-select-option> |
| 118 | </template> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 119 | </b-form-select> |
| 120 | <b-form-invalid-feedback role="alert"> |
| 121 | <template v-if="!$v.form.privilege.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 122 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 123 | </template> |
| 124 | </b-form-invalid-feedback> |
| 125 | </b-form-group> |
| 126 | </b-col> |
| 127 | <b-col> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 128 | <b-form-group |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 129 | :label="$t('pageUserManagement.modal.userPassword')" |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 130 | label-for="password" |
| 131 | > |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 132 | <b-form-text id="password-help-block"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 133 | {{ |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 134 | $t('pageUserManagement.modal.passwordMustBeBetween', { |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 135 | min: passwordRequirements.minLength, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 136 | max: passwordRequirements.maxLength, |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 137 | }) |
| 138 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 139 | </b-form-text> |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 140 | <input-password-toggle> |
| 141 | <b-form-input |
| 142 | id="password" |
| 143 | v-model="form.password" |
| 144 | type="password" |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 145 | data-test-id="userManagement-input-password" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 146 | aria-describedby="password-help-block" |
| 147 | :state="getValidationState($v.form.password)" |
Dixsie Wolmers | 5ea1678 | 2020-07-27 17:50:43 -0500 | [diff] [blame] | 148 | class="form-control-with-button" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 149 | @input="$v.form.password.$touch()" |
| 150 | /> |
| 151 | <b-form-invalid-feedback role="alert"> |
| 152 | <template v-if="!$v.form.password.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 153 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 154 | </template> |
| 155 | <template |
| 156 | v-if=" |
| 157 | !$v.form.password.minLength || !$v.form.password.maxLength |
| 158 | " |
| 159 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 160 | {{ |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 161 | $t('pageUserManagement.modal.passwordMustBeBetween', { |
| 162 | min: passwordRequirements.minLength, |
| 163 | max: passwordRequirements.maxLength, |
| 164 | }) |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 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 |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 171 | :label="$t('pageUserManagement.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" |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 178 | data-test-id="userManagement-input-passwordConfirmation" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 179 | type="password" |
| 180 | :state="getValidationState($v.form.passwordConfirmation)" |
Dixsie Wolmers | 5ea1678 | 2020-07-27 17:50:43 -0500 | [diff] [blame] | 181 | class="form-control-with-button" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 182 | @input="$v.form.passwordConfirmation.$touch()" |
| 183 | /> |
| 184 | <b-form-invalid-feedback role="alert"> |
| 185 | <template v-if="!$v.form.passwordConfirmation.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 186 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 187 | </template> |
| 188 | <template |
| 189 | v-else-if="!$v.form.passwordConfirmation.sameAsPassword" |
| 190 | > |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 191 | {{ $t('pageUserManagement.modal.passwordsDoNotMatch') }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 192 | </template> |
| 193 | </b-form-invalid-feedback> |
| 194 | </input-password-toggle> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 195 | </b-form-group> |
| 196 | </b-col> |
| 197 | </b-row> |
| 198 | </b-container> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 199 | </b-form> |
Sukanya Pandey | 1837503 | 2020-10-30 21:13:06 +0530 | [diff] [blame] | 200 | <template #modal-footer="{ cancel }"> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 201 | <b-button |
| 202 | variant="secondary" |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 203 | data-test-id="userManagement-button-cancel" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 204 | @click="cancel()" |
| 205 | > |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 206 | {{ $t('global.action.cancel') }} |
| 207 | </b-button> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 208 | <b-button |
| 209 | form="form-user" |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 210 | data-test-id="userManagement-button-submit" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 211 | type="submit" |
| 212 | variant="primary" |
| 213 | @click="onOk" |
| 214 | > |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 215 | <template v-if="newUser"> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 216 | {{ $t('pageUserManagement.addUser') }} |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 217 | </template> |
| 218 | <template v-else> |
| 219 | {{ $t('global.action.save') }} |
| 220 | </template> |
| 221 | </b-button> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 222 | </template> |
| 223 | </b-modal> |
| 224 | </template> |
| 225 | |
| 226 | <script> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 227 | import { |
| 228 | required, |
| 229 | maxLength, |
| 230 | minLength, |
| 231 | sameAs, |
| 232 | helpers, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 233 | requiredIf, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 234 | } from 'vuelidate/lib/validators'; |
SurenNeware | 6185909 | 2020-10-01 09:37:32 +0530 | [diff] [blame] | 235 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
| 236 | import InputPasswordToggle from '@/components/Global/InputPasswordToggle'; |
| 237 | import Alert from '@/components/Global/Alert'; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 238 | |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 239 | export default { |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 240 | components: { Alert, InputPasswordToggle }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 241 | mixins: [VuelidateMixin], |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 242 | props: { |
| 243 | user: { |
| 244 | type: Object, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 245 | default: null, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 246 | }, |
| 247 | passwordRequirements: { |
| 248 | type: Object, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 249 | required: true, |
| 250 | }, |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 251 | }, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 252 | data() { |
| 253 | return { |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 254 | originalUsername: '', |
| 255 | form: { |
| 256 | status: true, |
| 257 | username: '', |
Yoshie Muranaka | bc0d61b | 2020-11-02 14:36:27 -0800 | [diff] [blame] | 258 | privilege: null, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 259 | password: '', |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 260 | passwordConfirmation: '', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 261 | manualUnlock: false, |
| 262 | }, |
Sivaprabu Ganesan | 2897447 | 2023-01-05 18:52:51 +0530 | [diff] [blame] | 263 | disabled: this.$store.getters['global/username'], |
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() { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 271 | return this.$store.getters['userManagement/accountSettings']; |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 272 | }, |
| 273 | manualUnlockPolicy() { |
| 274 | return !this.accountSettings.accountLockoutDuration; |
Yoshie Muranaka | 038a9da | 2020-04-17 11:22:56 -0700 | [diff] [blame] | 275 | }, |
| 276 | privilegeTypes() { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 277 | return this.$store.getters['userManagement/accountRoles']; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 278 | }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 279 | }, |
| 280 | watch: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 281 | user: function (value) { |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 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; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 287 | }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 288 | }, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 289 | validations() { |
| 290 | return { |
| 291 | form: { |
| 292 | status: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 293 | required, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 294 | }, |
| 295 | username: { |
| 296 | required, |
| 297 | maxLength: maxLength(16), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 298 | pattern: helpers.regex('pattern', /^([a-zA-Z_][a-zA-Z0-9_]*)/), |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 299 | }, |
| 300 | privilege: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 301 | required, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 302 | }, |
| 303 | password: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 304 | required: requiredIf(function () { |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 305 | return this.requirePassword(); |
| 306 | }), |
| 307 | minLength: minLength(this.passwordRequirements.minLength), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 308 | maxLength: maxLength(this.passwordRequirements.maxLength), |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 309 | }, |
| 310 | passwordConfirmation: { |
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 | }), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 314 | sameAsPassword: sameAs('password'), |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 315 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 316 | manualUnlock: {}, |
| 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 = ''; |
Yoshie Muranaka | bc0d61b | 2020-11-02 14:36:27 -0800 | [diff] [blame] | 369 | this.form.privilege = null; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 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(); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 385 | }, |
| 386 | }, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 387 | }; |
| 388 | </script> |