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