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.
429 lines
14 KiB
429 lines
14 KiB
4 years ago
|
<!-- eslint-disable -->
|
||
4 years ago
|
<template>
|
||
|
<div>
|
||
4 years ago
|
<v-card v-if="filteredGroupedData.length" class="elevation-0" style="">
|
||
4 years ago
|
<!-- <v-toolbar flat height="42" class="toolbar-border-bottom">-->
|
||
|
<!-- <v-toolbar-title>-->
|
||
|
<!-- <v-breadcrumbs :items="[{-->
|
||
|
<!-- text: this.nodes.env,-->
|
||
|
<!-- disabled: true,-->
|
||
|
<!-- href: '#'-->
|
||
|
<!-- },{-->
|
||
|
<!-- text: this.nodes.dbAlias,-->
|
||
|
<!-- disabled: true,-->
|
||
|
<!-- href: '#'-->
|
||
|
<!-- },-->
|
||
|
<!-- {-->
|
||
3 years ago
|
<!-- text: this.nodes.table_name + ' (ACL)',-->
|
||
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>-->
|
||
|
<!-- <v-spacer></v-spacer>-->
|
||
|
<!-- <x-btn outlined tooltip="Reload ACL"-->
|
||
|
<!-- color="primary"-->
|
||
|
<!-- small-->
|
||
|
<!-- v-ge="['acl','reload']"-->
|
||
|
<!-- @click="aclInit"-->
|
||
|
<!-- >-->
|
||
|
<!-- <v-icon small left>refresh</v-icon>-->
|
||
|
<!-- Reload-->
|
||
|
<!-- </x-btn>-->
|
||
|
<!-- <x-btn tooltip="Open ACL Folder"-->
|
||
|
<!-- icon="mdi-folder-open"-->
|
||
|
<!-- outlined-->
|
||
|
<!-- small-->
|
||
|
<!-- color="primary"-->
|
||
|
<!-- v-ge="['acl','open-folder']"-->
|
||
|
<!-- @click="openFolder">-->
|
||
|
<!-- Open Folder-->
|
||
|
<!-- </x-btn>-->
|
||
|
<!-- <x-btn outlined tooltip="Save Changes"-->
|
||
|
<!-- color="primary"-->
|
||
|
<!-- class="primary"-->
|
||
|
<!-- small-->
|
||
|
<!-- @click="save"-->
|
||
|
<!-- :disabled="disableSaveButton"-->
|
||
|
<!-- v-ge="['acl','save']">-->
|
||
|
<!-- <v-icon small left>save</v-icon>-->
|
||
|
<!-- Save-->
|
||
|
<!-- </x-btn>-->
|
||
|
|
||
|
<!-- </v-toolbar>-->
|
||
|
|
||
3 years ago
|
<!-- <v-text-field dense hide-details class="ma-2" :placeholder="`Search ${nodes.table_name} routes`"-->
|
||
4 years ago
|
<!-- prepend-inner-icon="search" v-model="search"-->
|
||
|
<!-- outlined></v-text-field>-->
|
||
|
<v-simple-table v-if="data1" dense>
|
||
|
<thead>
|
||
4 years ago
|
<tr>
|
||
|
<th colspan="2" class="text-center" rowspan="3">
|
||
|
<div class="d-flex justify-center">
|
||
4 years ago
|
<v-tooltip bottom>
|
||
4 years ago
|
<template #activator="{ on }">
|
||
4 years ago
|
<v-checkbox
|
||
4 years ago
|
v-model="allToggle"
|
||
3 years ago
|
v-ge="['acl', 'toggle-checkbox']"
|
||
4 years ago
|
class="mt-1 flex-shrink-1"
|
||
|
dense
|
||
|
v-on="on"
|
||
|
/>
|
||
4 years ago
|
</template>
|
||
3 years ago
|
<span>{{ allToggle ? 'Disable' : 'Enable' }} all {{ nodes.table_name }} routes for all roles</span>
|
||
4 years ago
|
</v-tooltip>
|
||
4 years ago
|
<span class="title">{{ routesName }} Routes</span>
|
||
|
</div>
|
||
|
</th>
|
||
|
<th
|
||
|
v-for="role in roles"
|
||
|
:key="role"
|
||
|
:colspan="methods.length"
|
||
3 years ago
|
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>
|
||
|
<!-- <th colspan="2"></th>-->
|
||
|
<template v-for="role in roles">
|
||
3 years ago
|
<template v-for="(method, i) in methods">
|
||
4 years ago
|
<th
|
||
|
:key="`${method}_${role}`"
|
||
|
width="25"
|
||
|
class="caption px-1"
|
||
|
:style="i ? '' : 'border-left: 1px solid grey'"
|
||
|
>
|
||
|
{{ method }}
|
||
|
</th>
|
||
|
</template>
|
||
4 years ago
|
</template>
|
||
4 years ago
|
</tr>
|
||
|
<tr>
|
||
|
<template v-for="role in roles">
|
||
3 years ago
|
<template v-for="(method, i) in methods">
|
||
4 years ago
|
<th
|
||
|
:key="`${method}_${role}`"
|
||
|
width="25"
|
||
|
class="caption px-1"
|
||
|
:style="i ? '' : 'border-left: 1px solid grey'"
|
||
|
>
|
||
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<v-checkbox
|
||
|
v-model="columnToggle[`${method}_${role}`]"
|
||
3 years ago
|
v-ge="['acl', 'toggle-checkbox']"
|
||
4 years ago
|
class="mt-0"
|
||
|
dense
|
||
|
v-on="on"
|
||
3 years ago
|
@change="toggleColumn(role, method, columnToggle[`${method}_${role}`])"
|
||
4 years ago
|
/>
|
||
|
</template>
|
||
4 years ago
|
|
||
3 years ago
|
<span
|
||
|
>{{ columnToggle[`${method}_${role}`] ? 'Disable' : 'Enable' }} all {{ method }} routes for
|
||
|
{{ role }}</span
|
||
|
>
|
||
4 years ago
|
</v-tooltip>
|
||
|
</th>
|
||
4 years ago
|
</template>
|
||
4 years ago
|
</template>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody>
|
||
3 years ago
|
<tr v-for="([path, route], i) in filteredGroupedData" :key="i">
|
||
4 years ago
|
<td width="20" class="px-0">
|
||
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<v-checkbox
|
||
|
v-model="rowToggle[path]"
|
||
3 years ago
|
v-ge="['acl', 'toggle-checkbox']"
|
||
4 years ago
|
class="mt-0 ml-3"
|
||
|
dense
|
||
|
v-on="on"
|
||
3 years ago
|
@change="toggleRow(path, rowToggle[path])"
|
||
4 years ago
|
/>
|
||
|
</template>
|
||
4 years ago
|
|
||
4 years ago
|
<span>{{ rowToggle[path] ? 'Disable' : 'Enable' }} this route for all roles</span>
|
||
|
</v-tooltip>
|
||
|
</td>
|
||
|
<td class="pl-0">
|
||
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<span v-on="on">{{ path }}</span>
|
||
|
</template>
|
||
|
<span>{{ path }}</span>
|
||
|
</v-tooltip>
|
||
|
</td>
|
||
|
<template v-for="role in roles">
|
||
3 years ago
|
<template v-for="(method, i) in methods">
|
||
4 years ago
|
<td
|
||
|
:key="`${path}_${method}_${role}`"
|
||
|
:style="i ? '' : 'border-left: 1px solid grey'"
|
||
|
class="pa-1"
|
||
3 years ago
|
@dblclick="route[method] && showSourceCode(route, method)"
|
||
4 years ago
|
>
|
||
|
<v-checkbox
|
||
|
v-if="route[method]"
|
||
|
v-model="route[method].acl[role]"
|
||
3 years ago
|
v-ge="['acl', 'toggle-checkbox']"
|
||
4 years ago
|
class="mt-0"
|
||
|
dense
|
||
|
:color="methodColor[method]"
|
||
|
:input-value="route[method].acl[role]"
|
||
3 years ago
|
@change="toggleCell(path, method, role, route[method].acl[role])"
|
||
4 years ago
|
/>
|
||
3 years ago
|
<span v-else>
|
||
4 years ago
|
<!-- todo: @dblclick="$set(data1[path],method , {})"-->
|
||
3 years ago
|
<v-checkbox v-ge="['acl', 'toggle-checkbox']" class="mt-0" dense :disabled="true"
|
||
|
/></span>
|
||
4 years ago
|
</td>
|
||
4 years ago
|
</template>
|
||
|
</template>
|
||
4 years ago
|
</tr>
|
||
4 years ago
|
</tbody>
|
||
|
</v-simple-table>
|
||
|
|
||
3 years ago
|
<v-alert v-else outlined type="info"> Permission file not found </v-alert>
|
||
4 years ago
|
</v-card>
|
||
|
|
||
3 years ago
|
<handler-code-editor v-model="showCodeEditor" :nodes="nodes" :route="editRoute" :method="editMethod" />
|
||
4 years ago
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { mapGetters } from 'vuex';
|
||
|
import HandlerCodeEditor from '../RestHandlerCodeEditor';
|
||
4 years ago
|
|
||
|
// const {fs, importFresh, shell, path} = require("electron").remote.require('./libs');
|
||
|
|
||
|
export default {
|
||
4 years ago
|
name: 'AclTsFileDbChild',
|
||
|
components: { HandlerCodeEditor },
|
||
|
props: ['nodes', 'policies', 'search'],
|
||
4 years ago
|
data() {
|
||
4 years ago
|
return {
|
||
|
showCodeEditor: false,
|
||
|
editRoute: null,
|
||
|
editMethod: null,
|
||
|
groupedData: {},
|
||
|
disableSaveButton: true,
|
||
|
policyPath: '',
|
||
|
columnToggle: {},
|
||
|
rowToggle: {},
|
||
|
// allToggle: false,
|
||
|
methodColor: {
|
||
|
get: 'green',
|
||
|
post: 'orange',
|
||
|
put: 'deep-orange',
|
||
|
patch: 'pink lighten-1',
|
||
3 years ago
|
delete: 'red darken-3',
|
||
4 years ago
|
},
|
||
3 years ago
|
roles: ['creator', 'editor', 'guest'],
|
||
|
methods: ['get', 'post', 'put', 'delete'],
|
||
|
data1: null,
|
||
|
};
|
||
4 years ago
|
},
|
||
4 years ago
|
methods: {
|
||
4 years ago
|
showSourceCode(route, method) {
|
||
3 years ago
|
this.editRoute = route;
|
||
|
this.editMethod = method;
|
||
|
this.showCodeEditor = true;
|
||
4 years ago
|
},
|
||
4 years ago
|
aclInit() {
|
||
3 years ago
|
this.disableSaveButton = true;
|
||
4 years ago
|
try {
|
||
|
// this.data1 = JSON.parse(JSON.stringify(importFresh(this.policyPath)));
|
||
3 years ago
|
this.groupRoutes();
|
||
|
this.initColumnCheckBox();
|
||
|
this.initRowCheckBox();
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log(e);
|
||
4 years ago
|
}
|
||
|
},
|
||
4 years ago
|
groupRoutes() {
|
||
3 years ago
|
const groupedData = {};
|
||
4 years ago
|
for (const route of this.data1) {
|
||
|
if (route.path) {
|
||
3 years ago
|
groupedData[route.path] = groupedData[route.path] || {};
|
||
|
groupedData[route.path][route.type] = route;
|
||
4 years ago
|
}
|
||
|
}
|
||
3 years ago
|
this.groupedData = groupedData;
|
||
4 years ago
|
},
|
||
4 years ago
|
toggleColumn(role, method, checked) {
|
||
4 years ago
|
for (const [path, methods] of Object.entries(this.groupedData)) {
|
||
4 years ago
|
if (methods[method]) {
|
||
3 years ago
|
this.$set(methods[method].acl, role, checked);
|
||
|
this.toggleCell(path, method, role, checked);
|
||
4 years ago
|
}
|
||
|
}
|
||
|
},
|
||
4 years ago
|
toggleRow(path, checked) {
|
||
4 years ago
|
for (const [method, route] of Object.entries(this.groupedData[path])) {
|
||
|
for (const role in route.acl) {
|
||
3 years ago
|
this.$set(route.acl, role, checked);
|
||
|
this.toggleCell(path, method, role, checked);
|
||
4 years ago
|
}
|
||
|
}
|
||
|
},
|
||
4 years ago
|
toggleAll(checked) {
|
||
3 years ago
|
this.disableSaveButton = false;
|
||
4 years ago
|
for (const path in this.groupedData) {
|
||
3 years ago
|
this.rowToggle[path] = checked;
|
||
4 years ago
|
}
|
||
4 years ago
|
for (const role of this.roles) {
|
||
|
for (const method of this.methods) {
|
||
3 years ago
|
this.columnToggle[`${method}_${role}`] = checked;
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
for (const methods of Object.values(this.groupedData)) {
|
||
|
for (const router of Object.values(methods)) {
|
||
|
for (const role of this.roles) {
|
||
3 years ago
|
this.$set(router.acl, role, checked);
|
||
4 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
4 years ago
|
toggleCell(path, method, role, checked) {
|
||
3 years ago
|
this.disableSaveButton = false;
|
||
|
this.$set(
|
||
|
this.columnToggle,
|
||
|
`${method}_${role}`,
|
||
|
Object.values(this.groupedData).some(methods => methods[method] && methods[method].acl[role])
|
||
|
);
|
||
|
this.$set(
|
||
|
this.rowToggle,
|
||
|
path,
|
||
|
Object.values(this.groupedData[path]).some(route => Object.values(route.acl).some(v => v))
|
||
|
);
|
||
4 years ago
|
},
|
||
4 years ago
|
initColumnCheckBox() {
|
||
4 years ago
|
for (const role of this.roles) {
|
||
|
for (const method of this.methods) {
|
||
3 years ago
|
this.columnToggle[`${method}_${role}`] = Object.values(this.groupedData).some(
|
||
|
methods => methods[method] && methods[method].acl[role]
|
||
|
);
|
||
4 years ago
|
}
|
||
|
}
|
||
|
},
|
||
4 years ago
|
initRowCheckBox() {
|
||
4 years ago
|
for (const path in this.groupedData) {
|
||
3 years ago
|
this.rowToggle[path] = Object.values(this.groupedData[path]).filter(
|
||
|
route =>
|
||
4 years ago
|
Object.entries(route.acl).filter(([role, v]) => {
|
||
4 years ago
|
if (!this.roles.includes(role)) {
|
||
3 years ago
|
this.roles = [...this.roles, role];
|
||
4 years ago
|
}
|
||
3 years ago
|
return v;
|
||
4 years ago
|
}).length
|
||
3 years ago
|
).length;
|
||
4 years ago
|
}
|
||
|
},
|
||
4 years ago
|
async save() {
|
||
4 years ago
|
try {
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
null,
|
||
|
'xcRoutesPolicyUpdate',
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
tn: this.nodes.table_name,
|
||
|
data: this.data1,
|
||
|
},
|
||
|
]);
|
||
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.groupedData &&
|
||
|
Object.values(this.groupedData).some(methods =>
|
||
|
Object.values(methods).some(route => Object.values(route.acl).some(v => v))
|
||
4 years ago
|
)
|
||
3 years ago
|
);
|
||
4 years ago
|
},
|
||
4 years ago
|
set(checked) {
|
||
3 years ago
|
this.toggleAll(checked);
|
||
|
},
|
||
4 years ago
|
},
|
||
4 years ago
|
routesName() {
|
||
3 years ago
|
return (
|
||
|
this.policyPath &&
|
||
|
this.policyPath
|
||
|
.split('/')
|
||
|
.pop()
|
||
|
.replace(/\.routes.js$/, '')
|
||
|
.replace(/(?:^|\.)(\w+)/g, (_, m) => {
|
||
|
if (m === 'bt') {
|
||
|
return ' BelongsTo';
|
||
|
}
|
||
|
if (m === 'hm') {
|
||
|
return ' HasMany';
|
||
|
}
|
||
|
return ' ' + m[0].toUpperCase() + m.slice(1);
|
||
|
})
|
||
|
);
|
||
4 years ago
|
},
|
||
4 years ago
|
filteredGroupedData() {
|
||
3 years ago
|
return Object.entries(this.groupedData).filter(
|
||
|
([path]) => !this.search || path.toLowerCase().includes(this.search.toLowerCase())
|
||
|
);
|
||
|
},
|
||
4 years ago
|
},
|
||
|
watch: {
|
||
4 years ago
|
policies(d) {
|
||
3 years ago
|
this.data1 = JSON.parse(JSON.stringify(d));
|
||
|
this.aclInit();
|
||
|
},
|
||
4 years ago
|
},
|
||
4 years ago
|
async mounted() {
|
||
3 years ago
|
this.data1 = JSON.parse(JSON.stringify(this.policies));
|
||
|
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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|