0
0
Fork 0

Account view forms

This commit is contained in:
William Buezas 2024-06-06 14:07:40 -03:00
parent 985ce9a643
commit f305cee3ce
6 changed files with 484 additions and 1 deletions

View File

@ -0,0 +1,111 @@
<script setup>
import { useI18n } from 'vue-i18n';
import FormModel from 'components/FormModel.vue';
import VnRow from 'components/ui/VnRow.vue';
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
import VnInput from 'src/components/common/VnInput.vue';
import axios from 'axios';
import useNotify from 'src/composables/useNotify.js';
const { t } = useI18n();
const { notify } = useNotify();
const onSynchronizeAll = async () => {
try {
notify(t('Synchronizing in the background'), 'positive');
await axios.patch(`Accounts/syncAll`);
} catch (error) {
console.error('Error synchronizing all accounts', error);
}
};
const onSynchronizeRoles = async () => {
try {
await axios.patch(`RoleInherits/sync`);
notify(t('Roles synchronized!'), 'positive');
} catch (error) {
console.error('Error synchronizing roles', error);
}
};
</script>
<template>
<QPage>
<VnSubToolbar />
<FormModel
:url="`AccountConfigs/${1}`"
:url-update="`AccountConfigs/${1}`"
model="AccountAccounts"
auto-load
>
<template #moreActions>
<QBtn
round
flat
color="primary"
:label="t('accounts.syncAll')"
@click="onSynchronizeAll()"
/>
<QBtn
round
flat
color="primary"
:label="t('accounts.syncRoles')"
@click="onSynchronizeRoles()"
/>
</template>
<template #form="{ data }">
<VnRow class="row q-gutter-md q-mb-md">
<VnInput :label="t('accounts.homedir')" v-model="data.homedir" />
</VnRow>
<VnRow class="row q-gutter-md q-mb-md">
<VnInput :label="t('accounts.shell')" v-model="data.shell" />
</VnRow>
<VnRow class="row q-gutter-md q-mb-md">
<VnInput
:label="t('accounts.idBase')"
v-model="data.idBase"
type="number"
min="0"
/>
</VnRow>
<VnRow class="row q-gutter-md q-mb-md">
<VnInput
:label="t('accounts.min')"
v-model="data.min"
type="number"
min="0"
/>
<VnInput
:label="t('accounts.max')"
v-model="data.max"
type="number"
min="0"
/>
</VnRow>
<VnRow class="row q-gutter-md q-mb-md">
<VnInput
:label="t('accounts.warn')"
v-model="data.warn"
type="number"
min="0"
/>
<VnInput
:label="t('accounts.inact')"
v-model="data.inact"
type="number"
min="0"
/>
</VnRow>
</template>
</FormModel>
</QPage>
</template>
<i18n>
es:
Roles synchronized!: ¡Roles sincronizados!
Synchronizing in the background: Sincronizando en segundo plano
</i18n>

View File

