|
|
|
@ -1,48 +1,56 @@
|
|
|
|
|
<script setup>
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
import { computed, onMounted, ref } from 'vue';
|
|
|
|
|
import { computed, onMounted, ref, toRefs } from 'vue';
|
|
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
|
import { useVnConfirm } from 'composables/useVnConfirm';
|
|
|
|
|
import { useRoute } from 'vue-router';
|
|
|
|
|
import { useAcl } from 'src/composables/useAcl';
|
|
|
|
|
import { useArrayData } from 'src/composables/useArrayData';
|
|
|
|
|
import { useState } from 'src/composables/useState';
|
|
|
|
|
import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
|
|
|
|
import VnChangePassword from 'src/components/common/VnChangePassword.vue';
|
|
|
|
|
import useNotify from 'src/composables/useNotify.js';
|
|
|
|
|
import useHasAccount from 'src/composables/useHasAccount.js';
|
|
|
|
|
import VnInputPassword from 'src/components/common/VnInputPassword.vue';
|
|
|
|
|
import VnChangePassword from 'src/components/common/VnChangePassword.vue';
|
|
|
|
|
import { useQuasar } from 'quasar';
|
|
|
|
|
import { useRouter } from 'vue-router';
|
|
|
|
|
|
|
|
|
|
const $props = defineProps({
|
|
|
|
|
entityId: {
|
|
|
|
|
type: Number,
|
|
|
|
|
hasAccount: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
|
|
|
|
required: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
|
const { hasAccount } = toRefs($props);
|
|
|
|
|
const { openConfirmationModal } = useVnConfirm();
|
|
|
|
|
const { notify } = useNotify();
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const state = useState();
|
|
|
|
|
const user = state.getUser();
|
|
|
|
|
const { notify } = useQuasar();
|
|
|
|
|
const account = computed(() => useArrayData('AccountId').store.data[0]);
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
account.value.hasAccount = await useHasAccount($props.entityId);
|
|
|
|
|
});
|
|
|
|
|
account.value.hasAccount = hasAccount.value;
|
|
|
|
|
const entityId = computed(() => +route.params.id);
|
|
|
|
|
const hasitManagementAccess = ref();
|
|
|
|
|
const hasSysadminAccess = ref();
|
|
|
|
|
|
|
|
|
|
async function updateStatusAccount(active) {
|
|
|
|
|
if (active) {
|
|
|
|
|
await axios.post(`Accounts`, { id: $props.entityId });
|
|
|
|
|
await axios.post(`Accounts`, { id: entityId.value });
|
|
|
|
|
} else {
|
|
|
|
|
await axios.delete(`Accounts/${$props.entityId}`);
|
|
|
|
|
await axios.delete(`Accounts/${entityId.value}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
account.value.hasAccount = active;
|
|
|
|
|
const status = active ? 'enable' : 'disable';
|
|
|
|
|
notify({
|
|
|
|
|
message: t(`account.card.${status}Account.success`),
|
|
|
|
|
message: t(`account.card.actions.${status}Account.success`),
|
|
|
|
|
type: 'positive',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
async function updateStatusUser(active) {
|
|
|
|
|
await axios.patch(`VnUsers/${$props.entityId}`, { active });
|
|
|
|
|
await axios.patch(`VnUsers/${entityId.value}`, { active });
|
|
|
|
|
account.value.active = active;
|
|
|
|
|
const status = active ? 'activate' : 'deactivate';
|
|
|
|
|
notify({
|
|
|
|
@ -50,6 +58,17 @@ async function updateStatusUser(active) {
|
|
|
|
|
type: 'positive',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function deleteAccount() {
|
|
|
|
|
const { data } = await axios.delete(`VnUsers/${entityId.value}`);
|
|
|
|
|
if (data) {
|
|
|
|
|
notify({
|
|
|
|
|
message: t('account.card.actions.delete.success'),
|
|
|
|
|
type: 'positive',
|
|
|
|
|
});
|
|
|
|
|
router.push({ name: 'AccountList' });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const showSyncDialog = ref(false);
|
|
|
|
|
const syncPassword = ref(null);
|
|
|
|
|
const shouldSyncPassword = ref(false);
|
|
|
|
@ -64,11 +83,27 @@ async function sync() {
|
|
|
|
|
type: 'positive',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const askOldPass = ref(false);
|
|
|
|
|
const changePassRef = ref();
|
|
|
|
|
|
|
|
|
|
const onChangePass = (oldPass) => {
|
|
|
|
|
askOldPass.value = oldPass;
|
|
|
|
|
changePassRef.value.show();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
hasitManagementAccess.value = useAcl().hasAny([
|
|
|
|
|
{ model: 'VnUser', props: 'higherPrivileges', accessType: 'WRITE' },
|
|
|
|
|
]);
|
|
|
|
|
hasSysadminAccess.value = useAcl().hasAny([
|
|
|
|
|
{ model: 'VnUser', props: 'adminUser', accessType: 'WRITE' },
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<template>
|
|
|
|
|
<VnChangePassword
|
|
|
|
|
ref="changePassRef"
|
|
|
|
|
:ask-old-pass="true"
|
|
|
|
|
:ask-old-pass="askOldPass"
|
|
|
|
|
:submit-fn="
|
|
|
|
|
async (newPassword, oldPassword) => {
|
|
|
|
|
await axios.patch(`Accounts/change-password`, {
|
|
|
|
@ -110,18 +145,46 @@ async function sync() {
|
|
|
|
|
</template>
|
|
|
|
|
</VnConfirm>
|
|
|
|
|
<QItem
|
|
|
|
|
v-if="
|
|
|
|
|
entityId == account.id &&
|
|
|
|
|
useAcl().hasAny([{ model: 'Account', props: '*', accessType: 'WRITE' }])
|
|
|
|
|
"
|
|
|
|
|
v-if="hasitManagementAccess"
|
|
|
|
|
v-ripple
|
|
|
|
|
clickable
|
|
|
|
|
@click="$refs.changePassRef.show()"
|
|
|
|
|
@click="
|
|
|
|
|
openConfirmationModal(
|
|
|
|
|
t('account.card.actions.disableAccount.title'),
|
|
|
|
|
t('account.card.actions.disableAccount.subtitle'),
|
|
|
|
|
() => deleteAccount()
|
|
|
|
|
)
|
|
|
|
|
"
|
|
|
|
|
>
|
|
|
|
|
<QItemSection>{{ t('globals.changePass') }}</QItemSection>
|
|
|
|
|
<QItemSection>{{ t('globals.delete') }}</QItemSection>
|
|
|
|
|
</QItem>
|
|
|
|
|
<QItem
|
|
|
|
|
v-if="account.hasAccount"
|
|
|
|
|
v-if="hasSysadminAccess"
|
|
|
|
|
v-ripple
|
|
|
|
|
clickable
|
|
|
|
|
@click="user.id === account.id ? onChangePass(true) : onChangePass(false)"
|
|
|
|
|
>
|
|
|
|
|
<QItemSection v-if="user.id === account.id">
|
|
|
|
|
{{ t('globals.changePass') }}
|
|
|
|
|
</QItemSection>
|
|
|
|
|
<QItemSection v-else>{{ t('globals.setPass') }}</QItemSection>
|
|
|
|
|
</QItem>
|
|
|
|
|
<QItem
|
|
|
|
|
v-if="!account.hasAccount && hasSysadminAccess"
|
|
|
|
|
v-ripple
|
|
|
|
|
clickable
|
|
|
|
|
@click="
|
|
|
|
|
openConfirmationModal(
|
|
|
|
|
t('account.card.actions.enableAccount.title'),
|
|
|
|
|
t('account.card.actions.enableAccount.subtitle'),
|
|
|
|
|
() => updateStatusAccount(true)
|
|
|
|
|
)
|
|
|
|
|
"
|
|
|
|
|
>
|
|
|
|
|
<QItemSection>{{ t('account.card.actions.enableAccount.name') }}</QItemSection>
|
|
|
|
|
</QItem>
|
|
|
|
|
<QItem
|
|
|
|
|
v-if="account.hasAccount && hasSysadminAccess"
|
|
|
|
|
v-ripple
|
|
|
|
|
clickable
|
|
|
|
|
@click="
|
|
|
|
@ -136,7 +199,7 @@ async function sync() {
|
|
|
|
|
</QItem>
|
|
|
|
|
|
|
|
|
|
<QItem
|
|
|
|
|
v-if="!account.active"
|
|
|
|
|
v-if="!account.active && hasitManagementAccess"
|
|
|
|
|
v-ripple
|
|
|
|
|
clickable
|
|
|
|
|
@click="
|
|
|
|
@ -150,7 +213,7 @@ async function sync() {
|
|
|
|
|
<QItemSection>{{ t('account.card.actions.activateUser.name') }}</QItemSection>
|
|
|
|
|
</QItem>
|
|
|
|
|
<QItem
|
|
|
|
|
v-if="account.active"
|
|
|
|
|
v-if="account.active && hasitManagementAccess"
|
|
|
|
|
v-ripple
|
|
|
|
|
clickable
|
|
|
|
|
@click="
|
|
|
|
@ -163,7 +226,12 @@ async function sync() {
|
|
|
|
|
>
|
|
|
|
|
<QItemSection>{{ t('account.card.actions.deactivateUser.name') }}</QItemSection>
|
|
|
|
|
</QItem>
|
|
|
|
|
<QItem v-ripple clickable @click="showSyncDialog = true">
|
|
|
|
|
<QItem
|
|
|
|
|
v-if="useAcl().hasAny([{ model: 'VnRole', props: '*', accessType: 'WRITE' }])"
|
|
|
|
|
v-ripple
|
|
|
|
|
clickable
|
|
|
|
|
@click="showSyncDialog = true"
|
|
|
|
|
>
|
|
|
|
|
<QItemSection>{{ t('account.card.actions.sync.name') }}</QItemSection>
|
|
|
|
|
</QItem>
|
|
|
|
|
<QSeparator />
|
|
|
|
|