дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 09:41:34 +02:00
feat(database): show table grants in the Modify Table dialog (#5965)
The Modify Table dialog gains a read-only Grants tab for PostgreSQL and MySQL tables: one row per grantee and grantor, a column per privilege, and a `*` mark for privileges held WITH GRANT OPTION. - PostgreSQL expands the table ACL with aclexplode, falling back to the owner's implicit privileges when relacl is null; PUBLIC is listed. - MySQL reads information_schema.table_privileges (no grantor there). - Other engines show no tab and run no query; grants load only when the tab is opened. Fixes #5832
Цей коміт міститься в:
1 джерело
de36b46660
коміт
a483ea77f4
18 files changed
+574
-107
No files matched your search
@@ -3,7 +3,7 @@
|
||||
* Drop, Truncate, SQL Scripts › …, Modify Table, Copy Reference), per dialect.
|
||||
* Pure functions.
|
||||
*/
|
||||
import type { DbColumnInfo, DbDriver } from "@/platform/ipc";
|
||||
import type { DbColumnInfo, DbDriver, DbTableGrant } from "@/platform/ipc";
|
||||
import { isReserved } from "./sql/dialect";
|
||||
|
||||
export function quoteIdent(driver: DbDriver, name: string): string {
|
||||
@@ -444,3 +444,55 @@ export function alterTableSql(
|
||||
out.push(renameSql(driver, { kind: "table", schema, name: table }, name.trim()));
|
||||
return out;
|
||||
}
|
||||
|
||||
// ---- Grants -------------------------------------------------------------------
|
||||
|
||||
/** Engines whose table privileges the Modify Table dialog shows (others run no query). */
|
||||
export function grantsSupported(driver: DbDriver): boolean {
|
||||
return driver === "postgres" || driver === "mysql";
|
||||
}
|
||||
|
||||
/** Column order of the Grants table: the SQL standard's table privileges, then the engine's own. */
|
||||
const PRIVILEGE_ORDER = [
|
||||
"SELECT",
|
||||
"INSERT",
|
||||
"UPDATE",
|
||||
"DELETE",
|
||||
"TRUNCATE",
|
||||
"REFERENCES",
|
||||
"TRIGGER",
|
||||
"MAINTAIN",
|
||||
"INDEX",
|
||||
"ALTER",
|
||||
"CREATE",
|
||||
"DROP",
|
||||
"CREATE VIEW",
|
||||
"SHOW VIEW",
|
||||
"DELETE HISTORY",
|
||||
];
|
||||
|
||||
export interface GrantRow {
|
||||
grantee: string;
|
||||
grantor: string | null;
|
||||
/** Privilege → granted with GRANT OPTION. */
|
||||
privileges: Map<string, boolean>;
|
||||
}
|
||||
|
||||
/** One row per grantee and grantor, with the privileges they hold as columns. */
|
||||
export function grantMatrix(grants: DbTableGrant[]): { privileges: string[]; rows: GrantRow[] } {
|
||||
const rows = new Map<string, GrantRow>();
|
||||
const seen = new Set<string>();
|
||||
for (const g of grants) {
|
||||
const key = JSON.stringify([g.grantee, g.grantor]);
|
||||
let row = rows.get(key);
|
||||
if (!row) rows.set(key, (row = { grantee: g.grantee, grantor: g.grantor, privileges: new Map() }));
|
||||
row.privileges.set(g.privilege, (row.privileges.get(g.privilege) ?? false) || g.grantable);
|
||||
seen.add(g.privilege);
|
||||
}
|
||||
const rank = (p: string) => {
|
||||
const i = PRIVILEGE_ORDER.indexOf(p);
|
||||
return i < 0 ? PRIVILEGE_ORDER.length : i;
|
||||
};
|
||||
const privileges = [...seen].sort((a, b) => rank(a) - rank(b) || a.localeCompare(b));
|
||||
return { privileges, rows: [...rows.values()] };
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача