mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 21:06:00 +00:00
handle permissions
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
||||
import { apiCall } from '../utility/api';
|
||||
import hasPermission from '../utility/hasPermission';
|
||||
|
||||
export let data;
|
||||
|
||||
@@ -140,6 +141,7 @@ await dbgateApi.deployDb(${JSON.stringify(
|
||||
],
|
||||
|
||||
data.name != 'default' &&
|
||||
hasPermission('dbops/model/compare') &&
|
||||
_.get($currentDatabase, 'connection._id') && {
|
||||
onClick: handleCompareWithCurrentDb,
|
||||
text: `Compare with ${_.get($currentDatabase, 'name')}`,
|
||||
|
||||
@@ -106,6 +106,7 @@
|
||||
import AboutModal from '../modals/AboutModal.svelte';
|
||||
import { tick } from 'svelte';
|
||||
import { getConnectionLabel } from 'dbgate-tools';
|
||||
import hasPermission from '../utility/hasPermission';
|
||||
|
||||
export let data;
|
||||
export let passProps;
|
||||
@@ -220,26 +221,27 @@
|
||||
};
|
||||
|
||||
return [
|
||||
config.runAsPortal == false && [
|
||||
{
|
||||
text: $openedConnections.includes(data._id) ? 'View details' : 'Edit',
|
||||
onClick: handleOpenConnectionTab,
|
||||
},
|
||||
!$openedConnections.includes(data._id) && {
|
||||
text: 'Delete',
|
||||
onClick: handleDelete,
|
||||
},
|
||||
{
|
||||
text: 'Duplicate',
|
||||
onClick: handleDuplicate,
|
||||
},
|
||||
],
|
||||
config.runAsPortal == false &&
|
||||
!config.storageDatabase && [
|
||||
{
|
||||
text: $openedConnections.includes(data._id) ? 'View details' : 'Edit',
|
||||
onClick: handleOpenConnectionTab,
|
||||
},
|
||||
!$openedConnections.includes(data._id) && {
|
||||
text: 'Delete',
|
||||
onClick: handleDelete,
|
||||
},
|
||||
{
|
||||
text: 'Duplicate',
|
||||
onClick: handleDuplicate,
|
||||
},
|
||||
],
|
||||
!data.singleDatabase && [
|
||||
!$openedConnections.includes(data._id) && {
|
||||
text: 'Connect',
|
||||
onClick: handleConnect,
|
||||
},
|
||||
{ onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
||||
hasPermission(`dbops/query`) && { onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
||||
$openedConnections.includes(data._id) &&
|
||||
data.status && {
|
||||
text: 'Refresh',
|
||||
@@ -249,7 +251,8 @@
|
||||
text: 'Disconnect',
|
||||
onClick: handleDisconnect,
|
||||
},
|
||||
$openedConnections.includes(data._id) &&
|
||||
hasPermission(`dbops/createdb`) &&
|
||||
$openedConnections.includes(data._id) &&
|
||||
driver?.supportedCreateDatabase &&
|
||||
!data.isReadOnly && {
|
||||
text: 'Create database',
|
||||
|
||||
@@ -280,20 +280,27 @@
|
||||
driver?.databaseEngineTypes?.includes('sql') || driver?.databaseEngineTypes?.includes('document');
|
||||
|
||||
return [
|
||||
{ onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
||||
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleNewTable, text: 'New table' },
|
||||
driver?.databaseEngineTypes?.includes('document') && {
|
||||
onClick: handleNewCollection,
|
||||
text: `New ${driver?.collectionSingularLabel ?? 'collection/container'}`,
|
||||
},
|
||||
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleQueryDesigner, text: 'Design query' },
|
||||
hasPermission(`dbops/query`) && { onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
||||
hasPermission(`dbops/model/edit`) &&
|
||||
!connection.isReadOnly &&
|
||||
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleNewTable, text: 'New table' },
|
||||
!connection.isReadOnly &&
|
||||
hasPermission(`dbops/model/edit`) &&
|
||||
driver?.databaseEngineTypes?.includes('document') && {
|
||||
onClick: handleNewCollection,
|
||||
text: `New ${driver?.collectionSingularLabel ?? 'collection/container'}`,
|
||||
},
|
||||
hasPermission(`dbops/query`) &&
|
||||
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleQueryDesigner, text: 'Design query' },
|
||||
driver?.databaseEngineTypes?.includes('sql') && {
|
||||
onClick: handleNewPerspective,
|
||||
text: 'Design perspective query',
|
||||
},
|
||||
{ divider: true },
|
||||
isSqlOrDoc && !connection.isReadOnly && { onClick: handleImport, text: 'Import wizard' },
|
||||
isSqlOrDoc && { onClick: handleExport, text: 'Export wizard' },
|
||||
isSqlOrDoc &&
|
||||
!connection.isReadOnly &&
|
||||
hasPermission(`dbops/import`) && { onClick: handleImport, text: 'Import wizard' },
|
||||
isSqlOrDoc && hasPermission(`dbops/export`) && { onClick: handleExport, text: 'Export wizard' },
|
||||
driver?.databaseEngineTypes?.includes('sql') &&
|
||||
hasPermission(`dbops/sql-dump/import`) &&
|
||||
!connection.isReadOnly && { onClick: handleSqlRestore, text: 'Restore/import SQL dump' },
|
||||
@@ -301,7 +308,9 @@
|
||||
hasPermission(`dbops/sql-dump/export`) && { onClick: handleSqlDump, text: 'Backup/export SQL dump' },
|
||||
isSqlOrDoc &&
|
||||
!connection.isReadOnly &&
|
||||
!connection.singleDatabase && { onClick: handleDropDatabase, text: 'Drop database' },
|
||||
!connection.singleDatabase &&
|
||||
isSqlOrDoc &&
|
||||
hasPermission(`dbops/dropdb`) && { onClick: handleDropDatabase, text: 'Drop database' },
|
||||
{ divider: true },
|
||||
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleCopyName, text: 'Copy database name' },
|
||||
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleShowDiagram, text: 'Show diagram' },
|
||||
@@ -309,10 +318,14 @@
|
||||
hasPermission(`dbops/sql-generator`) && { onClick: handleSqlGenerator, text: 'SQL Generator' },
|
||||
driver?.supportsDatabaseProfiler &&
|
||||
hasPermission(`dbops/profiler`) && { onClick: handleDatabaseProfiler, text: 'Database profiler' },
|
||||
isSqlOrDoc && { onClick: handleOpenJsonModel, text: 'Open model as JSON' },
|
||||
isSqlOrDoc && { onClick: handleExportModel, text: 'Export DB model - experimental' },
|
||||
isSqlOrDoc &&
|
||||
isSqlOrDoc &&
|
||||
hasPermission(`dbops/model/view`) && { onClick: handleOpenJsonModel, text: 'Open model as JSON' },
|
||||
isSqlOrDoc &&
|
||||
hasPermission(`dbops/model/view`) && { onClick: handleExportModel, text: 'Export DB model - experimental' },
|
||||
isSqlOrDoc &&
|
||||
_.get($currentDatabase, 'connection._id') &&
|
||||
hasPermission('dbops/model/compare') &&
|
||||
(_.get($currentDatabase, 'connection._id') != _.get(connection, '_id') ||
|
||||
(_.get($currentDatabase, 'connection._id') == _.get(connection, '_id') &&
|
||||
_.get($currentDatabase, 'name') != _.get(connection, 'name'))) && {
|
||||
|
||||
@@ -98,12 +98,12 @@
|
||||
isDrop: true,
|
||||
requiresWriteAccess: true,
|
||||
},
|
||||
{
|
||||
hasPermission('dbops/table/rename') && {
|
||||
label: 'Rename table',
|
||||
isRename: true,
|
||||
requiresWriteAccess: true,
|
||||
},
|
||||
{
|
||||
hasPermission('dbops/table/truncate') && {
|
||||
label: 'Truncate table',
|
||||
isTruncate: true,
|
||||
requiresWriteAccess: true,
|
||||
@@ -113,29 +113,29 @@
|
||||
isCopyTableName: true,
|
||||
requiresWriteAccess: false,
|
||||
},
|
||||
{
|
||||
hasPermission('dbops/table/backup') && {
|
||||
label: 'Create table backup',
|
||||
isDuplicateTable: true,
|
||||
requiresWriteAccess: true,
|
||||
},
|
||||
{
|
||||
hasPermission('dbops/model/view') && {
|
||||
label: 'Show diagram',
|
||||
isDiagram: true,
|
||||
},
|
||||
{
|
||||
divider: true,
|
||||
},
|
||||
{
|
||||
hasPermission('dbops/export') && {
|
||||
label: 'Export',
|
||||
functionName: 'tableReader',
|
||||
isExport: true,
|
||||
},
|
||||
{
|
||||
hasPermission('dbops/import') && {
|
||||
label: 'Import',
|
||||
isImport: true,
|
||||
requiresWriteAccess: true,
|
||||
},
|
||||
{
|
||||
hasPermission('dbops/charts') && {
|
||||
label: 'Open active chart',
|
||||
isActiveChart: true,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user