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.
352 lines
10 KiB
352 lines
10 KiB
3 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)',-->
|
||
3 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
|
||
|
v-ge="['roles','reload']"
|
||
|
outlined
|
||
3 years ago
|
:tooltip="$t('activity.reloadRoles')"
|
||
3 years ago
|
color="primary"
|
||
|
small
|
||
|
:disabled="loading"
|
||
|
@click="loadRoles(); loadAggrAcl();"
|
||
|
>
|
||
|
<v-icon small left>
|
||
|
refresh
|
||
|
</v-icon>
|
||
3 years ago
|
{{ $t('general.reload') }}
|
||
3 years ago
|
</x-btn>
|
||
3 years ago
|
<x-btn
|
||
|
v-ge="['roles','add new']"
|
||
|
outlined
|
||
|
tooltip="Add new role"
|
||
|
color="primary"
|
||
|
small
|
||
|
:disabled="loading"
|
||
|
@click="comingSoon"
|
||
|
@click.prevent
|
||
|
>
|
||
|
<v-icon small left>
|
||
|
mdi-plus
|
||
|
</v-icon>
|
||
3 years ago
|
<!--New Role-->
|
||
|
{{ $t('activity.newRole') }}
|
||
3 years ago
|
</x-btn>
|
||
3 years ago
|
<x-btn
|
||
|
v-ge="['rows','save']"
|
||
|
outlined
|
||
3 years ago
|
:tooltip="$t('tooltip.saveChanges')"
|
||
3 years ago
|
color="primary"
|
||
|
small
|
||
|
:disabled="loading || !edited"
|
||
|
|
||
|
@click="save"
|
||
|
@click.prevent
|
||
|
>
|
||
|
<v-icon small left>
|
||
|
save
|
||
|
</v-icon>
|
||
3 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
3 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="">
|
||
|
<v-simple-table dense style="width: auto;min-width:500px">
|
||
|
<thead>
|
||
3 years ago
|
<tr>
|
||
|
<th>
|
||
|
Role Name
|
||
|
</th>
|
||
|
|
||
|
<th>
|
||
|
Role Description
|
||
|
</th>
|
||
|
<th />
|
||
3 years ago
|
<!-- <th v-for="op in operations">
|
||
|
{{ op }}
|
||
|
</th>-->
|
||
3 years ago
|
</tr>
|
||
3 years ago
|
</thead>
|
||
|
<tbody>
|
||
3 years ago
|
<tr v-for="(role,i) in roles" :key="role.title">
|
||
|
<td>
|
||
|
<v-edit-dialog
|
||
|
lazy
|
||
|
>
|
||
|
<v-chip small :color="colors[i % colors.length]">
|
||
|
{{ role.title }}
|
||
|
</v-chip>
|
||
|
<template #input>
|
||
|
<v-text-field
|
||
|
v-model="role.title"
|
||
|
v-ge="['roles','title']"
|
||
|
: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>
|
||
|
<v-edit-dialog
|
||
|
lazy
|
||
|
>
|
||
|
<span> {{ role.description }}</span>
|
||
|
<template #input>
|
||
|
<v-text-field
|
||
|
v-model="role.description"
|
||
|
v-ge="['roles','title']"
|
||
|
: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"
|
||
|
@click="(deleteId = role.id,deleteIndex =i, showConfirmDlg =true)"
|
||
|
>
|
||
|
mdi-delete-forever
|
||
|
</x-icon>
|
||
|
<x-icon
|
||
|
v-else
|
||
|
small
|
||
|
tooltip="System defined role can't be edited"
|
||
|
color="info"
|
||
|
>
|
||
|
mdi-information-outline
|
||
|
</x-icon>
|
||
|
</td>
|
||
3 years ago
|
|
||
|
<!-- <td v-for="op in operations">
|
||
|
<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>
|
||
3 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
|
/>
|
||
3 years ago
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import DlgLabelSubmitCancel from '~/components/utils/DlgLabelSubmitCancel'
|
||
3 years ago
|
import colors from '@/mixins/colors'
|
||
3 years ago
|
|
||
|
export default {
|
||
3 years ago
|
name: 'Roles',
|
||
|
components: { DlgLabelSubmitCancel },
|
||
3 years ago
|
mixins: [colors],
|
||
|
props: ['nodes'],
|
||
|
data: () => ({
|
||
|
loading: false,
|
||
|
roles: null,
|
||
|
edited: false,
|
||
|
showConfirmDlg: false,
|
||
|
deleteId: null,
|
||
|
deleteIndex: null,
|
||
3 years ago
|
aggrAcl: null
|
||
3 years ago
|
|
||
|
}),
|
||
3 years ago
|
computed: {
|
||
3 years ago
|
operations() {
|
||
3 years ago
|
return [
|
||
|
'create',
|
||
|
'read',
|
||
|
'update',
|
||
|
'delete'
|
||
|
]
|
||
|
},
|
||
3 years ago
|
customRolesCount() {
|
||
3 years ago
|
return (this.roles && this.roles.filter(r => r.type !== 'SYSTEM').length) || 0
|
||
|
}
|
||
|
},
|
||
3 years ago
|
async created() {
|
||
3 years ago
|
await this.loadRoles()
|
||
|
await this.loadAggrAcl()
|
||
3 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
async loadRoles() {
|
||
3 years ago
|
try {
|
||
|
this.roles = (await this.$axios.get('/admin/roles', {
|
||
|
headers: {
|
||
|
'xc-auth': this.$store.state.users.token
|
||
|
},
|
||
|
params: {
|
||
|
project_id: this.$route.params.project_id
|
||
|
}
|
||
3 years ago
|
})).data
|
||
3 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Failed loading role list').goAway(3000)
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
this.edited = false
|
||
3 years ago
|
},
|
||
3 years ago
|
async loadAggrAcl() {
|
||
3 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
|
} */
|
||
3 years ago
|
},
|
||
3 years ago
|
addRole() {
|
||
3 years ago
|
this.roles.push({
|
||
|
title: ('role name ' + (this.customRolesCount || '')).trim(),
|
||
|
description: 'Role description'
|
||
3 years ago
|
})
|
||
|
this.edited = true
|
||
|
this.scrollAndFocusLastRow()
|
||
3 years ago
|
},
|
||
3 years ago
|
async save() {
|
||
3 years ago
|
try {
|
||
3 years ago
|
await this.$axios.put('/admin/roles', { roles: this.roles }, {
|
||
3 years ago
|
headers: {
|
||
|
'xc-auth': this.$store.state.users.token
|
||
|
}
|
||
3 years ago
|
})
|
||
3 years ago
|
|
||
|
/* await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
// todo: manage dbAlias or get aggregated
|
||
|
{dbAlias: 'db'},
|
||
|
'xcAclAggregatedSave',
|
||
|
this.aggrAcl
|
||
3 years ago
|
]) */
|
||
3 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)
|
||
3 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error(e.response.data.msg).goAway(3000)
|
||
3 years ago
|
}
|
||
3 years ago
|
await this.loadRoles()
|
||
|
await this.loadAggrAcl()
|
||
3 years ago
|
},
|
||
3 years ago
|
async confirmDelete(hideDialog) {
|
||
3 years ago
|
if (hideDialog) {
|
||
3 years ago
|
this.showConfirmDlg = false
|
||
3 years ago
|
return
|
||
|
}
|
||
|
if (this.deleteId) {
|
||
|
try {
|
||
|
await this.$axios.delete('/admin/roles/' + this.deleteId, {
|
||
|
headers: {
|
||
|
'xc-auth': this.$store.state.users.token
|
||
|
}
|
||
|
})
|
||
3 years ago
|
this.$toast.success('Successfully deleted role').goAway(3000)
|
||
3 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Failed deleting the role').goAway(3000)
|
||
3 years ago
|
}
|
||
3 years ago
|
await this.loadRoles()
|
||
3 years ago
|
} else {
|
||
|
this.roles.splice(this.deleteIndex, 1)
|
||
|
}
|
||
3 years ago
|
this.showConfirmDlg = false
|
||
3 years ago
|
},
|
||
3 years ago
|
scrollAndFocusLastRow() {
|
||
3 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')
|
||
3 years ago
|
if (menuActivator) {
|
||
3 years ago
|
menuActivator.click()
|
||
3 years ago
|
this.$nextTick(() => {
|
||
3 years ago
|
const inputField = document.querySelector('.menuable__content__active input')
|
||
3 years ago
|
inputField && inputField.select()
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
|
||
|
</style>
|
||
|
<!--
|
||
|
/**
|
||
|
* @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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|