dbgate-api-premium 7.1.0 → 7.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -7
- package/src/auth/storageAuthProvider.js +7 -6
- package/src/controllers/connections.js +3 -0
- package/src/controllers/databaseConnections.js +7 -3
- package/src/controllers/serverConnections.js +1 -1
- package/src/controllers/storageDb.js +22 -1
- package/src/currentVersion.js +2 -2
- package/src/utility/hasPermission.js +3 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbgate-api-premium",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "7.1.
|
|
4
|
+
"version": "7.1.2",
|
|
5
5
|
"homepage": "https://www.dbgate.io/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"compare-versions": "^3.6.0",
|
|
31
31
|
"cors": "^2.8.5",
|
|
32
32
|
"cross-env": "^6.0.3",
|
|
33
|
-
"dbgate-datalib": "^7.1.
|
|
34
|
-
"dbgate-query-splitter": "^4.
|
|
35
|
-
"dbgate-rest": "^7.1.
|
|
36
|
-
"dbgate-sqltree": "^7.1.
|
|
37
|
-
"dbgate-tools": "^7.1.
|
|
33
|
+
"dbgate-datalib": "^7.1.2",
|
|
34
|
+
"dbgate-query-splitter": "^4.12.0",
|
|
35
|
+
"dbgate-rest": "^7.1.2",
|
|
36
|
+
"dbgate-sqltree": "^7.1.2",
|
|
37
|
+
"dbgate-tools": "^7.1.2",
|
|
38
38
|
"debug": "^4.3.4",
|
|
39
39
|
"diff": "^5.0.0",
|
|
40
40
|
"diff2html": "^3.4.13",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@types/fs-extra": "^9.0.11",
|
|
90
90
|
"@types/lodash": "^4.14.149",
|
|
91
|
-
"dbgate-types": "^7.1.
|
|
91
|
+
"dbgate-types": "^7.1.2",
|
|
92
92
|
"env-cmd": "^10.1.0",
|
|
93
93
|
"jsdoc-to-markdown": "^9.0.5",
|
|
94
94
|
"node-loader": "^1.0.2",
|
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
loadSuperadminPermissions,
|
|
15
15
|
readComplexUserRolePermissions,
|
|
16
16
|
readComplexRolePermissions,
|
|
17
|
+
resolvePermissionConnectionIds,
|
|
17
18
|
storageCheckRoleConnectionAccess,
|
|
18
19
|
storageCheckUserRoleConnectionAccess,
|
|
19
20
|
} = require('../controllers/storageDb');
|
|
@@ -61,12 +62,12 @@ class SuperadminAuthProvider extends AuthProviderBase {
|
|
|
61
62
|
|
|
62
63
|
async getCurrentDatabasePermissions(req) {
|
|
63
64
|
const databasePermissions = await readComplexRolePermissions(-3, 'role_databases');
|
|
64
|
-
return databasePermissions;
|
|
65
|
+
return resolvePermissionConnectionIds(databasePermissions);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
async getCurrentTablePermissions(req) {
|
|
68
69
|
const tablePermissions = await readComplexRolePermissions(-3, 'role_tables');
|
|
69
|
-
return tablePermissions;
|
|
70
|
+
return resolvePermissionConnectionIds(tablePermissions);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
async getCurrentFilePermissions(req) {
|
|
@@ -104,13 +105,13 @@ class StorageProviderBase extends AuthProviderBase {
|
|
|
104
105
|
async getCurrentDatabasePermissions(req) {
|
|
105
106
|
const userId = this.getUserIdFromRequest(req);
|
|
106
107
|
const databasePermissions = await readComplexUserRolePermissions(userId, 'user_databases', 'role_databases');
|
|
107
|
-
return databasePermissions;
|
|
108
|
+
return resolvePermissionConnectionIds(databasePermissions);
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
async getCurrentTablePermissions(req) {
|
|
111
112
|
const userId = this.getUserIdFromRequest(req);
|
|
112
113
|
const tablePermissions = await readComplexUserRolePermissions(userId, 'user_tables', 'role_tables');
|
|
113
|
-
return tablePermissions;
|
|
114
|
+
return resolvePermissionConnectionIds(tablePermissions);
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
async getCurrentFilePermissions(req) {
|
|
@@ -172,12 +173,12 @@ class AnonymousProvider extends StorageProviderBase {
|
|
|
172
173
|
|
|
173
174
|
async getCurrentDatabasePermissions(req) {
|
|
174
175
|
const databasePermissions = await readComplexRolePermissions(-1, 'role_databases');
|
|
175
|
-
return databasePermissions;
|
|
176
|
+
return resolvePermissionConnectionIds(databasePermissions);
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
async getCurrentTablePermissions(req) {
|
|
179
180
|
const tablePermissions = await readComplexRolePermissions(-1, 'role_tables');
|
|
180
|
-
return tablePermissions;
|
|
181
|
+
return resolvePermissionConnectionIds(tablePermissions);
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
async getCurrentFilePermissions(req) {
|
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
getLogger,
|
|
16
16
|
extractErrorLogData,
|
|
17
17
|
filterStructureBySchema,
|
|
18
|
+
serializeJsTypesForJsonStringify,
|
|
18
19
|
} = require('dbgate-tools');
|
|
19
20
|
const { html, parse } = require('diff2html');
|
|
20
21
|
const { handleProcessCommunication } = require('../utility/processComm');
|
|
@@ -224,12 +225,13 @@ module.exports = {
|
|
|
224
225
|
this.close(conid, database, false);
|
|
225
226
|
});
|
|
226
227
|
|
|
227
|
-
|
|
228
|
+
const connectMessage = serializeJsTypesForJsonStringify({
|
|
228
229
|
msgtype: 'connect',
|
|
229
230
|
connection: { ...connection, database },
|
|
230
231
|
structure: lastClosed ? lastClosed.structure : null,
|
|
231
232
|
globalSettings: await config.getSettings(),
|
|
232
233
|
});
|
|
234
|
+
subprocess.send(connectMessage);
|
|
233
235
|
return newOpened;
|
|
234
236
|
},
|
|
235
237
|
|
|
@@ -239,7 +241,8 @@ module.exports = {
|
|
|
239
241
|
const promise = new Promise((resolve, reject) => {
|
|
240
242
|
this.requests[msgid] = [resolve, reject, additionalData];
|
|
241
243
|
try {
|
|
242
|
-
|
|
244
|
+
const serializedMessage = serializeJsTypesForJsonStringify({ msgid, ...message });
|
|
245
|
+
conn.subprocess.send(serializedMessage);
|
|
243
246
|
} catch (err) {
|
|
244
247
|
logger.error(extractErrorLogData(err), 'DBGM-00115 Error sending request do process');
|
|
245
248
|
this.close(conn.conid, conn.database);
|
|
@@ -473,6 +476,7 @@ module.exports = {
|
|
|
473
476
|
|
|
474
477
|
const databasePermissions = await loadDatabasePermissionsFromRequest(req);
|
|
475
478
|
const tablePermissions = await loadTablePermissionsFromRequest(req);
|
|
479
|
+
const databasePermissionRole = getDatabasePermissionRole(conid, database, databasePermissions);
|
|
476
480
|
const fieldsAndRoles = [
|
|
477
481
|
[changeSet.inserts, 'create_update_delete'],
|
|
478
482
|
[changeSet.deletes, 'create_update_delete'],
|
|
@@ -487,7 +491,7 @@ module.exports = {
|
|
|
487
491
|
operation.schemaName,
|
|
488
492
|
operation.pureName,
|
|
489
493
|
tablePermissions,
|
|
490
|
-
|
|
494
|
+
databasePermissionRole
|
|
491
495
|
);
|
|
492
496
|
if (getTablePermissionRoleLevelIndex(role) < getTablePermissionRoleLevelIndex(requiredRole)) {
|
|
493
497
|
throw new Error('DBGM-00262 Permission not granted');
|
|
@@ -171,7 +171,7 @@ module.exports = {
|
|
|
171
171
|
const databasePermissions = await loadDatabasePermissionsFromRequest(req);
|
|
172
172
|
const res = [];
|
|
173
173
|
for (const db of opened?.databases ?? []) {
|
|
174
|
-
const databasePermissionRole = getDatabasePermissionRole(
|
|
174
|
+
const databasePermissionRole = getDatabasePermissionRole(conid, db.name, databasePermissions);
|
|
175
175
|
if (databasePermissionRole != 'deny') {
|
|
176
176
|
res.push({
|
|
177
177
|
...db,
|
|
@@ -247,6 +247,24 @@ async function readComplexRolePermissions(roleId, rolePermissionsTable) {
|
|
|
247
247
|
return rolePermissionsResp;
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
async function resolvePermissionConnectionIds(permissionRows) {
|
|
251
|
+
if (!permissionRows || permissionRows.length === 0) return permissionRows;
|
|
252
|
+
|
|
253
|
+
const connectionIds = Array.from(new Set(permissionRows.filter(r => r.connection_id).map(r => r.connection_id)));
|
|
254
|
+
if (connectionIds.length === 0) return permissionRows;
|
|
255
|
+
|
|
256
|
+
const conidMap = {};
|
|
257
|
+
const rows = await storageSelectFmt('select ~id, ~conid from ~connections where ~id in (%,v)', connectionIds);
|
|
258
|
+
for (const row of rows ?? []) {
|
|
259
|
+
conidMap[row.id] = row.conid;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return permissionRows.map(r => ({
|
|
263
|
+
...r,
|
|
264
|
+
connection_conid: r.connection_id ? conidMap[r.connection_id] ?? null : null,
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
267
|
+
|
|
250
268
|
async function loadSuperadminPermissions() {
|
|
251
269
|
const rolePermissions = await storageReadRolePermissions(-3);
|
|
252
270
|
return [...getPredefinedPermissions('superadmin'), ...rolePermissions];
|
|
@@ -496,10 +514,12 @@ function getStorageConnectionError() {
|
|
|
496
514
|
async function selectStorageIdentity(tableName) {
|
|
497
515
|
const [conn, driver] = await getStorageConnection();
|
|
498
516
|
|
|
517
|
+
const tableDefinition = storageModel.tables?.find(t => t.pureName === tableName);
|
|
518
|
+
|
|
499
519
|
const resp = await runQueryOnDriver(conn, driver, dmp =>
|
|
500
520
|
dmp.selectScopeIdentity(
|
|
501
521
|
// @ts-ignore
|
|
502
|
-
{ pureName: tableName }
|
|
522
|
+
tableDefinition || { pureName: tableName }
|
|
503
523
|
)
|
|
504
524
|
);
|
|
505
525
|
|
|
@@ -1098,6 +1118,7 @@ module.exports = {
|
|
|
1098
1118
|
storageSaveDetailPermissionsDiff,
|
|
1099
1119
|
readComplexUserRolePermissions,
|
|
1100
1120
|
readComplexRolePermissions,
|
|
1121
|
+
resolvePermissionConnectionIds,
|
|
1101
1122
|
storageCheckRoleConnectionAccess,
|
|
1102
1123
|
storageCheckUserRoleConnectionAccess,
|
|
1103
1124
|
storageCreateTeamFile,
|
package/src/currentVersion.js
CHANGED
|
@@ -96,8 +96,9 @@ async function loadFilePermissionsFromRequest(req) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
function matchDatabasePermissionRow(conid, database, permissionRow) {
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
const connectionIdentifier = permissionRow.connection_conid ?? permissionRow.connection_id;
|
|
100
|
+
if (connectionIdentifier) {
|
|
101
|
+
if (conid != connectionIdentifier) {
|
|
101
102
|
return false;
|
|
102
103
|
}
|
|
103
104
|
}
|