blob: 5a1dc61a42acbbb3886ecc00fd1c03762a55018b [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>
17 <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"
30 value="false"
31 />
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -070032 <b-button
33 variant="primary"
34 :disabled="$v.form.manualUnlock.$dirty"
Sandeepa Singhb4406162021-07-26 15:05:39 +053035 data-test-id="userManagement-button-manualUnlock"
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -070036 @click="$v.form.manualUnlock.$touch()"
37 >
Sandeepa Singhb4406162021-07-26 15:05:39 +053038 {{ $t('pageUserManagement.modal.unlock') }}
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -070039 </b-button>
40 </b-col>
41 </b-row>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080042 <b-row>
43 <b-col>
Sandeepa Singhb4406162021-07-26 15:05:39 +053044 <b-form-group :label="$t('pageUserManagement.modal.accountStatus')">
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080045 <b-form-radio
46 v-model="form.status"
47 name="user-status"
48 :value="true"
Sandeepa Singhb4406162021-07-26 15:05:39 +053049 data-test-id="userManagement-radioButton-statusEnabled"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080050 @input="$v.form.status.$touch()"
51 >
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080052 {{ $t('global.status.enabled') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080053 </b-form-radio>
54 <b-form-radio
55 v-model="form.status"
56 name="user-status"
Sandeepa Singhb4406162021-07-26 15:05:39 +053057 data-test-id="userManagement-radioButton-statusDisabled"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080058 :value="false"
Sivaprabu Ganesan28974472023-01-05 18:52:51 +053059 :disabled="!newUser && originalUsername === disabled"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080060 @input="$v.form.status.$touch()"
61 >
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080062 {{ $t('global.status.disabled') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080063 </b-form-radio>
64 </b-form-group>
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080065 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +053066 :label="$t('pageUserManagement.modal.username')"
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080067 label-for="username"
68 >
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080069 <b-form-text id="username-help-block">
Sandeepa Singhb4406162021-07-26 15:05:39 +053070 {{ $t('pageUserManagement.modal.cannotStartWithANumber') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080071 <br />
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080072 {{
73 $t(
Sandeepa Singhb4406162021-07-26 15:05:39 +053074 'pageUserManagement.modal.noSpecialCharactersExceptUnderscore'
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080075 )
76 }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080077 </b-form-text>
78 <b-form-input
Derick Montague09e45cd2020-01-23 15:45:57 -060079 id="username"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080080 v-model="form.username"
81 type="text"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080082 aria-describedby="username-help-block"
Sandeepa Singhb4406162021-07-26 15:05:39 +053083 data-test-id="userManagement-input-username"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080084 :state="getValidationState($v.form.username)"
Sivaprabu Ganesan28974472023-01-05 18:52:51 +053085 :disabled="!newUser && originalUsername === disabled"
Yoshie Muranaka52b02232020-02-20 08:00:45 -080086 @input="$v.form.username.$touch()"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080087 />
88 <b-form-invalid-feedback role="alert">
89 <template v-if="!$v.form.username.required">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080090 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080091 </template>
92 <template v-else-if="!$v.form.username.maxLength">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080093 {{
94 $t('global.form.lengthMustBeBetween', { min: 1, max: 16 })
95 }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080096 </template>
97 <template v-else-if="!$v.form.username.pattern">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -080098 {{ $t('global.form.invalidFormat') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -080099 </template>
100 </b-form-invalid-feedback>
101 </b-form-group>
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800102 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +0530103 :label="$t('pageUserManagement.modal.privilege')"
Yoshie Muranakaa4b9e402020-03-06 14:59:46 -0800104 label-for="privilege"
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800105 >
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800106 <b-form-select
Yoshie Muranakaa4b9e402020-03-06 14:59:46 -0800107 id="privilege"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800108 v-model="form.privilege"
109 :options="privilegeTypes"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530110 data-test-id="userManagement-select-privilege"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800111 :state="getValidationState($v.form.privilege)"
112 @input="$v.form.privilege.$touch()"
113 >
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">
121 <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"
147 :state="getValidationState($v.form.password)"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -0500148 class="form-control-with-button"
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800149 @input="$v.form.password.$touch()"
150 />
151 <b-form-invalid-feedback role="alert">
152 <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="
157 !$v.form.password.minLength || !$v.form.password.maxLength
158 "
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"
180 :state="getValidationState($v.form.passwordConfirmation)"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -0500181 class="form-control-with-button"
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800182 @input="$v.form.passwordConfirmation.$touch()"
183 />
184 <b-form-invalid-feedback role="alert">
185 <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
189 v-else-if="!$v.form.passwordConfirmation.sameAsPassword"
190 >
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,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800234} from 'vuelidate/lib/validators';
SurenNeware61859092020-10-01 09:37:32 +0530235import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
236import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
237import Alert from '@/components/Global/Alert';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800238
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800239export default {
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700240 components: { Alert, InputPasswordToggle },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800241 mixins: [VuelidateMixin],
Derick Montague09e45cd2020-01-23 15:45:57 -0600242 props: {
243 user: {
244 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -0500245 default: null,
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800246 },
247 passwordRequirements: {
248 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -0500249 required: true,
250 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600251 },
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800252 data() {
253 return {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800254 originalUsername: '',
255 form: {
256 status: true,
257 username: '',
Yoshie Muranakabc0d61b2020-11-02 14:36:27 -0800258 privilege: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800259 password: '',
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700260 passwordConfirmation: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500261 manualUnlock: false,
262 },
Sivaprabu Ganesan28974472023-01-05 18:52:51 +0530263 disabled: this.$store.getters['global/username'],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800264 };
265 },
266 computed: {
267 newUser() {
268 return this.user ? false : true;
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700269 },
270 accountSettings() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530271 return this.$store.getters['userManagement/accountSettings'];
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700272 },
273 manualUnlockPolicy() {
274 return !this.accountSettings.accountLockoutDuration;
Yoshie Muranaka038a9da2020-04-17 11:22:56 -0700275 },
276 privilegeTypes() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530277 return this.$store.getters['userManagement/accountRoles'];
Derick Montague602e98a2020-10-21 16:20:00 -0500278 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800279 },
280 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -0500281 user: function (value) {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800282 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 Montague602e98a2020-10-21 16:20:00 -0500287 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800288 },
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800289 validations() {
290 return {
291 form: {
292 status: {
Derick Montague602e98a2020-10-21 16:20:00 -0500293 required,
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800294 },
295 username: {
296 required,
297 maxLength: maxLength(16),
Derick Montague602e98a2020-10-21 16:20:00 -0500298 pattern: helpers.regex('pattern', /^([a-zA-Z_][a-zA-Z0-9_]*)/),
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800299 },
300 privilege: {
Derick Montague602e98a2020-10-21 16:20:00 -0500301 required,
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800302 },
303 password: {
Derick Montague602e98a2020-10-21 16:20:00 -0500304 required: requiredIf(function () {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800305 return this.requirePassword();
306 }),
307 minLength: minLength(this.passwordRequirements.minLength),
Derick Montague602e98a2020-10-21 16:20:00 -0500308 maxLength: maxLength(this.passwordRequirements.maxLength),
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800309 },
310 passwordConfirmation: {
Derick Montague602e98a2020-10-21 16:20:00 -0500311 required: requiredIf(function () {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800312 return this.requirePassword();
313 }),
Derick Montague602e98a2020-10-21 16:20:00 -0500314 sameAsPassword: sameAs('password'),
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700315 },
Derick Montague602e98a2020-10-21 16:20:00 -0500316 manualUnlock: {},
317 },
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800318 };
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800319 },
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 Muranaka1f9ed4c2020-03-26 16:59:54 -0700346 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 Muranaka4b0fc1d2020-01-06 07:36:16 -0800351 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 Muranaka463a5702019-12-04 09:09:36 -0800359 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800360 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 Muranakabc0d61b2020-11-02 14:36:27 -0800369 this.form.privilege = null;
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800370 this.form.password = '';
371 this.form.passwordConfirmation = '';
372 this.$v.$reset();
Yoshie Muranaka791622b2020-04-17 13:55:16 -0700373 this.$emit('hidden');
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800374 },
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 Montague602e98a2020-10-21 16:20:00 -0500385 },
386 },
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800387};
388</script>