Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: new PasswordRegExp config adding WIP [WTEL-4702] #721

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading