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