blob: 3b334871f65a8b0bec208a00374deed690ee6bcb [file] [log] [blame]
Yoshie Muranaka463a5702019-12-04 09:09:36 -08001<template>
Yoshie Muranaka0b8cffd2020-06-23 08:44:54 -07002 <b-modal id="modal-user" ref="modal" @hidden="resetForm">
Derick Montague602e98a2020-10-21 16:20:00 -05003 <template #modal-title>
Yoshie Muranaka463a5702019-12-04 09:09:36 -08004 <template v-if="newUser">
Sandeepa Singhb4406162021-07-26 15:05:39 +05305 {{ $t('pageUserManagement.addUser') }}
Yoshie Muranaka463a5702019-12-04 09:09:36 -08006 </template>
7 <template v-else>
Sandeepa Singhb4406162021-07-26 15:05:39 +05308 {{ $t('pageUserManagement.editUser') }}
Yoshie Muranaka463a5702019-12-04 09:09:36 -08009 </template>
10 </template>
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -070011 <b-form id="form-user" novalidate @submit.prevent="handleSubmit">
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080012 <b-container>
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -070013 <!-- 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>
Surya Vde23ea22024-07-11 15:19:46 +053017 <template v-if="!v$.form.manualUnlock.$dirty">
Sandeepa Singhb4406162021-07-26 15:05:39 +053018 {{ $t('pageUserManagement.modal.accountLocked') }}
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -070019 </template>
20 <template v-else>
Sandeepa Singhb4406162021-07-26 15:05:39 +053021 {{ $t('pageUserManagement.modal.clickSaveToUnlockAccount') }}
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -070022 </template>
23 </alert>
24 </b-col>
25 <b-col sm="3">
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050026 <input
27 v-model="form.manualUnlock"
Sandeepa Singhb4406162021-07-26 15:05:39 +053028 data-test-id="userManagement-input-manualUnlock"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050029 type="hidden"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -050030 />
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -070031 <b-button
32 variant="primary"
Surya Vde23ea22024-07-11 15:19:46 +053033 :disabled="v$.form.manualUnlock.$dirty"
Sandeepa Singhb4406162021-07-26 15:05:39 +053034 data-test-id="userManagement-button-manualUnlock"
Surya Vde23ea22024-07-11 15:19:46 +053035 @click="v$.form.manualUnlock.$touch()"
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -070036 >
Sandeepa Singhb4406162021-07-26 15:05:39 +053037 {{ $t('pageUserManagement.modal.unlock') }}
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -070038 </b-button>
39 </b-col>
40 </b-row>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080041 <b-row>
42 <b-col>
Sandeepa Singhb4406162021-07-26 15:05:39 +053043 <b-form-group :label="$t('pageUserManagement.modal.accountStatus')">
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080044 <b-form-radio
45 v-model="form.status"
46 name="user-status"
47 :value="true"
Sandeepa Singhb4406162021-07-26 15:05:39 +053048 data-test-id="userManagement-radioButton-statusEnabled"
Surya Vde23ea22024-07-11 15:19:46 +053049 @input="v$.form.status.$touch()"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080050 >
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080051 {{ $t('global.status.enabled') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080052 </b-form-radio>
53 <b-form-radio
54 v-model="form.status"
55 name="user-status"
Sandeepa Singhb4406162021-07-26 15:05:39 +053056 data-test-id="userManagement-radioButton-statusDisabled"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080057 :value="false"
Sivaprabu Ganesan28974472023-01-05 18:52:51 +053058 :disabled="!newUser && originalUsername === disabled"
Surya Vde23ea22024-07-11 15:19:46 +053059 @input="v$.form.status.$touch()"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080060 >
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080061 {{ $t('global.status.disabled') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080062 </b-form-radio>
63 </b-form-group>
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080064 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +053065 :label="$t('pageUserManagement.modal.username')"
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080066 label-for="username"
67 >
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080068 <b-form-text id="username-help-block">
Sandeepa Singhb4406162021-07-26 15:05:39 +053069 {{ $t('pageUserManagement.modal.cannotStartWithANumber') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080070 <br />
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080071 {{
72 $t(
Ed Tanous81323992024-02-27 11:26:24 -080073 'pageUserManagement.modal.noSpecialCharactersExceptUnderscore',
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080074 )
75 }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080076 </b-form-text>
77 <b-form-input
Derick Montague09e45cd2020-01-23 15:45:57 -060078 id="username"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080079 v-model="form.username"
80 type="text"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080081 aria-describedby="username-help-block"
Sandeepa Singhb4406162021-07-26 15:05:39 +053082 data-test-id="userManagement-input-username"
Surya Vde23ea22024-07-11 15:19:46 +053083 :state="getValidationState(v$.form.username)"
Sivaprabu Ganesan28974472023-01-05 18:52:51 +053084 :disabled="!newUser && originalUsername === disabled"
Surya Vde23ea22024-07-11 15:19:46 +053085 @input="v$.form.username.$touch()"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080086 />
87 <b-form-invalid-feedback role="alert">
Surya Venkatesan90300e92024-08-01 12:40:20 +053088 <template v-if="v$.form.username.required.$invalid">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080089 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080090 </template>
Surya Venkatesan90300e92024-08-01 12:40:20 +053091 <template v-else-if="v$.form.username.maxLength.$invalid">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080092 {{
93 $t('global.form.lengthMustBeBetween', { min: 1, max: 16 })
94 }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080095 </template>
Surya Venkatesan90300e92024-08-01 12:40:20 +053096 <template v-else-if="v$.form.username.pattern.$invalid">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080097 {{ $t('global.form.invalidFormat') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080098 </template>
99 </b-form-invalid-feedback>
100 </b-form-group>
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800101 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +0530102 :label="$t('pageUserManagement.modal.privilege')"
Yoshie Muranakaa4b9e402020-03-06 14:59:46 -0800103 label-for="privilege"
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800104 >
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800105 <b-form-select
Yoshie Muranakaa4b9e402020-03-06 14:59:46 -0800106 id="privilege"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800107 v-model="form.privilege"
108 :options="privilegeTypes"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530109 data-test-id="userManagement-select-privilege"
Surya Vde23ea22024-07-11 15:19:46 +0530110 :state="getValidationState(v$.form.privilege)"
aravinths12b021032024-05-22 21:29:50 +0530111 :disabled="!newUser && originalUsername === 'root'"
Surya Vde23ea22024-07-11 15:19:46 +0530112 @input="v$.form.privilege.$touch()"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800113 >
Yoshie Muranakabc0d61b2020-11-02 14:36:27 -0800114 <template #first>
115 <b-form-select-option :value="null" disabled>
116 {{ $t('global.form.selectAnOption') }}
117 </b-form-select-option>
118 </template>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800119 </b-form-select>
120 <b-form-invalid-feedback role="alert">
Surya Venkatesan90300e92024-08-01 12:40:20 +0530121 <template v-if="v$.form.privilege.required.$invalid">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800122 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800123 </template>
124 </b-form-invalid-feedback>
125 </b-form-group>
126 </b-col>
127 <b-col>
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800128 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +0530129 :label="$t('pageUserManagement.modal.userPassword')"
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800130 label-for="password"
131 >
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800132 <b-form-text id="password-help-block">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800133 {{
Sandeepa Singhb4406162021-07-26 15:05:39 +0530134 $t('pageUserManagement.modal.passwordMustBeBetween', {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800135 min: passwordRequirements.minLength,
Derick Montague602e98a2020-10-21 16:20:00 -0500136 max: passwordRequirements.maxLength,
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800137 })
138 }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800139 </b-form-text>
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800140 <input-password-toggle>
141 <b-form-input
142 id="password"
143 v-model="form.password"
144 type="password"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530145 data-test-id="userManagement-input-password"
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800146 aria-describedby="password-help-block"
Surya Vde23ea22024-07-11 15:19:46 +0530147 :state="getValidationState(v$.form.password)"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -0500148 class="form-control-with-button"
Surya Vde23ea22024-07-11 15:19:46 +0530149 @input="v$.form.password.$touch()"
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800150 />
151 <b-form-invalid-feedback role="alert">
Surya Venkatesan90300e92024-08-01 12:40:20 +0530152 <template v-if="v$.form.password.required.$invalid">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800153 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800154 </template>
155 <template
156 v-if="
Surya Venkatesan90300e92024-08-01 12:40:20 +0530157 v$.form.password.minLength.$invalid ||
158 v$.form.password.maxLength.$invalid
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800159 "
160 >
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800161 {{
Sandeepa Singhb4406162021-07-26 15:05:39 +0530162 $t('pageUserManagement.modal.passwordMustBeBetween', {
163 min: passwordRequirements.minLength,
164 max: passwordRequirements.maxLength,
165 })
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800166 }}
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800167 </template>
168 </b-form-invalid-feedback>
169 </input-password-toggle>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800170 </b-form-group>
171 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +0530172 :label="$t('pageUserManagement.modal.confirmUserPassword')"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800173 label-for="password-confirmation"
174 >
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800175 <input-password-toggle>
176 <b-form-input
177 id="password-confirmation"
178 v-model="form.passwordConfirmation"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530179 data-test-id="userManagement-input-passwordConfirmation"
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800180 type="password"
Surya Vde23ea22024-07-11 15:19:46 +0530181 :state="getValidationState(v$.form.passwordConfirmation)"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -0500182 class="form-control-with-button"
Surya Vde23ea22024-07-11 15:19:46 +0530183 @input="v$.form.passwordConfirmation.$touch()"
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800184 />
185 <b-form-invalid-feedback role="alert">
Surya Venkatesan90300e92024-08-01 12:40:20 +0530186 <template
187 v-if="v$.form.passwordConfirmation.required.$invalid"
188 >
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800189 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800190 </template>
191 <template
Surya Venkatesan90300e92024-08-01 12:40:20 +0530192 v-else-if="
193 v$.form.passwordConfirmation.sameAsPassword.$invalid
194 "
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800195 >
Sandeepa Singhb4406162021-07-26 15:05:39 +0530196 {{ $t('pageUserManagement.modal.passwordsDoNotMatch') }}
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800197 </template>
198 </b-form-invalid-feedback>
199 </input-password-toggle>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800200 </b-form-group>
201 </b-col>
202 </b-row>
203 </b-container>
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800204 </b-form>
Sukanya Pandey18375032020-10-30 21:13:06 +0530205 <template #modal-footer="{ cancel }">
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500206 <b-button
207 variant="secondary"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530208 data-test-id="userManagement-button-cancel"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500209 @click="cancel()"
210 >
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700211 {{ $t('global.action.cancel') }}
212 </b-button>
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500213 <b-button
214 form="form-user"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530215 data-test-id="userManagement-button-submit"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500216 type="submit"
217 variant="primary"
218 @click="onOk"
219 >
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700220 <template v-if="newUser">
Sandeepa Singhb4406162021-07-26 15:05:39 +0530221 {{ $t('pageUserManagement.addUser') }}
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700222 </template>
223 <template v-else>
224 {{ $t('global.action.save') }}
225 </template>
226 </b-button>
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800227 </template>
228 </b-modal>
229</template>
230
231<script>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800232import {
233 required,
234 maxLength,
235 minLength,
Derick Montague602e98a2020-10-21 16:20:00 -0500236 requiredIf,
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700237} from '@vuelidate/validators';
Surya Venkatesan90300e92024-08-01 12:40:20 +0530238import { helpers, sameAs } from 'vuelidate/lib/validators';
SurenNeware61859092020-10-01 09:37:32 +0530239import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700240import { useVuelidate } from '@vuelidate/core';
241
SurenNeware61859092020-10-01 09:37:32 +0530242import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
243import Alert from '@/components/Global/Alert';
Surya Vde23ea22024-07-11 15:19:46 +0530244import { useI18n } from 'vue-i18n';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800245
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800246export default {
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700247 components: { Alert, InputPasswordToggle },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800248 mixins: [VuelidateMixin],
Derick Montague09e45cd2020-01-23 15:45:57 -0600249 props: {
250 user: {
251 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -0500252 default: null,
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800253 },
254 passwordRequirements: {
255 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -0500256 required: true,
257 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600258 },
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700259 setup() {
260 return {
261 v$: useVuelidate(),
262 };
263 },
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800264 data() {
265 return {
Surya Vde23ea22024-07-11 15:19:46 +0530266 $t: useI18n().t,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800267 originalUsername: '',
268 form: {
269 status: true,
270 username: '',
Yoshie Muranakabc0d61b2020-11-02 14:36:27 -0800271 privilege: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800272 password: '',
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700273 passwordConfirmation: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500274 manualUnlock: false,
275 },
Sivaprabu Ganesan28974472023-01-05 18:52:51 +0530276 disabled: this.$store.getters['global/username'],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800277 };
278 },
279 computed: {
280 newUser() {
281 return this.user ? false : true;
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700282 },
283 accountSettings() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530284 return this.$store.getters['userManagement/accountSettings'];
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700285 },
286 manualUnlockPolicy() {
287 return !this.accountSettings.accountLockoutDuration;
Yoshie Muranaka038a9da2020-04-17 11:22:56 -0700288 },
289 privilegeTypes() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530290 return this.$store.getters['userManagement/accountRoles'];
Derick Montague602e98a2020-10-21 16:20:00 -0500291 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800292 },
293 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -0500294 user: function (value) {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800295 if (value === null) return;
296 this.originalUsername = value.username;
297 this.form.username = value.username;
298 this.form.status = value.Enabled;
299 this.form.privilege = value.privilege;
Derick Montague602e98a2020-10-21 16:20:00 -0500300 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800301 },
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800302 validations() {
303 return {
304 form: {
305 status: {
Derick Montague602e98a2020-10-21 16:20:00 -0500306 required,
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800307 },
308 username: {
309 required,
310 maxLength: maxLength(16),
Derick Montague602e98a2020-10-21 16:20:00 -0500311 pattern: helpers.regex('pattern', /^([a-zA-Z_][a-zA-Z0-9_]*)/),
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800312 },
313 privilege: {
Derick Montague602e98a2020-10-21 16:20:00 -0500314 required,
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800315 },
316 password: {
Derick Montague602e98a2020-10-21 16:20:00 -0500317 required: requiredIf(function () {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800318 return this.requirePassword();
319 }),
320 minLength: minLength(this.passwordRequirements.minLength),
Derick Montague602e98a2020-10-21 16:20:00 -0500321 maxLength: maxLength(this.passwordRequirements.maxLength),
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800322 },
323 passwordConfirmation: {
Derick Montague602e98a2020-10-21 16:20:00 -0500324 required: requiredIf(function () {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800325 return this.requirePassword();
326 }),
Derick Montague602e98a2020-10-21 16:20:00 -0500327 sameAsPassword: sameAs('password'),
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700328 },
Derick Montague602e98a2020-10-21 16:20:00 -0500329 manualUnlock: {},
330 },
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800331 };
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800332 },
333 methods: {
334 handleSubmit() {
335 let userData = {};
336
337 if (this.newUser) {
Surya Vde23ea22024-07-11 15:19:46 +0530338 this.v$.$touch();
339 if (this.v$.$invalid) return;
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800340 userData.username = this.form.username;
341 userData.status = this.form.status;
342 userData.privilege = this.form.privilege;
343 userData.password = this.form.password;
344 } else {
Surya Vde23ea22024-07-11 15:19:46 +0530345 if (this.v$.$invalid) return;
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800346 userData.originalUsername = this.originalUsername;
Surya Vde23ea22024-07-11 15:19:46 +0530347 if (this.v$.form.status.$dirty) {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800348 userData.status = this.form.status;
349 }
Surya Vde23ea22024-07-11 15:19:46 +0530350 if (this.v$.form.username.$dirty) {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800351 userData.username = this.form.username;
352 }
Surya Vde23ea22024-07-11 15:19:46 +0530353 if (this.v$.form.privilege.$dirty) {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800354 userData.privilege = this.form.privilege;
355 }
Surya Vde23ea22024-07-11 15:19:46 +0530356 if (this.v$.form.password.$dirty) {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800357 userData.password = this.form.password;
358 }
Surya Vde23ea22024-07-11 15:19:46 +0530359 if (this.v$.form.manualUnlock.$dirty) {
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700360 // If form manualUnlock control $dirty then
361 // set user Locked property to false
362 userData.locked = false;
363 }
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800364 if (Object.entries(userData).length === 1) {
365 this.closeModal();
366 return;
367 }
368 }
369
370 this.$emit('ok', { isNewUser: this.newUser, userData });
371 this.closeModal();
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800372 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800373 closeModal() {
374 this.$nextTick(() => {
375 this.$refs.modal.hide();
376 });
377 },
378 resetForm() {
379 this.form.originalUsername = '';
380 this.form.status = true;
381 this.form.username = '';
Yoshie Muranakabc0d61b2020-11-02 14:36:27 -0800382 this.form.privilege = null;
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800383 this.form.password = '';
384 this.form.passwordConfirmation = '';
Surya Vde23ea22024-07-11 15:19:46 +0530385 this.v$.$reset();
Yoshie Muranaka791622b2020-04-17 13:55:16 -0700386 this.$emit('hidden');
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800387 },
388 requirePassword() {
389 if (this.newUser) return true;
Surya Vde23ea22024-07-11 15:19:46 +0530390 if (this.v$.form.password.$dirty) return true;
391 if (this.v$.form.passwordConfirmation.$dirty) return true;
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800392 return false;
393 },
394 onOk(bvModalEvt) {
395 // prevent modal close
396 bvModalEvt.preventDefault();
397 this.handleSubmit();
Derick Montague602e98a2020-10-21 16:20:00 -0500398 },
399 },
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800400};
401</script>