Skip to content

Commit

Permalink
Merge pull request #721 from webitel/feature/password-reg-exp
Browse files Browse the repository at this point in the history
feature: new PasswordRegExp config adding WIP [WTEL-4702]
  • Loading branch information
Lera24 authored Jul 19, 2024
2 parents 6743dae + dc6551a commit 9468d13
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 23 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"vue-router": "^4.2.5",
"vue2-dropzone": "^3.6.0",
"vuex": "^4.1.0",
"webitel-sdk": "^24.4.7"
"webitel-sdk": "^24.4.13"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
Expand Down
11 changes: 11 additions & 0 deletions src/app/utils/validators.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { helpers } from '@vuelidate/validators';

export const macValidator = (value) => {
if (typeof value === 'undefined' || value === null || value === '') {
return true;
Expand Down Expand Up @@ -81,3 +83,12 @@ export const regExpValidator = (value) => {
return false;
}
};
export const isRegExpMatched = (regExp, errorMessage) => {
return helpers.withParams(
{ type: 'isRegExpMatched', regExp, errorMessage },
(value) => {
if (!value) return true;
return regExp.test(value);
}
);
};
57 changes: 41 additions & 16 deletions src/modules/directory/modules/users/components/opened-user.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import { useVuelidate } from '@vuelidate/core';
import { helpers, required, requiredIf, requiredUnless } from '@vuelidate/validators';
import openedObjectMixin from '../../../../../app/mixins/objectPagesMixins/openedObjectMixin/openedObjectMixin';
import { isRegExpMatched } from '../../../../../app/utils/validators.js';
import Logs from '../modules/logs/components/opened-user-logs.vue';
import LogsFilters from '../modules/logs/modules/filters/components/opened-user-logs-filters.vue';
import Tokens from '../modules/tokens/components/opened-user-token.vue';
Expand All @@ -56,6 +57,8 @@ import General from './opened-user-general.vue';
import License from './opened-user-license.vue';
import Roles from './opened-user-roles.vue';
import Variables from './opened-user-variables.vue';
import { EngineSystemSettingName } from 'webitel-sdk';
import ConfigurationAPI from '../../../../system/modules/configuration/api/configuration.js';
export default {
name: 'OpenedUser',
Expand All @@ -76,24 +79,29 @@ export default {
}),
data: () => ({
namespace: 'directory/users',
passwordRegExp: '',
validationText: '',
}),
validations: {
itemInstance: {
username: { required },
password: {
required: requiredUnless((value, item) => !!item.id),
},
variables: {
$each: helpers.forEach({
key: {
required: requiredIf((value, item) => !!item.value),
},
value: {
required: requiredIf((value, item) => !!item.key),
},
}),
validations() {
return {
itemInstance: {
username: { required },
password: {
required: requiredUnless((value, item) => !!item.id),
isRegExpMatched: isRegExpMatched(this.passwordRegExp, this.validationText)
},
variables: {
$each: helpers.forEach({
key: {
required: requiredIf((value, item) => !!item.value),
},
value: {
required: requiredIf((value, item) => !!item.key),
},
}),
},
},
},
};
},
computed: {
Expand Down Expand Up @@ -152,6 +160,23 @@ export default {
return tabs;
},
},
methods: {
async checkPasswordRegExp() {
const PasswordRegExp = await ConfigurationAPI.getList({ name: EngineSystemSettingName.PasswordRegExp });
const exportSettingsValue = PasswordRegExp.items[0]?.value;
this.passwordRegExp = new RegExp(exportSettingsValue);
},
async checkPasswordValidationText() {
const PasswordRegExp = await ConfigurationAPI.getList({ name: EngineSystemSettingName.PasswordValidationText });
const exportSettingsValue = PasswordRegExp.items[0]?.value;
this.validationText = new RegExp(exportSettingsValue);
},
},
async mounted() {
await this.checkPasswordRegExp();
await this.checkPasswordValidationText();
}
};
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/modules/system/modules/configuration/api/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import configuration from '../../../../../app/api/openAPIConfig';
const service = new SystemSettingServiceApiFactory(configuration, '', instance);

const getList = async (params) => {
const { page, size, search, sort, fields } = applyTransform(params, [
const { page, size, search, sort, fields, name } = applyTransform(params, [
merge(getDefaultGetParams()),
starToSearch('search'),
]);

try {
const response = await service.searchSystemSetting(page, size, search, sort, fields);
const response = await service.searchSystemSetting(page, size, search, sort, fields, name);
const { items, next } = applyTransform(response.data, [
snakeToCamel(),
merge(getDefaultGetListResponse()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export default {
},
};
}
const defaultStringConfig = {
itemInstance: {
value: {
Expand All @@ -177,6 +178,10 @@ export default {
return deepmerge(defaults, defaultSelectConfig);
case EngineSystemSettingName.ChatAiConnection:
return deepmerge(defaults, defaultStringConfig);
case EngineSystemSettingName.PasswordRegExp:
return deepmerge(defaults, defaultStringConfig);
case EngineSystemSettingName.PasswordValidationText:
return deepmerge(defaults, defaultStringConfig);
default:
return defaults;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const ConfigurationValueTypes = Object.freeze({
[EngineSystemSettingName.SchemeVersionLimit]: 'number',
[EngineSystemSettingName.SearchNumberLength]: 'number',
[EngineSystemSettingName.ExportSettings]: 'select',
[EngineSystemSettingName.PasswordRegExp]: 'string',
[EngineSystemSettingName.PasswordValidationText]: 'string',
[EngineSystemSettingName.ChatAiConnection]: 'string',
},
);
Expand Down

0 comments on commit 9468d13

Please sign in to comment.