From 4c5da50a04e3a724347a3481ffd64a29fc5effc1 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Tue, 30 Jul 2024 16:26:02 +0200 Subject: [PATCH] connections per role --- packages/api/src/controllers/auth.js | 1 + packages/api/src/controllers/connections.js | 2 +- packages/api/src/controllers/storage.js | 2 +- packages/tools/src/testPermission.ts | 6 +++--- packages/web/src/commands/stdCommands.ts | 2 +- packages/web/src/utility/connectionsPinger.js | 4 +++- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/api/src/controllers/auth.js b/packages/api/src/controllers/auth.js index 3f4c397c..29d93147 100644 --- a/packages/api/src/controllers/auth.js +++ b/packages/api/src/controllers/auth.js @@ -71,6 +71,7 @@ module.exports = { { login: 'superadmin', permissions: await storage.loadSuperadminPermissions(), + roleId: -3, }, getTokenSecret(), { diff --git a/packages/api/src/controllers/connections.js b/packages/api/src/controllers/connections.js index b6d9d0bb..697abecd 100644 --- a/packages/api/src/controllers/connections.js +++ b/packages/api/src/controllers/connections.js @@ -201,7 +201,7 @@ module.exports = { async list(_params, req) { const storage = require('./storage'); - const storageConnections = await storage.connections(); + const storageConnections = await storage.connections(req); if (storageConnections) { return storageConnections; } diff --git a/packages/api/src/controllers/storage.js b/packages/api/src/controllers/storage.js index 2be17b4b..9599dd0e 100644 --- a/packages/api/src/controllers/storage.js +++ b/packages/api/src/controllers/storage.js @@ -1,6 +1,6 @@ module.exports = { connections_meta: true, - async connections() { + async connections(req) { return null; }, diff --git a/packages/tools/src/testPermission.ts b/packages/tools/src/testPermission.ts index d6b805f9..ee679b91 100644 --- a/packages/tools/src/testPermission.ts +++ b/packages/tools/src/testPermission.ts @@ -101,11 +101,11 @@ export function testSubPermission( export function getPredefinedPermissions(predefinedRoleName: string) { switch (predefinedRoleName) { case 'superadmin': - return ['*', '~widgets/*', 'widgets/admin']; + return ['*', '~widgets/*', 'widgets/admin', '~all-connections']; case 'logged-user': - return ['*', '~widgets/admin', '~admin/*']; + return ['*', '~widgets/admin', '~admin/*', '~internal-storage', '~all-connections']; case 'anonymous-user': - return ['*', '~widgets/admin', '~admin/*']; + return ['*', '~widgets/admin', '~admin/*', '~internal-storage', '~all-connections']; default: return null; } diff --git a/packages/web/src/commands/stdCommands.ts b/packages/web/src/commands/stdCommands.ts index cd0e02e3..93e4d671 100644 --- a/packages/web/src/commands/stdCommands.ts +++ b/packages/web/src/commands/stdCommands.ts @@ -104,7 +104,7 @@ registerCommand({ category: 'New', toolbarOrder: 1, name: 'Connection', - testEnabled: () => !getCurrentConfig()?.runAsPortal, + testEnabled: () => !getCurrentConfig()?.runAsPortal && !getCurrentConfig()?.storageDatabase, onClick: () => { openNewTab({ title: 'New Connection', diff --git a/packages/web/src/utility/connectionsPinger.js b/packages/web/src/utility/connectionsPinger.js index efa0fd7b..0e626657 100644 --- a/packages/web/src/utility/connectionsPinger.js +++ b/packages/web/src/utility/connectionsPinger.js @@ -2,6 +2,7 @@ import _ from 'lodash'; import { openedConnections, currentDatabase, openedConnectionsWithTemporary, getCurrentConfig } from '../stores'; import { apiCall, strmid } from './api'; import { getConnectionList } from './metadataLoaders'; +import hasPermission from '../utility/hasPermission'; // const doServerPing = async value => { // const connectionList = getConnectionList(); @@ -11,7 +12,8 @@ import { getConnectionList } from './metadataLoaders'; const doServerPing = value => { apiCall('server-connections/ping', { - conidArray: getCurrentConfig().storageDatabase ? ['__storage', ...value] : value, + conidArray: + getCurrentConfig().storageDatabase && hasPermission('internal-storage') ? ['__storage', ...value] : value, strmid, }); };