mirror of https://github.com/nocodb/nocodb
333 lines
10 KiB
333 lines
10 KiB
4 years ago
|
<template>
|
||
|
<div>
|
||
|
<v-toolbar flat height="42" class="toolbar-border-bottom">
|
||
|
<!-- <v-toolbar-title>-->
|
||
|
<!-- <v-breadcrumbs :items="[{-->
|
||
|
<!-- text: nodes.env,-->
|
||
|
<!-- disabled: true,-->
|
||
|
<!-- href: '#'-->
|
||
|
<!-- },{-->
|
||
|
<!-- text: nodes.dbAlias,-->
|
||
|
<!-- disabled: true,-->
|
||
|
<!-- href: '#'-->
|
||
|
<!-- },-->
|
||
|
<!-- {-->
|
||
3 years ago
|
<!-- text: nodes.table_name + ' (Logic)',-->
|
||
4 years ago
|
<!-- disabled: true,-->
|
||
|
<!-- href: '#'-->
|
||
|
<!-- }]" divider=">" small>-->
|
||
|
<!-- <template v-slot:divider>-->
|
||
|
<!-- <v-icon small color="grey lighten-2">forward</v-icon>-->
|
||
|
<!-- </template>-->
|
||
|
<!-- </v-breadcrumbs>-->
|
||
|
|
||
|
<!-- </v-toolbar-title>-->
|
||
3 years ago
|
<v-spacer />
|
||
3 years ago
|
<!-- tooltip="Reload roles" -->
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['roles', 'reload']"
|
||
3 years ago
|
outlined
|
||
3 years ago
|
:tooltip="$t('activity.reloadRoles')"
|
||
3 years ago
|
color="primary"
|
||
|
small
|
||
|
:disabled="loading"
|
||
3 years ago
|
@click="
|
||
|
loadRoles();
|
||
|
loadAggrAcl();
|
||
|
"
|
||
3 years ago
|
>
|
||
3 years ago
|
<v-icon small left> refresh </v-icon>
|
||
3 years ago
|
{{ $t('general.reload') }}
|
||
4 years ago
|
</x-btn>
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['roles', 'add new']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Add new role"
|
||
|
color="primary"
|
||
|
small
|
||
|
:disabled="loading"
|
||
|
@click="comingSoon"
|
||
|
@click.prevent
|
||
|
>
|
||
3 years ago
|
<v-icon small left> mdi-plus </v-icon>
|
||
3 years ago
|
<!--New Role-->
|
||
|
{{ $t('activity.newRole') }}
|
||
4 years ago
|
</x-btn>
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['rows', 'save']"
|
||
3 years ago
|
outlined
|
||
3 years ago
|
:tooltip="$t('tooltip.saveChanges')"
|
||
3 years ago
|
color="primary"
|
||
|
small
|
||
|
:disabled="loading || !edited"
|
||
|
@click="save"
|
||
|
@click.prevent
|
||
|
>
|
||
3 years ago
|
<v-icon small left> save </v-icon>
|
||
3 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
4 years ago
|
</x-btn>
|
||
|
</v-toolbar>
|
||
|
<div class="" style="width: 100%">
|
||
|
<div class="d-flex justify-center mx-auto">
|
||
|
<v-card class="flex-shrink-1" style="">
|
||
3 years ago
|
<v-simple-table dense style="width: auto; min-width: 500px">
|
||
4 years ago
|
<thead>
|
||
3 years ago
|
<tr>
|
||
3 years ago
|
<th>Role Name</th>
|
||
3 years ago
|
|
||
3 years ago
|
<th>Role Description</th>
|
||
3 years ago
|
<th />
|
||
3 years ago
|
<!-- <th v-for="op in operations">
|
||
4 years ago
|
{{ op }}
|
||
|
</th>-->
|
||
3 years ago
|
</tr>
|
||
4 years ago
|
</thead>
|
||
|
<tbody>
|
||
3 years ago
|
<tr v-for="(role, i) in roles" :key="role.title">
|
||
3 years ago
|
<td>
|
||
3 years ago
|
<v-edit-dialog lazy>
|
||
3 years ago
|
<v-chip small :color="colors[i % colors.length]">
|
||
|
{{ role.title }}
|
||
|
</v-chip>
|
||
|
<template #input>
|
||
|
<v-text-field
|
||
|
v-model="role.title"
|
||
3 years ago
|
v-ge="['roles', 'title']"
|
||
3 years ago
|
:disabled="role.type === 'SYSTEM'"
|
||
3 years ago
|
:label="$t('general.edit')"
|
||
3 years ago
|
single-line
|
||
|
@input="edited = true"
|
||
|
/>
|
||
|
</template>
|
||
|
</v-edit-dialog>
|
||
|
</td>
|
||
|
<td>
|
||
3 years ago
|
<v-edit-dialog lazy>
|
||
3 years ago
|
<span> {{ role.description }}</span>
|
||
|
<template #input>
|
||
|
<v-text-field
|
||
|
v-model="role.description"
|
||
3 years ago
|
v-ge="['roles', 'title']"
|
||
3 years ago
|
:disabled="role.type === 'SYSTEM'"
|
||
3 years ago
|
:label="$t('general.edit')"
|
||
3 years ago
|
single-line
|
||
|
@input="edited = true"
|
||
|
/>
|
||
|
</template>
|
||
|
</v-edit-dialog>
|
||
|
</td>
|
||
|
|
||
|
<td>
|
||
|
<x-icon
|
||
|
v-if="role.type !== 'SYSTEM'"
|
||
|
small
|
||
|
color="error"
|
||
|
tooltip="Delete role"
|
||
3 years ago
|
@click="(deleteId = role.id), (deleteIndex = i), (showConfirmDlg = true)"
|
||
3 years ago
|
>
|
||
|
mdi-delete-forever
|
||
|
</x-icon>
|
||
3 years ago
|
<x-icon v-else small tooltip="System defined role can't be edited" color="info">
|
||
3 years ago
|
mdi-information-outline
|
||
|
</x-icon>
|
||
|
</td>
|
||
4 years ago
|
|
||
3 years ago
|
<!-- <td v-for="op in operations">
|
||
4 years ago
|
<v-tooltip
|
||
|
bottom
|
||
|
|
||
|
v-if="role.id && aggrAcl && aggrAcl[role.title]">
|
||
|
<template v-slot:activator="{on}">
|
||
|
<div v-on="on">
|
||
|
<v-checkbox
|
||
|
@change="edited = true"
|
||
|
v-model="aggrAcl[role.title][op]"
|
||
|
hide-details dense class="mt-n1 pt-0"
|
||
|
></v-checkbox>
|
||
|
</div>
|
||
|
</template>
|
||
|
<span>Disable/Enable access to {{ op }} operation for all tables in all databases.</span>
|
||
|
</v-tooltip>
|
||
|
</td>-->
|
||
3 years ago
|
</tr>
|
||
4 years ago
|
</tbody>
|
||
|
</v-simple-table>
|
||
|
</v-card>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<dlg-label-submit-cancel
|
||
|
type="primary"
|
||
|
:actions-mtd="confirmDelete"
|
||
|
heading="Do you want to delete the role?"
|
||
|
:dialog-show="showConfirmDlg"
|
||
3 years ago
|
/>
|
||
4 years ago
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import DlgLabelSubmitCancel from '~/components/utils/DlgLabelSubmitCancel';
|
||
|
import colors from '@/mixins/colors';
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
name: 'Roles',
|
||
|
components: { DlgLabelSubmitCancel },
|
||
4 years ago
|
mixins: [colors],
|
||
|
props: ['nodes'],
|
||
|
data: () => ({
|
||
|
loading: false,
|
||
|
roles: null,
|
||
|
edited: false,
|
||
|
showConfirmDlg: false,
|
||
|
deleteId: null,
|
||
|
deleteIndex: null,
|
||
3 years ago
|
aggrAcl: null,
|
||
4 years ago
|
}),
|
||
3 years ago
|
computed: {
|
||
3 years ago
|
operations() {
|
||
3 years ago
|
return ['create', 'read', 'update', 'delete'];
|
||
3 years ago
|
},
|
||
3 years ago
|
customRolesCount() {
|
||
3 years ago
|
return (this.roles && this.roles.filter(r => r.type !== 'SYSTEM').length) || 0;
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
async created() {
|
||
3 years ago
|
await this.loadRoles();
|
||
|
await this.loadAggrAcl();
|
||
4 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
async loadRoles() {
|
||
4 years ago
|
try {
|
||
3 years ago
|
this.roles = (
|
||
|
await this.$axios.get('/admin/roles', {
|
||
|
headers: {
|
||
|
'xc-auth': this.$store.state.users.token,
|
||
|
},
|
||
|
params: {
|
||
|
project_id: this.$route.params.project_id,
|
||
|
},
|
||
|
})
|
||
|
).data;
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Failed loading role list').goAway(3000);
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
this.edited = false;
|
||
4 years ago
|
},
|
||
3 years ago
|
async loadAggrAcl() {
|
||
4 years ago
|
/* try {
|
||
|
this.aggrAcl = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
// todo: manage dbAlias or get aggregated
|
||
|
{dbAlias: 'db'},
|
||
|
'xcAclAggregatedGet'
|
||
|
])
|
||
|
} catch (e) {
|
||
3 years ago
|
} */
|
||
4 years ago
|
},
|
||
3 years ago
|
addRole() {
|
||
4 years ago
|
this.roles.push({
|
||
|
title: ('role name ' + (this.customRolesCount || '')).trim(),
|
||
3 years ago
|
description: 'Role description',
|
||
|
});
|
||
|
this.edited = true;
|
||
|
this.scrollAndFocusLastRow();
|
||
4 years ago
|
},
|
||
3 years ago
|
async save() {
|
||
4 years ago
|
try {
|
||
3 years ago
|
await this.$axios.put(
|
||
|
'/admin/roles',
|
||
|
{ roles: this.roles },
|
||
|
{
|
||
|
headers: {
|
||
|
'xc-auth': this.$store.state.users.token,
|
||
|
},
|
||
4 years ago
|
}
|
||
3 years ago
|
);
|
||
4 years ago
|
|
||
|
/* await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
// todo: manage dbAlias or get aggregated
|
||
|
{dbAlias: 'db'},
|
||
|
'xcAclAggregatedSave',
|
||
|
this.aggrAcl
|
||
3 years ago
|
]) */
|
||
4 years ago
|
|
||
|
//
|
||
|
//
|
||
|
// this.$axios('sqlMgr/ActSqlOp', [{
|
||
|
// env: this.nodes.env,
|
||
|
// // todo: handle all dbs
|
||
|
// dbAlias: this.$store.state.project.authDbAlias
|
||
|
// }, 'projectSaveOrUpdateRoles', ]);
|
||
3 years ago
|
this.$toast.success('Successfully saved all changes').goAway(3000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error(e.response.data.msg).goAway(3000);
|
||
4 years ago
|
}
|
||
3 years ago
|
await this.loadRoles();
|
||
|
await this.loadAggrAcl();
|
||
4 years ago
|
},
|
||
3 years ago
|
async confirmDelete(hideDialog) {
|
||
4 years ago
|
if (hideDialog) {
|
||
3 years ago
|
this.showConfirmDlg = false;
|
||
|
return;
|
||
4 years ago
|
}
|
||
|
if (this.deleteId) {
|
||
|
try {
|
||
|
await this.$axios.delete('/admin/roles/' + this.deleteId, {
|
||
|
headers: {
|
||
3 years ago
|
'xc-auth': this.$store.state.users.token,
|
||
|
},
|
||
|
});
|
||
|
this.$toast.success('Successfully deleted role').goAway(3000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Failed deleting the role').goAway(3000);
|
||
4 years ago
|
}
|
||
3 years ago
|
await this.loadRoles();
|
||
4 years ago
|
} else {
|
||
3 years ago
|
this.roles.splice(this.deleteIndex, 1);
|
||
4 years ago
|
}
|
||
3 years ago
|
this.showConfirmDlg = false;
|
||
4 years ago
|
},
|
||
3 years ago
|
scrollAndFocusLastRow() {
|
||
4 years ago
|
this.$nextTick(() => {
|
||
3 years ago
|
document.querySelector('.project-container').scrollTop = 9999;
|
||
|
const menuActivator = this.$el && this.$el.querySelector('tr:last-child .v-small-dialog__activator__content');
|
||
4 years ago
|
if (menuActivator) {
|
||
3 years ago
|
menuActivator.click();
|
||
4 years ago
|
this.$nextTick(() => {
|
||
3 years ago
|
const inputField = document.querySelector('.menuable__content__active input');
|
||
|
inputField && inputField.select();
|
||
|
});
|
||
4 years ago
|
}
|
||
3 years ago
|
});
|
||
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
3 years ago
|
<style scoped></style>
|
||
4 years ago
|
<!--
|
||
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|