mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
361 lines
11 KiB
361 lines
11 KiB
4 years ago
|
<!-- eslint-disable -->
|
||
4 years ago
|
<template>
|
||
|
<div>
|
||
|
<v-card style="">
|
||
|
<v-toolbar flat height="42" class="toolbar-border-bottom">
|
||
|
<v-toolbar-title>
|
||
4 years ago
|
<v-breadcrumbs
|
||
3 years ago
|
:items="[
|
||
|
{
|
||
|
text: nodes.env,
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
{
|
||
|
text: nodes.dbAlias,
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
{
|
||
|
text: nodes.table_name + ' (ACL)',
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
]"
|
||
4 years ago
|
divider=">"
|
||
|
small
|
||
|
>
|
||
|
<template #divider>
|
||
3 years ago
|
<v-icon small color="grey lighten-2"> forward </v-icon>
|
||
4 years ago
|
</template>
|
||
|
</v-breadcrumbs>
|
||
|
</v-toolbar-title>
|
||
4 years ago
|
<v-spacer />
|
||
3 years ago
|
<x-btn v-ge="['acl-gql', 'reload']" outlined tooltip="Reload ACL" color="primary" small @click="aclInit">
|
||
|
<v-icon small left> refresh </v-icon>
|
||
3 years ago
|
<!-- Reload -->
|
||
|
{{ $t('general.reload') }}
|
||
4 years ago
|
</x-btn>
|
||
4 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['acl-gql', 'open-folder']"
|
||
4 years ago
|
tooltip="Open ACL Folder"
|
||
|
icon="mdi-folder-open"
|
||
|
outlined
|
||
|
small
|
||
|
color="primary"
|
||
|
@click="openFolder"
|
||
|
>
|
||
4 years ago
|
Open Folder
|
||
|
</x-btn>
|
||
4 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['acl-gql', 'save']"
|
||
4 years ago
|
outlined
|
||
|
tooltip="Save ACL"
|
||
|
color="primary"
|
||
|
class="primary"
|
||
|
small
|
||
|
:disabled="disableSaveButton"
|
||
|
@click="save"
|
||
|
>
|
||
3 years ago
|
<v-icon small left> save </v-icon>
|
||
3 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
4 years ago
|
</x-btn>
|
||
|
</v-toolbar>
|
||
|
|
||
4 years ago
|
<v-text-field
|
||
|
v-model="search"
|
||
|
dense
|
||
|
hide-details
|
||
|
class="ma-2"
|
||
3 years ago
|
:placeholder="`Search ${nodes.table_name} resolvers`"
|
||
4 years ago
|
prepend-inner-icon="search"
|
||
|
outlined
|
||
|
/>
|
||
4 years ago
|
|
||
|
<v-simple-table v-if="policies && policies.length" dense>
|
||
|
<thead>
|
||
4 years ago
|
<tr>
|
||
|
<th colspan="2" class="text-center" rowspan="2">
|
||
|
<div class="d-flex justify-center">
|
||
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<v-checkbox
|
||
|
v-model="allToggle"
|
||
3 years ago
|
v-ge="['acl-gql', 'open-folder']"
|
||
4 years ago
|
small
|
||
|
class="mt-1 flex-shrink-1"
|
||
|
dense
|
||
|
v-on="on"
|
||
|
/>
|
||
|
</template>
|
||
3 years ago
|
<span>{{ allToggle ? 'Disable' : 'Enable' }} all {{ nodes.table_name }} resolvers for all roles</span>
|
||
4 years ago
|
</v-tooltip>
|
||
3 years ago
|
<span class="title">{{ nodes.table_name }} Resolvers</span>
|
||
4 years ago
|
</div>
|
||
|
</th>
|
||
3 years ago
|
<th v-for="role in roles" style="border-left: 1px solid grey; border-bottom: 1px solid grey">
|
||
4 years ago
|
<div class="d-flex align-center justify-center">
|
||
|
<span>{{ role }}</span>
|
||
|
</div>
|
||
|
</th>
|
||
|
</tr>
|
||
|
<tr>
|
||
3 years ago
|
<th v-for="role in roles" class="pa-1" style="border-left: 1px solid grey; border-bottom: 1px solid grey">
|
||
4 years ago
|
<div class="d-flex justify-center">
|
||
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<v-checkbox
|
||
|
v-model="columnToggle[role]"
|
||
3 years ago
|
v-ge="['acl-gql', 'open-folder']"
|
||
4 years ago
|
small
|
||
|
class="mt-0"
|
||
|
dense
|
||
|
v-on="on"
|
||
3 years ago
|
@change="toggleColumn(role, columnToggle[role])"
|
||
4 years ago
|
/>
|
||
|
</template>
|
||
|
<span>
|
||
3 years ago
|
<span>{{ columnToggle[role] ? 'Disable' : 'Enable' }} all resolvers for {{ role }}</span></span
|
||
|
>
|
||
4 years ago
|
</v-tooltip>
|
||
|
</div>
|
||
|
</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody>
|
||
3 years ago
|
<tr
|
||
|
v-for="(resolver, path) in data1"
|
||
|
v-show="!search || path.toLowerCase().indexOf(search.toLowerCase()) > -1"
|
||
|
key="path"
|
||
|
:
|
||
|
>
|
||
4 years ago
|
<td width="20" class="pl-6 pr-3">
|
||
4 years ago
|
<v-tooltip bottom>
|
||
4 years ago
|
<template #activator="{ on }">
|
||
4 years ago
|
<v-checkbox
|
||
4 years ago
|
v-model="rowToggle[path]"
|
||
3 years ago
|
v-ge="['acl-gql', 'open-folder']"
|
||
4 years ago
|
small
|
||
|
class="mt-0 ml-3"
|
||
|
dense
|
||
|
v-on="on"
|
||
3 years ago
|
@change="toggleRow(path, rowToggle[path])"
|
||
4 years ago
|
/>
|
||
4 years ago
|
</template>
|
||
|
|
||
4 years ago
|
<span>{{ rowToggle[path] ? 'Disable' : 'Enable' }} this resolver for all roles</span>
|
||
|
</v-tooltip>
|
||
|
</td>
|
||
|
<td class="pl-0">
|
||
4 years ago
|
<v-tooltip bottom>
|
||
4 years ago
|
<template #activator="{ on }">
|
||
|
<span v-on="on">{{ path }}</span>
|
||
4 years ago
|
</template>
|
||
4 years ago
|
<span>{{ path }}</span>
|
||
4 years ago
|
</v-tooltip>
|
||
|
</td>
|
||
3 years ago
|
<template v-for="role in roles">
|
||
4 years ago
|
<td :key="`${path}_${role}`" style="border-left: 1px solid grey" class="pa-1">
|
||
|
<div class="d-flex justify-center">
|
||
|
<v-checkbox
|
||
|
v-model="data1[path][role]"
|
||
3 years ago
|
v-ge="['acl-gql', 'open-folder']"
|
||
4 years ago
|
small
|
||
|
class="mt-0"
|
||
|
dense
|
||
3 years ago
|
@change="toggleCell(path, role, data1[path][role])"
|
||
4 years ago
|
/>
|
||
|
</div>
|
||
|
</td>
|
||
|
</template>
|
||
|
</tr>
|
||
4 years ago
|
</tbody>
|
||
|
</v-simple-table>
|
||
|
|
||
3 years ago
|
<v-alert v-else-if="policies" outlined type="info"> Permission file not found </v-alert>
|
||
4 years ago
|
</v-card>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { mapGetters } from 'vuex';
|
||
4 years ago
|
|
||
|
// const {fs, importFresh, shell, path} = require("electron").remote.require('./libs');
|
||
|
|
||
|
export default {
|
||
4 years ago
|
name: 'AclTsFileDbGql',
|
||
4 years ago
|
|
||
4 years ago
|
props: ['nodes'],
|
||
4 years ago
|
data() {
|
||
4 years ago
|
return {
|
||
|
disableSaveButton: true,
|
||
|
search: '',
|
||
|
policyPath: '',
|
||
|
policies: null,
|
||
|
columnToggle: {},
|
||
|
rowToggle: {},
|
||
3 years ago
|
roles: ['creator', 'editor', 'guest'],
|
||
|
data1: null,
|
||
|
};
|
||
4 years ago
|
},
|
||
4 years ago
|
methods: {
|
||
4 years ago
|
openFolder() {
|
||
4 years ago
|
// shell.openItem(path.dirname(this.policyPath));
|
||
|
},
|
||
4 years ago
|
toggleColumn(role, checked) {
|
||
4 years ago
|
for (const [resolver, roles] of Object.entries(this.data1)) {
|
||
3 years ago
|
this.$set(roles, role, checked);
|
||
|
this.toggleCell(resolver, role, checked);
|
||
4 years ago
|
}
|
||
|
},
|
||
4 years ago
|
toggleRow(resolver, checked) {
|
||
4 years ago
|
for (const role in this.data1[resolver]) {
|
||
3 years ago
|
this.$set(this.data1[resolver], role, checked);
|
||
|
this.toggleCell(resolver, role, checked);
|
||
4 years ago
|
}
|
||
|
},
|
||
4 years ago
|
toggleAll(checked) {
|
||
3 years ago
|
this.disableSaveButton = false;
|
||
4 years ago
|
for (const path in this.data1) {
|
||
3 years ago
|
this.rowToggle[path] = checked;
|
||
4 years ago
|
}
|
||
4 years ago
|
for (const role of this.roles) {
|
||
3 years ago
|
this.columnToggle[role] = checked;
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
for (const roles of Object.values(this.data1)) {
|
||
|
for (const role of this.roles) {
|
||
3 years ago
|
this.$set(roles, role, checked);
|
||
4 years ago
|
}
|
||
|
}
|
||
|
},
|
||
4 years ago
|
toggleCell(resolver, role, checked) {
|
||
3 years ago
|
this.disableSaveButton = false;
|
||
|
this.$set(
|
||
|
this.columnToggle,
|
||
|
role,
|
||
|
Object.values(this.data1).some(roles => roles[role])
|
||
|
);
|
||
|
this.$set(
|
||
|
this.rowToggle,
|
||
|
resolver,
|
||
|
Object.values(this.data1[resolver]).some(enabled => enabled)
|
||
|
);
|
||
4 years ago
|
},
|
||
4 years ago
|
initColumnCheckBox() {
|
||
4 years ago
|
for (const role of this.roles) {
|
||
3 years ago
|
this.columnToggle[role] = Object.values(this.data1).some(roles => roles[role]);
|
||
4 years ago
|
}
|
||
|
},
|
||
4 years ago
|
initRowCheckBox() {
|
||
4 years ago
|
for (const path in this.data1) {
|
||
4 years ago
|
this.rowToggle[path] = Object.entries(this.data1[path]).filter(([role, v]) => {
|
||
3 years ago
|
if (!this.roles.includes(role)) {
|
||
|
this.roles = [...this.roles, role];
|
||
|
}
|
||
|
return v;
|
||
|
}).length;
|
||
4 years ago
|
}
|
||
|
},
|
||
4 years ago
|
async aclInit() {
|
||
4 years ago
|
try {
|
||
3 years ago
|
console.log(this.sqlMgr);
|
||
|
this.disableSaveButton = true;
|
||
4 years ago
|
// this.policies = (await this.sqlMgr.xcResolverPolicyGet({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias,
|
||
3 years ago
|
// tn: this.nodes.table_name
|
||
4 years ago
|
// })).data.list;
|
||
3 years ago
|
this.policies = (
|
||
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
null,
|
||
|
'xcResolverPolicyGet',
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
tn: this.nodes.table_name,
|
||
|
},
|
||
|
])
|
||
|
).data.list;
|
||
4 years ago
|
|
||
4 years ago
|
// .data.list;
|
||
3 years ago
|
this.data = JSON.parse(JSON.stringify(this.policies));
|
||
4 years ago
|
this.data1 = this.data.reduce((aclObj, resolver) => {
|
||
|
if (resolver.resolver) {
|
||
3 years ago
|
aclObj[resolver.resolver] = resolver.acl;
|
||
4 years ago
|
}
|
||
3 years ago
|
return aclObj;
|
||
|
}, {});
|
||
4 years ago
|
|
||
3 years ago
|
this.initColumnCheckBox();
|
||
|
this.initRowCheckBox();
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log(e);
|
||
4 years ago
|
}
|
||
|
},
|
||
4 years ago
|
async save() {
|
||
4 years ago
|
try {
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
null,
|
||
|
'xcResolverPolicyUpdate',
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
tn: this.nodes.table_name,
|
||
|
data: this.data,
|
||
|
},
|
||
|
]);
|
||
4 years ago
|
|
||
3 years ago
|
this.disableSaveButton = true;
|
||
|
this.$toast.success(`${this.policyPath} updated successfully`).goAway(3000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log(e);
|
||
|
this.$toast.error(`${this.policyPath} updating failed`).goAway(3000);
|
||
4 years ago
|
}
|
||
3 years ago
|
},
|
||
4 years ago
|
},
|
||
|
computed: {
|
||
4 years ago
|
...mapGetters({ sqlMgr: 'sqlMgr/sqlMgr' }),
|
||
4 years ago
|
allToggle: {
|
||
4 years ago
|
get() {
|
||
3 years ago
|
return this.data1 && Object.values(this.data1).some(roles => Object.values(roles).some(v => v));
|
||
4 years ago
|
},
|
||
4 years ago
|
set(checked) {
|
||
3 years ago
|
this.toggleAll(checked);
|
||
|
},
|
||
|
},
|
||
4 years ago
|
},
|
||
4 years ago
|
watch: {},
|
||
4 years ago
|
async mounted() {
|
||
3 years ago
|
await this.aclInit();
|
||
|
},
|
||
|
};
|
||
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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|