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.
410 lines
14 KiB
410 lines
14 KiB
3 years ago
|
<!-- eslint-disable -->
|
||
4 years ago
|
<template>
|
||
|
<div>
|
||
3 years ago
|
<v-card v-if="filteredGroupedData.length" 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>
|
||
3 years ago
|
<tr>
|
||
|
<th colspan="2" class="text-center" rowspan="3">
|
||
|
<div class="d-flex justify-center">
|
||
4 years ago
|
<v-tooltip bottom>
|
||
3 years ago
|
<template #activator="{ on }">
|
||
4 years ago
|
<v-checkbox
|
||
3 years ago
|
v-model="allToggle"
|
||
2 years ago
|
v-ge="['acl', 'toggle-checkbox']"
|
||
3 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>
|
||
3 years ago
|
<span class="title">{{ routesName }} Routes</span>
|
||
|
</div>
|
||
|
</th>
|
||
|
<th
|
||
|
v-for="role in roles"
|
||
|
:key="role"
|
||
|
:colspan="methods.length"
|
||
2 years ago
|
style="border-left: 1px solid grey; border-bottom: 1px solid grey"
|
||
3 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">
|
||
2 years ago
|
<template v-for="(method, i) in methods">
|
||
3 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>
|
||
3 years ago
|
</tr>
|
||
|
<tr>
|
||
|
<template v-for="role in roles">
|
||
2 years ago
|
<template v-for="(method, i) in methods">
|
||
3 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}`]"
|
||
2 years ago
|
v-ge="['acl', 'toggle-checkbox']"
|
||
3 years ago
|
class="mt-0"
|
||
|
dense
|
||
|
v-on="on"
|
||
2 years ago
|
@change="toggleColumn(role, method, columnToggle[`${method}_${role}`])"
|
||
3 years ago
|
/>
|
||
|
</template>
|
||
4 years ago
|
|
||
2 years ago
|
<span
|
||
|
>{{ columnToggle[`${method}_${role}`] ? 'Disable' : 'Enable' }} all {{ method }} routes for
|
||
|
{{ role }}</span
|
||
|
>
|
||
3 years ago
|
</v-tooltip>
|
||
|
</th>
|
||
4 years ago
|
</template>
|
||
3 years ago
|
</template>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tbody>
|
||
2 years ago
|
<tr v-for="([path, route], i) in filteredGroupedData" :key="i">
|
||
3 years ago
|
<td width="20" class="px-0">
|
||
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<v-checkbox
|
||
|
v-model="rowToggle[path]"
|
||
2 years ago
|
v-ge="['acl', 'toggle-checkbox']"
|
||
3 years ago
|
class="mt-0 ml-3"
|
||
|
dense
|
||
|
v-on="on"
|
||
2 years ago
|
@change="toggleRow(path, rowToggle[path])"
|
||
3 years ago
|
/>
|
||
|
</template>
|
||
4 years ago
|
|
||
3 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">
|
||
2 years ago
|
<template v-for="(method, i) in methods">
|
||
3 years ago
|
<td :key="`${path}_${method}_${role}`" :style="i ? '' : 'border-left: 1px solid grey'" class="pa-1">
|
||
|
<v-checkbox
|
||
|
v-if="route[method]"
|
||
|
v-model="route[method].acl[role]"
|
||
2 years ago
|
v-ge="['acl', 'toggle-checkbox']"
|
||
3 years ago
|
class="mt-0"
|
||
|
dense
|
||
|
:color="methodColor[method]"
|
||
|
:input-value="route[method].acl[role]"
|
||
2 years ago
|
@change="toggleCell(path, method, role, route[method].acl[role])"
|
||
3 years ago
|
/>
|
||
2 years ago
|
<span v-else>
|
||
3 years ago
|
<!-- todo: @dblclick="$set(data1[path],method , {})"-->
|
||
2 years ago
|
<v-checkbox v-ge="['acl', 'toggle-checkbox']" class="mt-0" dense :disabled="true"
|
||
|
/></span>
|
||
3 years ago
|
</td>
|
||
4 years ago
|
</template>
|
||
|
</template>
|
||
3 years ago
|
</tr>
|
||
4 years ago
|
</tbody>
|
||
|
</v-simple-table>
|
||
|
|
||
2 years ago
|
<v-alert v-else outlined type="info"> Permission file not found </v-alert>
|
||
4 years ago
|
</v-card>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
2 years ago
|
import { mapGetters } from 'vuex';
|
||
4 years ago
|
|
||
3 years ago
|
// const {fs, importFresh, shell, path} = require("electron").remote.require('./libs');
|
||
4 years ago
|
|
||
3 years ago
|
export default {
|
||
|
name: 'AclTsFileChild',
|
||
4 years ago
|
|
||
3 years ago
|
props: ['nodes', 'policyPath', 'search'],
|
||
3 years ago
|
data() {
|
||
3 years ago
|
return {
|
||
|
groupedData: null,
|
||
|
disableSaveButton: true,
|
||
|
// policyPath: '',
|
||
|
columnToggle: {},
|
||
|
rowToggle: {},
|
||
|
// allToggle: false,
|
||
|
methodColor: {
|
||
|
get: 'green',
|
||
|
post: 'orange',
|
||
|
put: 'deep-orange',
|
||
|
patch: 'pink lighten-1',
|
||
2 years ago
|
delete: 'red darken-3',
|
||
3 years ago
|
},
|
||
2 years ago
|
roles: ['creator', 'editor', 'guest'],
|
||
|
methods: ['get', 'post', 'put', 'delete'],
|
||
|
data1: null,
|
||
|
};
|
||
3 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
async aclInit() {
|
||
2 years ago
|
this.disableSaveButton = true;
|
||
4 years ago
|
|
||
3 years ago
|
try {
|
||
|
// this.data1 = JSON.parse(JSON.stringify(await this.sqlMgr.importFresh({path: this.policyPath})));
|
||
2 years ago
|
this.data1 = JSON.parse(
|
||
|
JSON.stringify(
|
||
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'importFresh', { path: this.policyPath }])
|
||
|
)
|
||
|
);
|
||
|
this.groupRoutes();
|
||
|
this.initColumnCheckBox();
|
||
|
this.initRowCheckBox();
|
||
3 years ago
|
} catch (e) {
|
||
2 years ago
|
console.log(e);
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
groupRoutes() {
|
||
2 years ago
|
const groupedData = {};
|
||
3 years ago
|
for (const route of this.data1) {
|
||
2 years ago
|
groupedData[route.path] = groupedData[route.path] || {};
|
||
|
groupedData[route.path][route.type] = route;
|
||
3 years ago
|
}
|
||
2 years ago
|
this.groupedData = groupedData;
|
||
3 years ago
|
},
|
||
3 years ago
|
toggleColumn(role, method, checked) {
|
||
3 years ago
|
for (const [path, methods] of Object.entries(this.groupedData)) {
|
||
|
if (methods[method]) {
|
||
2 years ago
|
this.$set(methods[method].acl, role, checked);
|
||
|
this.toggleCell(path, method, role, checked);
|
||
4 years ago
|
}
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
toggleRow(path, checked) {
|
||
3 years ago
|
for (const [method, route] of Object.entries(this.groupedData[path])) {
|
||
|
for (const role in route.acl) {
|
||
2 years ago
|
this.$set(route.acl, role, checked);
|
||
|
this.toggleCell(path, method, role, checked);
|
||
4 years ago
|
}
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
toggleAll(checked) {
|
||
2 years ago
|
this.disableSaveButton = false;
|
||
3 years ago
|
for (const path in this.groupedData) {
|
||
2 years ago
|
this.rowToggle[path] = checked;
|
||
3 years ago
|
}
|
||
|
for (const role of this.roles) {
|
||
|
for (const method of this.methods) {
|
||
2 years ago
|
this.columnToggle[`${method}_${role}`] = checked;
|
||
4 years ago
|
}
|
||
3 years ago
|
}
|
||
4 years ago
|
|
||
3 years ago
|
for (const methods of Object.values(this.groupedData)) {
|
||
|
for (const router of Object.values(methods)) {
|
||
|
for (const role of this.roles) {
|
||
2 years ago
|
this.$set(router.acl, role, checked);
|
||
4 years ago
|
}
|
||
|
}
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
toggleCell(path, method, role, checked) {
|
||
2 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))
|
||
|
);
|
||
3 years ago
|
},
|
||
3 years ago
|
initColumnCheckBox() {
|
||
3 years ago
|
for (const role of this.roles) {
|
||
|
for (const method of this.methods) {
|
||
2 years ago
|
this.columnToggle[`${method}_${role}`] = Object.values(this.groupedData).some(
|
||
|
methods => methods[method] && methods[method].acl[role]
|
||
|
);
|
||
4 years ago
|
}
|
||
|
}
|
||
|
},
|
||
3 years ago
|
initRowCheckBox() {
|
||
3 years ago
|
for (const path in this.groupedData) {
|
||
2 years ago
|
this.rowToggle[path] = Object.values(this.groupedData[path]).filter(
|
||
|
route =>
|
||
3 years ago
|
Object.entries(route.acl).filter(([role, v]) => {
|
||
2 years ago
|
if (!this.roles.includes(role)) {
|
||
|
this.roles = [...this.roles, role];
|
||
|
}
|
||
|
return v;
|
||
3 years ago
|
}).length
|
||
2 years ago
|
).length;
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async save() {
|
||
3 years ago
|
try {
|
||
2 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
null,
|
||
|
'writeFile',
|
||
|
{
|
||
|
path: this.policyPath,
|
||
|
data: `module.exports = ${JSON.stringify(this.data1, null, 2)}`,
|
||
|
},
|
||
|
]);
|
||
|
this.disableSaveButton = true;
|
||
|
this.$toast.success(`${this.policyPath} updated successfully`).goAway(3000);
|
||
3 years ago
|
} catch (e) {
|
||
2 years ago
|
console.log(e);
|
||
|
this.$toast.error(`${this.policyPath} updating failed`).goAway(3000);
|
||
3 years ago
|
}
|
||
2 years ago
|
},
|
||
3 years ago
|
},
|
||
|
computed: {
|
||
|
...mapGetters({ sqlMgr: 'sqlMgr/sqlMgr' }),
|
||
|
allToggle: {
|
||
3 years ago
|
get() {
|
||
2 years ago
|
return (
|
||
|
this.groupedData &&
|
||
|
Object.values(this.groupedData).some(methods =>
|
||
|
Object.values(methods).some(route => Object.values(route.acl).some(v => v))
|
||
3 years ago
|
)
|
||
2 years ago
|
);
|
||
4 years ago
|
},
|
||
3 years ago
|
set(checked) {
|
||
2 years ago
|
this.toggleAll(checked);
|
||
|
},
|
||
4 years ago
|
},
|
||
3 years ago
|
routesName() {
|
||
2 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
|
},
|
||
3 years ago
|
filteredGroupedData() {
|
||
3 years ago
|
return this.groupedData
|
||
2 years ago
|
? Object.entries(this.groupedData).filter(
|
||
|
([path]) => !this.search || path.toLowerCase().includes(this.search.toLowerCase())
|
||
|
)
|
||
|
: [];
|
||
|
},
|
||
3 years ago
|
},
|
||
|
watch: {},
|
||
3 years ago
|
async created() {
|
||
2 years ago
|
await this.aclInit();
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
2 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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|