new package dbHandler accesscontrol memeberdb and login with rights
All checks were successful
Build Quasar SPA and Go Backend for memberApp / build-spa (push) Successful in 2m20s
Build Quasar SPA and Go Backend for memberApp / build-backend (amd64, .exe, windows) (push) Successful in 5m27s
Build Quasar SPA and Go Backend for memberApp / build-backend (amd64, , linux) (push) Successful in 5m32s
Build Quasar SPA and Go Backend for memberApp / build-backend (arm, 6, , linux) (push) Successful in 5m28s
Build Quasar SPA and Go Backend for memberApp / build-backend (arm64, , linux) (push) Successful in 5m29s
All checks were successful
Build Quasar SPA and Go Backend for memberApp / build-spa (push) Successful in 2m20s
Build Quasar SPA and Go Backend for memberApp / build-backend (amd64, .exe, windows) (push) Successful in 5m27s
Build Quasar SPA and Go Backend for memberApp / build-backend (amd64, , linux) (push) Successful in 5m32s
Build Quasar SPA and Go Backend for memberApp / build-backend (arm, 6, , linux) (push) Successful in 5m28s
Build Quasar SPA and Go Backend for memberApp / build-backend (arm64, , linux) (push) Successful in 5m29s
This commit is contained in:
@@ -3,6 +3,8 @@ import { ref, computed } from 'vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { i18n } from 'boot/lang';
|
||||
import type { Roles } from 'src/vueLib/models/roles';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
import { useLogin } from 'src/vueLib/login/useLogin';
|
||||
|
||||
export const roles = ref<Roles>([]);
|
||||
|
||||
@@ -31,11 +33,10 @@ export function useRoleTable() {
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'rights',
|
||||
name: 'permissions',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('rights'),
|
||||
field: 'rights',
|
||||
sortable: true,
|
||||
label: i18n.global.t('permissions'),
|
||||
field: '',
|
||||
style: 'width: 120px; max-width: 120px;',
|
||||
},
|
||||
{ name: 'option', align: 'center' as const, label: '', field: 'option', icon: 'option' },
|
||||
@@ -44,18 +45,21 @@ export function useRoleTable() {
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
const loading = ref(false);
|
||||
const userStore = useUserStore();
|
||||
const login = useLogin();
|
||||
|
||||
//updates user list from database
|
||||
function updateRoles() {
|
||||
async function updateRoles() {
|
||||
loading.value = true;
|
||||
appApi
|
||||
.get('secure/roles')
|
||||
await appApi
|
||||
.get('roles?id=0')
|
||||
.then((resp) => {
|
||||
if (resp.data === null) {
|
||||
roles.value = [];
|
||||
return;
|
||||
}
|
||||
roles.value = resp.data as Roles;
|
||||
|
||||
if (roles.value === null) {
|
||||
roles.value = [];
|
||||
return;
|
||||
@@ -68,6 +72,17 @@ export function useRoleTable() {
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
await appApi
|
||||
.get('/login/me')
|
||||
.then((resp) => {
|
||||
userStore
|
||||
.setUser({ id: resp.data.id, username: resp.data.username, role: resp.data.role })
|
||||
.catch((err) => console.log(err));
|
||||
login.refresh().catch((err) => console.error(err));
|
||||
})
|
||||
.catch(() => {
|
||||
login.logout().catch((err) => console.error(err));
|
||||
});
|
||||
}
|
||||
return {
|
||||
roles,
|
||||
|
||||
@@ -23,10 +23,17 @@
|
||||
>
|
||||
<template v-slot:top-left>
|
||||
<q-btn-group push flat style="color: grey">
|
||||
<q-btn dense flat icon="add" @click="openAllValueDialog(null)">
|
||||
<q-btn
|
||||
v-if="user.isPermittedTo('userSettings', 'write')"
|
||||
dense
|
||||
flat
|
||||
icon="add"
|
||||
@click="openAllValueDialog(null)"
|
||||
>
|
||||
<q-tooltip>{{ $t('addNewRole') }}</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
v-if="user.isPermittedTo('userSettings', 'write')"
|
||||
dense
|
||||
flat
|
||||
style="color: grey"
|
||||
@@ -62,21 +69,65 @@
|
||||
<template v-slot:body-cell="props">
|
||||
<q-td
|
||||
:props="props"
|
||||
@click="openSingleValueDialog(props.col.label, props.col.name, props.row)"
|
||||
:disable="!autorized(props.row)"
|
||||
:style="
|
||||
autorized(props.row) && user.isPermittedTo('userSettings', 'write')
|
||||
? 'cursor: pointer'
|
||||
: ''
|
||||
"
|
||||
@click="
|
||||
autorized(props.row) && user.isPermittedTo('userSettings', 'write')
|
||||
? openSingleValueDialog(props.col.label, props.col.name, props.row)
|
||||
: ''
|
||||
"
|
||||
>
|
||||
{{ props.value }}
|
||||
</q-td>
|
||||
</template>
|
||||
<template v-slot:body-cell-permissions="props">
|
||||
<q-td :props="props">
|
||||
<q-btn
|
||||
:disable="!autorized(props.row) || !user.isPermittedTo('userSettings', 'write')"
|
||||
flat
|
||||
dense
|
||||
icon="rule"
|
||||
:color="
|
||||
autorized(props.row) && user.isPermittedTo('userSettings', 'write')
|
||||
? 'secondary'
|
||||
: 'grey'
|
||||
"
|
||||
@click="
|
||||
user.isPermittedTo('userSettings', 'write') &&
|
||||
openAllValueDialog(props.row, 'permissions')
|
||||
"
|
||||
>
|
||||
<q-tooltip> {{ $t('permissions') }} </q-tooltip>
|
||||
</q-btn>
|
||||
</q-td>
|
||||
</template>
|
||||
<template v-slot:body-cell-option="props">
|
||||
<q-td :props="props">
|
||||
<q-btn flat dense icon="delete" color="negative" @click="openRemoveDialog(props.row)">
|
||||
<q-btn
|
||||
v-if="user.isPermittedTo('userSettings', 'delete')"
|
||||
:disable="!autorized(props.row)"
|
||||
flat
|
||||
dense
|
||||
icon="delete"
|
||||
color="negative"
|
||||
@click="openRemoveDialog(props.row)"
|
||||
>
|
||||
<q-tooltip> {{ $t('delete') }} </q-tooltip>
|
||||
</q-btn>
|
||||
</q-td>
|
||||
</template>
|
||||
</q-table>
|
||||
</div>
|
||||
<EditOneDialog ref="editOneDialog" v-on:update="updateRoles"></EditOneDialog>
|
||||
<EditOneDialog
|
||||
ref="editOneDialog"
|
||||
endpoint="roles/update"
|
||||
query-id
|
||||
v-on:update="updateRoles"
|
||||
></EditOneDialog>
|
||||
<EditAllDialog ref="editAllDialog" v-on:update="updateRoles"></EditAllDialog>
|
||||
<OkDialog
|
||||
ref="okDialog"
|
||||
@@ -101,6 +152,9 @@ import OkDialog from 'src/components/dialog/OkDialog.vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { useRoleTable } from './RoleTable';
|
||||
import { useLogin } from 'src/vueLib/login/useLogin';
|
||||
import { i18n } from 'src/boot/lang';
|
||||
import { QTable } from 'quasar';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const editOneDialog = ref();
|
||||
@@ -110,24 +164,33 @@ const deleteText = ref('');
|
||||
const selectOption = ref(false);
|
||||
const selected = ref<Roles>([]);
|
||||
const openSubmenu = ref(false);
|
||||
const currentUser = ref();
|
||||
const filter = ref('');
|
||||
const user = useUserStore();
|
||||
|
||||
const { roles, pagination, loading, columns, updateRoles } = useRoleTable();
|
||||
|
||||
//load on mounting page
|
||||
onMounted(() => {
|
||||
loading.value = true;
|
||||
updateRoles();
|
||||
const login = useLogin();
|
||||
currentUser.value = login.getUser();
|
||||
updateRoles().catch((err) => console.error(err));
|
||||
});
|
||||
|
||||
function autorized(role: Role): boolean {
|
||||
if (role.id !== 1) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// opens dialog for all role values
|
||||
function openSingleValueDialog(label: string, field: string, role: Role) {
|
||||
editOneDialog.value?.open(label, field, role);
|
||||
}
|
||||
|
||||
//opens dialog for one value
|
||||
function openAllValueDialog(role: Role | null) {
|
||||
editAllDialog.value?.open(role);
|
||||
function openAllValueDialog(role: Role | null, typ?: 'permissions') {
|
||||
editAllDialog.value?.open(role, typ);
|
||||
}
|
||||
|
||||
//opens remove dialog
|
||||
@@ -145,18 +208,22 @@ function removeRole(...removeRoles: Roles) {
|
||||
const roles: string[] = [];
|
||||
|
||||
removeRoles.forEach((role: Role) => {
|
||||
if (role.role) {
|
||||
if (role.role === currentUser.value.role) {
|
||||
NotifyResponse(i18n.global.t('notPossibleToDeleteLoggedInRole'), 'error');
|
||||
} else if (role.role) {
|
||||
roles.push(role.role);
|
||||
}
|
||||
});
|
||||
|
||||
const login = useLogin();
|
||||
const user = login.getUser();
|
||||
|
||||
appApi
|
||||
.post('secure/roles/delete?role=' + user?.role, { roles: roles })
|
||||
.then(() => {
|
||||
updateRoles();
|
||||
.post('roles/delete?role=' + currentUser.value.role, { roles: roles })
|
||||
.then((resp) => {
|
||||
updateRoles().catch((err) => console.error(err));
|
||||
if (roles.length === 1) {
|
||||
NotifyResponse("'" + roles[0] + "' " + i18n.global.t('deleted'), 'warning');
|
||||
} else {
|
||||
NotifyResponse(resp.data, 'warning');
|
||||
}
|
||||
selected.value = [];
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'))
|
||||
@@ -169,6 +236,7 @@ function getSelected(): Roles {
|
||||
if (selected.value.length === 0) return [];
|
||||
return selected.value;
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
getSelected,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user