@ -0,0 +1,167 @@
<script setup>
import { ref, onMounted, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import FormModel from 'components/FormModel.vue';
import VnRow from 'components/ui/VnRow.vue';
import VnInput from 'src/components/common/VnInput.vue';
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
import useNotify from 'src/composables/useNotify.js';
import axios from 'axios';
const { t } = useI18n();
const { notify } = useNotify();
const DEFAULT_DATA = {
id: 1,
hasData: false,
groupDn: null,
password: null,
rdn: null,
server: null,
userDn: null,
};
const initialData = ref({
...DEFAULT_DATA,
});
const hasData = computed({
get: () => initialData.value.hasData,
set: (val) => {
initialData.value.hasData = val;
if (!val) customFn.value = deleteMailForward;
else customFn.value = null;
},
});
const initialDataLoaded = ref(false);
const urlCreate = ref(null);
const urlUpdate = ref(null);
const customFn = ref(null);
const onTestConection = async () => {
try {
await axios.get(`LdapConfigs/test`);
notify(t('LDAP connection established!'), 'positive');
} catch (error) {
console.error('Error testing connection', error);
}
};
const getInitialLdapConfig = async () => {
try {
initialDataLoaded.value = false;
const { data } = await axios.get(`LdapConfigs/${1}`);
initialData.value = data;
hasData.value = true;
return data;
} catch (error) {
hasData.value = false;
console.error('Error fetching initial LDAP config', error);
return null;
} finally {
if (hasData.value) {
urlUpdate.value = `LdapConfigs/${1}`;
urlCreate.value = null;
} else {
urlUpdate.value = null;
urlCreate.value = `LdapConfigs`;
}
initialDataLoaded.value = true;
}
};
const deleteMailForward = async () => {
try {
await axios.delete(`LdapConfigs/${1}`);
initialData.value = { ...DEFAULT_DATA };
hasData.value = false;
notify(t('globals.dataSaved'), 'positive');
} catch (err) {
console.error('Error deleting mail forward', err);
}
};
onMounted(async () => await getInitialLdapConfig());
</script>
<template>
<QPage>
<VnSubToolbar></VnSubToolbar>
<FormModel
:key="initialDataLoaded"
model="AccountLdap"
:form-initial-data="initialData"
:url-create="urlCreate"
:url-update="urlUpdate"
:save-fn="customFn"
auto-load
@on-data-saved="getInitialLdapConfig()"
>
<template #moreActions>
<QBtnGroup push class="q-gutter-x-sm">
<QBtn
round
flat
color="primary"
:label="t('ldap.testConnection')"
@click="onTestConection()"
>
<QTooltip>
{{ t('ldap.testConnection') }}
</QTooltip>
</QBtn>
</QBtnGroup>
</template>
<template #form="{ data, validate }">
<VnRow class="row q-gutter-md q-mb-md">
<div class="col">
<QCheckbox
:label="t('ldap.enableSync')"
v-model="data.hasData"
@update:model-value="($event) => (hasData = $event)"
:toggle-indeterminate="false"
/>
</div>
</VnRow>
<template v-if="hasData">
<VnInput
:label="t('ldap.server')"
clearable
v-model="data.server"
:required="true"
:rules="validate('LdapConfig.server')"
/>
<VnInput
:label="t('ldap.rdn')"
clearable
v-model="data.rdn"
:required="true"
:rules="validate('LdapConfig.rdn')"
/>
<VnInput
:label="t('ldap.password')"
clearable
type="password"
v-model="data.password"
:required="true"
:rules="validate('LdapConfig.password')"
/>
<VnInput :label="t('ldap.userDN')" clearable v-model="data.userDn" />
<VnInput
:label="t('ldap.groupDN')"
clearable
v-model="data.groupDn"
/>
</template>
</template>
</FormModel>
</QPage>
</template>
<i18n>
es:
LDAP connection established!: ¡Conexión con LDAP establecida!
</i18n>

View File

@ -0,0 +1,182 @@
<script setup>
import { ref, onMounted, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import FormModel from 'components/FormModel.vue';
import VnRow from 'components/ui/VnRow.vue';
import VnInput from 'src/components/common/VnInput.vue';
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
import useNotify from 'src/composables/useNotify.js';
import axios from 'axios';
const { t } = useI18n();
const { notify } = useNotify();
const formModel = ref(null);
const DEFAULT_DATA = {
id: 1,
hasData: false,
adDomain: null,
adController: null,
adUser: null,
adPassword: null,
userDn: null,
verifyCert: false,
};
const initialData = ref({
...DEFAULT_DATA,
});
const hasData = computed({
get: () => initialData.value.hasData,
set: (val) => {
initialData.value.hasData = val;
if (!val) customFn.value = deleteMailForward;
else customFn.value = null;
},
});
const initialDataLoaded = ref(false);
const urlCreate = ref(null);
const urlUpdate = ref(null);
const customFn = ref(null);
const onTestConection = async () => {
try {
await axios.get(`SambaConfigs/test`);
notify(t('Samba connection established!'), 'positive');
} catch (error) {
console.error('Error testing connection', error);
}
};
const getInitialLdapConfig = async () => {
try {
initialDataLoaded.value = false;
const { data } = await axios.get(`SambaConfigs/${1}`);
initialData.value = data;
hasData.value = true;
return data;
} catch (error) {
hasData.value = false;
console.error('Error fetching initial LDAP config', error);
return null;
} finally {
if (hasData.value) {
urlUpdate.value = `SambaConfigs/${1}`;
urlCreate.value = null;
} else {
urlUpdate.value = null;
urlCreate.value = `SambaConfigs`;
}
initialDataLoaded.value = true;
}
};
const deleteMailForward = async () => {
try {
await axios.delete(`SambaConfigs/${1}`);
initialData.value = { ...DEFAULT_DATA };
hasData.value = false;
notify(t('globals.dataSaved'), 'positive');
} catch (err) {
console.error('Error deleting mail forward', err);
}
};
onMounted(async () => await getInitialLdapConfig());
</script>
<template>
<QPage>
<VnSubToolbar></VnSubToolbar>
<FormModel
ref="formModel"
:key="initialDataLoaded"
model="AccountSamba"
:form-initial-data="initialData"
:url-create="urlCreate"
:url-update="urlUpdate"
:save-fn="customFn"
auto-load
@on-data-saved="getInitialLdapConfig()"
>
<template #moreActions>
<QBtnGroup push class="q-gutter-x-sm">
<QBtn
round
flat
color="primary"
:label="t('ldap.testConnection')"
:disable="formModel.hasChanges"
@click="onTestConection()"
>
<QTooltip>
{{ t('ldap.testConnection') }}
</QTooltip>
</QBtn>
</QBtnGroup>
</template>
<template #form="{ data, validate }">
<VnRow class="row q-gutter-md q-mb-md">
<div class="col">
<QCheckbox
:label="t('ldap.enableSync')"
v-model="data.hasData"
@update:model-value="($event) => (hasData = $event)"
:toggle-indeterminate="false"
/>
</div>
</VnRow>
<template v-if="hasData">
<VnInput
:label="t('samba.domainAD')"
clearable
v-model="data.adDomain"
:required="true"
:rules="validate('SambaConfigs.server')"
/>
<VnInput
:label="t('samba.domainController')"
clearable
v-model="data.adController"
:required="true"
:rules="validate('SambaConfigs.adController')"
/>
<VnInput
:label="t('samba.userAD')"
clearable
v-model="data.adUser"
:rules="validate('SambaConfigs.adUser')"
/>
<VnInput
:label="t('samba.passwordAD')"
clearable
type="password"
v-model="data.adPassword"
/>
<VnInput
:label="t('samba.domainPart')"
clearable
v-model="data.userDn"
:required="true"
:rules="validate('SambaConfigs.userDn')"
/>
<QCheckbox
:label="t('samba.verifyCertificate')"
v-model="data.verifyCert"
:rules="validate('SambaConfigs.groupDn')"
:toggle-indeterminate="false"
/>
</template>
</template>
</FormModel>
</QPage>
</template>
<i18n>
es:
Samba connection established!: ¡Conexión con LDAP establecida!
</i18n>

View File

@ -65,3 +65,13 @@ samba:
verifyCertificate: Verify certificate verifyCertificate: Verify certificate
testConnection: Test connection testConnection: Test connection
success: Samba connection established! success: Samba connection established!
accounts:
homedir: Homedir base
shell: Shell
idBase: User and role base id
min: Min
max: Max
warn: Warn
inact: Inact
syncAll: Synchronize all
syncRoles: Synchronize roles

View File

@ -76,3 +76,13 @@ samba:
Verify certificate: Verificar certificado Verify certificate: Verificar certificado
testConnection: Probar conexión testConnection: Probar conexión
success: ¡Conexión con Samba establecida! success: ¡Conexión con Samba establecida!
accounts:
homedir: Directorio base para carpetas de usuario
shell: Intérprete de línea de comandos
idBase: Id base usuarios y roles
min: Min
max: Max
warn: Warn
inact: Inact
syncAll: Sincronizar todo
syncRoles: Sincronizar roles

View File

@ -11,7 +11,7 @@ export default {
component: RouterView, component: RouterView,
redirect: { name: 'AccountMain' }, redirect: { name: 'AccountMain' },
menus: { menus: {
main: ['AccountRoles'], main: ['AccountRoles', 'AccountAccounts', 'AccountLdap', 'AccountSamba'],
card: [], card: [],
}, },
children: [ children: [
@ -54,6 +54,7 @@ export default {
meta: { meta: {
title: 'accounts', title: 'accounts',
icon: 'accessibility', icon: 'accessibility',
roles: ['itManagement'],
}, },
component: () => import('src/pages/Account/AccountAccounts.vue'), component: () => import('src/pages/Account/AccountAccounts.vue'),
}, },
@ -63,6 +64,7 @@ export default {
meta: { meta: {
title: 'ldap', title: 'ldap',
icon: 'account_tree', icon: 'account_tree',
roles: ['itManagement'],
}, },
component: () => import('src/pages/Account/AccountLdap.vue'), component: () => import('src/pages/Account/AccountLdap.vue'),
}, },
@ -72,6 +74,7 @@ export default {
meta: { meta: {
title: 'samba', title: 'samba',
icon: 'preview', icon: 'preview',
roles: ['itManagement'],
}, },
component: () => import('src/pages/Account/AccountSamba.vue'), component: () => import('src/pages/Account/AccountSamba.vue'),
}, },