blob: 5ffb2979f253f563d18a068fa4e4eea024086057 [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(
Ed Tanous81323992024-02-27 11:26:24 -080074 '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)"
aravinths12b021032024-05-22 21:29:50 +0530112 :disabled="!newUser && originalUsername === 'root'"
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800113 @input="$v.form.privilege.$touch()"
114 >
Yoshie Muranakabc0d61b2020-11-02 14:36:27 -0800115 <template #first>
116 <b-form-select-option :value="null" disabled>
117 {{ $t('global.form.selectAnOption') }}
118 </b-form-select-option>
119 </template>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800120 </b-form-select>
121 <b-form-invalid-feedback role="alert">
122 <template v-if="!$v.form.privilege.required">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800123 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800124 </template>
125 </b-form-invalid-feedback>
126 </b-form-group>
127 </b-col>
128 <b-col>
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800129 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +0530130 :label="$t('pageUserManagement.modal.userPassword')"
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800131 label-for="password"
132 >
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800133 <b-form-text id="password-help-block">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800134 {{
Sandeepa Singhb4406162021-07-26 15:05:39 +0530135 $t('pageUserManagement.modal.passwordMustBeBetween', {
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800136 min: passwordRequirements.minLength,
Derick Montague602e98a2020-10-21 16:20:00 -0500137 max: passwordRequirements.maxLength,
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800138 })
139 }}
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800140 </b-form-text>
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800141 <input-password-toggle>
142 <b-form-input
143 id="password"
144 v-model="form.password"
145 type="password"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530146 data-test-id="userManagement-input-password"
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800147 aria-describedby="password-help-block"
148 :state="getValidationState($v.form.password)"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -0500149 class="form-control-with-button"
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800150 @input="$v.form.password.$touch()"
151 />
152 <b-form-invalid-feedback role="alert">
153 <template v-if="!$v.form.password.required">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800154 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800155 </template>
156 <template
157 v-if="
158 !$v.form.password.minLength || !$v.form.password.maxLength
159 "
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"
181 :state="getValidationState($v.form.passwordConfirmation)"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -0500182 class="form-control-with-button"
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800183 @input="$v.form.passwordConfirmation.$touch()"
184 />
185 <b-form-invalid-feedback role="alert">
186 <template v-if="!$v.form.passwordConfirmation.required">
Yoshie Muranakaeaa04802020-02-28 13:21:27 -0800187 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800188 </template>
189 <template
190 v-else-if="!$v.form.passwordConfirmation.sameAsPassword"
191 >
Sandeepa Singhb4406162021-07-26 15:05:39 +0530192 {{ $t('pageUserManagement.modal.passwordsDoNotMatch') }}
Yoshie Muranaka4ee8d292020-02-20 07:29:58 -0800193 </template>
194 </b-form-invalid-feedback>
195 </input-password-toggle>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800196 </b-form-group>
197 </b-col>
198 </b-row>
199 </b-container>
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800200 </b-form>
Sukanya Pandey18375032020-10-30 21:13:06 +0530201 <template #modal-footer="{ cancel }">
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500202 <b-button
203 variant="secondary"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530204 data-test-id="userManagement-button-cancel"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500205 @click="cancel()"
206 >
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700207 {{ $t('global.action.cancel') }}
208 </b-button>
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500209 <b-button
210 form="form-user"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530211 data-test-id="userManagement-button-submit"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500212 type="submit"
213 variant="primary"
214 @click="onOk"
215 >
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700216 <template v-if="newUser">
Sandeepa Singhb4406162021-07-26 15:05:39 +0530217 {{ $t('pageUserManagement.addUser') }}
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700218 </template>
219 <template v-else>
220 {{ $t('global.action.save') }}
221 </template>
222 </b-button>
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800223 </template>
224 </b-modal>
225</template>
226
227<script>
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800228import {
229 required,
230 maxLength,
231 minLength,
232 sameAs,
233 helpers,
Derick Montague602e98a2020-10-21 16:20:00 -0500234 requiredIf,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800235} from 'vuelidate/lib/validators';
SurenNeware61859092020-10-01 09:37:32 +0530236import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
237import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
238import Alert from '@/components/Global/Alert';
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800239
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800240export default {
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700241 components: { Alert, InputPasswordToggle },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800242 mixins: [VuelidateMixin],
Derick Montague09e45cd2020-01-23 15:45:57 -0600243 props: {
244 user: {
245 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -0500246 default: null,
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800247 },
248 passwordRequirements: {
249 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -0500250 required: true,
251 },
Derick Montague09e45cd2020-01-23 15:45:57 -0600252 },
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800253 data() {
254 return {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800255 originalUsername: '',
256 form: {
257 status: true,
258 username: '',
Yoshie Muranakabc0d61b2020-11-02 14:36:27 -0800259 privilege: null,
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800260 password: '',
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700261 passwordConfirmation: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500262 manualUnlock: false,
263 },
Sivaprabu Ganesan28974472023-01-05 18:52:51 +0530264 disabled: this.$store.getters['global/username'],
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800265 };
266 },
267 computed: {
268 newUser() {
269 return this.user ? false : true;
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700270 },
271 accountSettings() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530272 return this.$store.getters['userManagement/accountSettings'];
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700273 },
274 manualUnlockPolicy() {
275 return !this.accountSettings.accountLockoutDuration;
Yoshie Muranaka038a9da2020-04-17 11:22:56 -0700276 },
277 privilegeTypes() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530278 return this.$store.getters['userManagement/accountRoles'];
Derick Montague602e98a2020-10-21 16:20:00 -0500279 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800280 },
281 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -0500282 user: function (value) {
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800283 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 Montague602e98a2020-10-21 16:20:00 -0500288 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800289 },
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800290 validations() {
291 return {
292 form: {
293 status: {
Derick Montague602e98a2020-10-21 16:20:00 -0500294 required,
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800295 },
296 username: {
297 required,
298 maxLength: maxLength(16),
Derick Montague602e98a2020-10-21 16:20:00 -0500299 pattern: helpers.regex('pattern', /^([a-zA-Z_][a-zA-Z0-9_]*)/),
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800300 },
301 privilege: {
Derick Montague602e98a2020-10-21 16:20:00 -0500302 required,
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800303 },
304 password: {
Derick Montague602e98a2020-10-21 16:20:00 -0500305 required: requiredIf(function () {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800306 return this.requirePassword();
307 }),
308 minLength: minLength(this.passwordRequirements.minLength),
Derick Montague602e98a2020-10-21 16:20:00 -0500309 maxLength: maxLength(this.passwordRequirements.maxLength),
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800310 },
311 passwordConfirmation: {
Derick Montague602e98a2020-10-21 16:20:00 -0500312 required: requiredIf(function () {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800313 return this.requirePassword();
314 }),
Derick Montague602e98a2020-10-21 16:20:00 -0500315 sameAsPassword: sameAs('password'),
Yoshie Muranaka1f9ed4c2020-03-26 16:59:54 -0700316 },
Derick Montague602e98a2020-10-21 16:20:00 -0500317 manualUnlock: {},
318 },
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800319 };
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800320 },
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 Muranaka1f9ed4c2020-03-26 16:59:54 -0700347 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 Muranaka4b0fc1d2020-01-06 07:36:16 -0800352 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 Muranaka463a5702019-12-04 09:09:36 -0800360 },
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800361 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 Muranakabc0d61b2020-11-02 14:36:27 -0800370 this.form.privilege = null;
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800371 this.form.password = '';
372 this.form.passwordConfirmation = '';
373 this.$v.$reset();
Yoshie Muranaka791622b2020-04-17 13:55:16 -0700374 this.$emit('hidden');
Yoshie Muranaka4b0fc1d2020-01-06 07:36:16 -0800375 },
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 Montague602e98a2020-10-21 16:20:00 -0500386 },
387 },
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800388};
389</script>