blob: 8932eb56bb90444c84c1edfedb0deb11fcf91c00 [file] [log] [blame]
Yoshie Muranaka463a5702019-12-04 09:09:36 -08001<template>
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -08002 <b-modal
3 id="modal-settings"
4 ref="modal"
Sandeepa Singhb4406162021-07-26 15:05:39 +05305 :title="$t('pageUserManagement.accountPolicySettings')"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -08006 @hidden="resetForm"
7 >
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -07008 <b-form id="form-settings" novalidate @submit.prevent="handleSubmit">
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -08009 <b-container>
10 <b-row>
11 <b-col>
12 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +053013 :label="$t('pageUserManagement.modal.maxFailedLoginAttempts')"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080014 label-for="lockout-threshold"
15 >
16 <b-form-text id="lockout-threshold-help-block">
17 {{
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080018 $t('global.form.valueMustBeBetween', {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080019 min: 0,
Derick Montague602e98a2020-10-21 16:20:00 -050020 max: 65535,
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080021 })
22 }}
23 </b-form-text>
24 <b-form-input
25 id="lockout-threshold"
26 v-model.number="form.lockoutThreshold"
27 type="number"
28 aria-describedby="lockout-threshold-help-block"
Sandeepa Singhb4406162021-07-26 15:05:39 +053029 data-test-id="userManagement-input-lockoutThreshold"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080030 :state="getValidationState($v.form.lockoutThreshold)"
31 @input="$v.form.lockoutThreshold.$touch()"
32 />
33 <b-form-invalid-feedback role="alert">
34 <template v-if="!$v.form.lockoutThreshold.required">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080035 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080036 </template>
37 <template
38 v-if="
39 !$v.form.lockoutThreshold.minLength ||
Derick Montague602e98a2020-10-21 16:20:00 -050040 !$v.form.lockoutThreshold.maxLength
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080041 "
42 >
43 {{
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080044 $t('global.form.valueMustBeBetween', {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080045 min: 0,
Derick Montague602e98a2020-10-21 16:20:00 -050046 max: 65535,
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080047 })
48 }}
49 </template>
50 </b-form-invalid-feedback>
51 </b-form-group>
52 </b-col>
53 <b-col>
54 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +053055 :label="$t('pageUserManagement.modal.userUnlockMethod')"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080056 >
57 <b-form-radio
58 v-model="form.unlockMethod"
59 name="unlock-method"
60 class="mb-2"
61 :value="0"
Sandeepa Singhb4406162021-07-26 15:05:39 +053062 data-test-id="userManagement-radio-manualUnlock"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080063 @input="$v.form.unlockMethod.$touch()"
64 >
Sandeepa Singhb4406162021-07-26 15:05:39 +053065 {{ $t('pageUserManagement.modal.manual') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080066 </b-form-radio>
67 <b-form-radio
68 v-model="form.unlockMethod"
69 name="unlock-method"
70 :value="1"
Sandeepa Singhb4406162021-07-26 15:05:39 +053071 data-test-id="userManagement-radio-automaticUnlock"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080072 @input="$v.form.unlockMethod.$touch()"
73 >
Sandeepa Singhb4406162021-07-26 15:05:39 +053074 {{ $t('pageUserManagement.modal.automaticAfterTimeout') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080075 </b-form-radio>
76 <div class="mt-3 ml-4">
77 <b-form-text id="lockout-duration-help-block">
Sandeepa Singhb4406162021-07-26 15:05:39 +053078 {{ $t('pageUserManagement.modal.timeoutDurationSeconds') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080079 </b-form-text>
80 <b-form-input
81 v-model.number="form.lockoutDuration"
82 aria-describedby="lockout-duration-help-block"
83 type="number"
Sandeepa Singhb4406162021-07-26 15:05:39 +053084 data-test-id="userManagement-input-lockoutDuration"
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080085 :state="getValidationState($v.form.lockoutDuration)"
86 :readonly="$v.form.unlockMethod.$model === 0"
87 @input="$v.form.lockoutDuration.$touch()"
88 />
89 <b-form-invalid-feedback role="alert">
90 <template v-if="!$v.form.lockoutDuration.required">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080091 {{ $t('global.form.fieldRequired') }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080092 </template>
93 <template v-else-if="!$v.form.lockoutDuration.minvalue">
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080094 {{ $t('global.form.mustBeAtLeast', { value: 1 }) }}
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -080095 </template>
96 </b-form-invalid-feedback>
97 </div>
98 </b-form-group>
99 </b-col>
100 </b-row>
101 </b-container>
102 </b-form>
Sukanya Pandey18375032020-10-30 21:13:06 +0530103 <template #modal-footer="{ cancel }">
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500104 <b-button
105 variant="secondary"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530106 data-test-id="userManagement-button-cancel"
Dixsie Wolmersfe1e6582020-07-15 11:18:12 -0500107 @click="cancel()"
108 >
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700109 {{ $t('global.action.cancel') }}
110 </b-button>
111 <b-button
112 form="form-settings"
113 type="submit"
114 variant="primary"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530115 data-test-id="userManagement-button-submit"
Yoshie Muranaka7f7687e2020-08-12 09:13:44 -0700116 @click="onOk"
Yoshie Muranaka9a9092d2020-05-04 08:24:21 -0700117 >
118 {{ $t('global.action.save') }}
119 </b-button>
120 </template>
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800121 </b-modal>
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800122</template>
123
124<script>
SurenNeware61859092020-10-01 09:37:32 +0530125import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700126import { useVuelidate } from '@vuelidate/core';
127
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800128import {
129 required,
130 requiredIf,
131 minValue,
Derick Montague602e98a2020-10-21 16:20:00 -0500132 maxValue,
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700133} from '@vuelidate/validators';
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800134
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800135export default {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800136 mixins: [VuelidateMixin],
Derick Montague09e45cd2020-01-23 15:45:57 -0600137 props: {
138 settings: {
Yoshie Muranaka52b02232020-02-20 08:00:45 -0800139 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -0500140 required: true,
141 },
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800142 },
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700143 setup() {
144 return {
145 v$: useVuelidate(),
146 };
147 },
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800148 data() {
149 return {
150 form: {
151 lockoutThreshold: 0,
152 unlockMethod: 0,
Derick Montague602e98a2020-10-21 16:20:00 -0500153 lockoutDuration: null,
154 },
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800155 };
156 },
157 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -0500158 settings: function ({ lockoutThreshold, lockoutDuration }) {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800159 this.form.lockoutThreshold = lockoutThreshold;
160 this.form.unlockMethod = lockoutDuration ? 1 : 0;
161 this.form.lockoutDuration = lockoutDuration ? lockoutDuration : null;
Derick Montague602e98a2020-10-21 16:20:00 -0500162 },
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800163 },
164 validations: {
165 form: {
166 lockoutThreshold: {
167 minValue: minValue(0),
168 maxValue: maxValue(65535),
Derick Montague602e98a2020-10-21 16:20:00 -0500169 required,
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800170 },
171 unlockMethod: { required },
172 lockoutDuration: {
Derick Montague602e98a2020-10-21 16:20:00 -0500173 minValue: function (value) {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800174 return this.form.unlockMethod === 0 || value > 0;
175 },
Derick Montague602e98a2020-10-21 16:20:00 -0500176 required: requiredIf(function () {
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800177 return this.form.unlockMethod === 1;
Derick Montague602e98a2020-10-21 16:20:00 -0500178 }),
179 },
180 },
Yoshie Muranaka1b1c1002020-02-20 10:18:36 -0800181 },
182 methods: {
183 handleSubmit() {
184 this.$v.$touch();
185 if (this.$v.$invalid) return;
186
187 let lockoutThreshold;
188 let lockoutDuration;
189 if (this.$v.form.lockoutThreshold.$dirty) {
190 lockoutThreshold = this.form.lockoutThreshold;
191 }
192 if (this.$v.form.unlockMethod.$dirty) {
193 lockoutDuration = this.form.unlockMethod
194 ? this.form.lockoutDuration
195 : 0;
196 }
197
198 this.$emit('ok', { lockoutThreshold, lockoutDuration });
199 this.closeModal();
200 },
201 onOk(bvModalEvt) {
202 // prevent modal close
203 bvModalEvt.preventDefault();
204 this.handleSubmit();
205 },
206 closeModal() {
207 this.$nextTick(() => {
208 this.$refs.modal.hide();
209 });
210 },
211 resetForm() {
212 // Reset form models
213 this.form.lockoutThreshold = this.settings.lockoutThreshold;
214 this.form.unlockMethod = this.settings.lockoutDuration ? 1 : 0;
215 this.form.lockoutDuration = this.settings.lockoutDuration
216 ? this.settings.lockoutDuration
217 : null;
218 this.$v.$reset(); // clear validations
Derick Montague602e98a2020-10-21 16:20:00 -0500219 },
220 },
Yoshie Muranaka463a5702019-12-04 09:09:36 -0800221};
222</script>