blob: 44ab516d6b6c07ba2293957c6a25e7dece11a356 [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 Vde23ea22024-07-11 15:19:46 +053088 <template v-if="!v$.form.username.required">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080089 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080090 </template>
Surya Vde23ea22024-07-11 15:19:46 +053091 <template v-else-if="!v$.form.username.maxLength">
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 Vde23ea22024-07-11 15:19:46 +053096 <template v-else-if="!v$.form.username.pattern">
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 Vde23ea22024-07-11 15:19:46 +0530121 <template v-if="!v$.form.privilege.required">
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 Vde23ea22024-07-11 15:19:46 +0530152 <template v-if="!v$.form.password.required">
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 Vde23ea22024-07-11 15:19:46 +0530157 !v$.form.password.minLength || !v$.form.password.maxLength
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800158 "
159 >
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800160 {{
Sandeepa Singhb4406162021-07-26 15:05:39 +0530161 $t('pageUserManagement.modal.passwordMustBeBetween', {
162 min: passwordRequirements.minLength,
163 max: passwordRequirements.maxLength,
164 })
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800165 }}
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800166 </template>
167 </b-form-invalid-feedback>
168 </input-password-toggle>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800169 </b-form-group>
170 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +0530171 :label="$t('pageUserManagement.modal.confirmUserPassword')"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800172 label-for="password-confirmation"
173 >
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800174 <input-password-toggle>
175 <b-form-input
176 id="password-confirmation"
177 v-model="form.passwordConfirmation"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530178 data-test-id="userManagement-input-passwordConfirmation"
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800179 type="password"
Surya Vde23ea22024-07-11 15:19:46 +0530180 :state="getValidationState(v$.form.passwordConfirmation)"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -0500181 class="form-control-with-button"
Surya Vde23ea22024-07-11 15:19:46 +0530182 @input="v$.form.passwordConfirmation.$touch()"
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800183 />
184 <b-form-invalid-feedback role="alert">
Surya Vde23ea22024-07-11 15:19:46 +0530185 <template v-if="!v$.form.passwordConfirmation.required">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800186 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800187 </template>
188 <template
Surya Vde23ea22024-07-11 15:19:46 +0530189 v-else-if="!v$.form.passwordConfirmation.sameAsPassword"
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800190 >
Sandeepa Singhb4406162021-07-26 15:05:39 +0530191 {{ $t('pageUserManagement.modal.passwordsDoNotMatch') }}
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800192 </template>
193 </b-form-invalid-feedback>
194 </input-password-toggle>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800195 </b-form-group>
196 </b-col>
197 </b-row>
198 </b-container>
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800199 </b-form>
Sukanya Pandey18375032020-10-30 21:13:06 +0530200 <template #modal-footer="{ cancel }">
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500201 <b-button
202 variant="secondary"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530203 data-test-id="userManagement-button-cancel"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500204 @click="cancel()"
205 >
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700206 {{ $t('global.action.cancel') }}
207 </b-button>
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500208 <b-button
209 form="form-user"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530210 data-test-id="userManagement-button-submit"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500211 type="submit"
212 variant="primary"
213 @click="onOk"
214 >
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700215 <template v-if="newUser">
Sandeepa Singhb4406162021-07-26 15:05:39 +0530216 {{ $t('pageUserManagement.addUser') }}
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700217 </template>
218 <template v-else>
219 {{ $t('global.action.save') }}
220 </template>
221 </b-button>
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800222 </template>
223 </b-modal>
224</template>
225
226<script>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800227import {
228 required,
229 maxLength,
230 minLength,
231 sameAs,
232 helpers,
Derick Montague602e98a2020-10-21 16:20:00 -0500233 requiredIf,
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700234} from '@vuelidate/validators';
SurenNeware61859092020-10-01 09:37:32 +0530235import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700236import { useVuelidate } from '@vuelidate/core';
237
SurenNeware61859092020-10-01 09:37:32 +0530238import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
239import Alert from '@/components/Global/Alert';
Surya Vde23ea22024-07-11 15:19:46 +0530240import { useI18n } from 'vue-i18n';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800241
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800242export default {
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700243 components: { Alert, InputPasswordToggle },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800244 mixins: [VuelidateMixin],
Derick Montague09e45cd2020-01-23 15:45:57 -0600245 props: {
246 user: {
247 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -0500248 default: null,
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800249 },
250 passwordRequirements: {
251 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -0500252 required: true,
253 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600254 },
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700255 setup() {
256 return {
257 v$: useVuelidate(),
258 };
259 },
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800260 data() {
261 return {
Surya Vde23ea22024-07-11 15:19:46 +0530262 $t: useI18n().t,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800263 originalUsername: '',
264 form: {
265 status: true,
266 username: '',
Yoshie Muranakabc0d61b2020-11-02 14:36:27 -0800267 privilege: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800268 password: '',
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700269 passwordConfirmation: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500270 manualUnlock: false,
271 },
Sivaprabu Ganesan28974472023-01-05 18:52:51 +0530272 disabled: this.$store.getters['global/username'],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800273 };
274 },
275 computed: {
276 newUser() {
277 return this.user ? false : true;
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700278 },
279 accountSettings() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530280 return this.$store.getters['userManagement/accountSettings'];
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700281 },
282 manualUnlockPolicy() {
283 return !this.accountSettings.accountLockoutDuration;
Yoshie Muranaka038a9da2020-04-17 11:22:56 -0700284 },
285 privilegeTypes() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530286 return this.$store.getters['userManagement/accountRoles'];
Derick Montague602e98a2020-10-21 16:20:00 -0500287 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800288 },
289 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -0500290 user: function (value) {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800291 if (value === null) return;
292 this.originalUsername = value.username;
293 this.form.username = value.username;
294 this.form.status = value.Enabled;
295 this.form.privilege = value.privilege;
Derick Montague602e98a2020-10-21 16:20:00 -0500296 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800297 },
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800298 validations() {
299 return {
300 form: {
301 status: {
Derick Montague602e98a2020-10-21 16:20:00 -0500302 required,
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800303 },
304 username: {
305 required,
306 maxLength: maxLength(16),
Derick Montague602e98a2020-10-21 16:20:00 -0500307 pattern: helpers.regex('pattern', /^([a-zA-Z_][a-zA-Z0-9_]*)/),
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800308 },
309 privilege: {
Derick Montague602e98a2020-10-21 16:20:00 -0500310 required,
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800311 },
312 password: {
Derick Montague602e98a2020-10-21 16:20:00 -0500313 required: requiredIf(function () {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800314 return this.requirePassword();
315 }),
316 minLength: minLength(this.passwordRequirements.minLength),
Derick Montague602e98a2020-10-21 16:20:00 -0500317 maxLength: maxLength(this.passwordRequirements.maxLength),
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800318 },
319 passwordConfirmation: {
Derick Montague602e98a2020-10-21 16:20:00 -0500320 required: requiredIf(function () {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800321 return this.requirePassword();
322 }),
Derick Montague602e98a2020-10-21 16:20:00 -0500323 sameAsPassword: sameAs('password'),
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700324 },
Derick Montague602e98a2020-10-21 16:20:00 -0500325 manualUnlock: {},
326 },
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800327 };
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800328 },
329 methods: {
330 handleSubmit() {
331 let userData = {};
332
333 if (this.newUser) {
Surya Vde23ea22024-07-11 15:19:46 +0530334 this.v$.$touch();
335 if (this.v$.$invalid) return;
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800336 userData.username = this.form.username;
337 userData.status = this.form.status;
338 userData.privilege = this.form.privilege;
339 userData.password = this.form.password;
340 } else {
Surya Vde23ea22024-07-11 15:19:46 +0530341 if (this.v$.$invalid) return;
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800342 userData.originalUsername = this.originalUsername;
Surya Vde23ea22024-07-11 15:19:46 +0530343 if (this.v$.form.status.$dirty) {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800344 userData.status = this.form.status;
345 }
Surya Vde23ea22024-07-11 15:19:46 +0530346 if (this.v$.form.username.$dirty) {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800347 userData.username = this.form.username;
348 }
Surya Vde23ea22024-07-11 15:19:46 +0530349 if (this.v$.form.privilege.$dirty) {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800350 userData.privilege = this.form.privilege;
351 }
Surya Vde23ea22024-07-11 15:19:46 +0530352 if (this.v$.form.password.$dirty) {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800353 userData.password = this.form.password;
354 }
Surya Vde23ea22024-07-11 15:19:46 +0530355 if (this.v$.form.manualUnlock.$dirty) {
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700356 // If form manualUnlock control $dirty then
357 // set user Locked property to false
358 userData.locked = false;
359 }
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800360 if (Object.entries(userData).length === 1) {
361 this.closeModal();
362 return;
363 }
364 }
365
366 this.$emit('ok', { isNewUser: this.newUser, userData });
367 this.closeModal();
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800368 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800369 closeModal() {
370 this.$nextTick(() => {
371 this.$refs.modal.hide();
372 });
373 },
374 resetForm() {
375 this.form.originalUsername = '';
376 this.form.status = true;
377 this.form.username = '';
Yoshie Muranakabc0d61b2020-11-02 14:36:27 -0800378 this.form.privilege = null;
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800379 this.form.password = '';
380 this.form.passwordConfirmation = '';
Surya Vde23ea22024-07-11 15:19:46 +0530381 this.v$.$reset();
Yoshie Muranaka791622b2020-04-17 13:55:16 -0700382 this.$emit('hidden');
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800383 },
384 requirePassword() {
385 if (this.newUser) return true;
Surya Vde23ea22024-07-11 15:19:46 +0530386 if (this.v$.form.password.$dirty) return true;
387 if (this.v$.form.passwordConfirmation.$dirty) return true;
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800388 return false;
389 },
390 onOk(bvModalEvt) {
391 // prevent modal close
392 bvModalEvt.preventDefault();
393 this.handleSubmit();
Derick Montague602e98a2020-10-21 16:20:00 -0500394 },
395 },
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800396};
397</script>