Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(frontend): read access grants status, creator, databases, statement, then dates
zchpeterdf845665efdc
diff --git a/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx b/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsxindex a0f92fc5a8..a7be351910 100644--- a/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx+++ b/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx@@ -16,6 +16,7 @@ import {AccessGrant_Status,AccessGrantSchema,} from "@/types/proto-es/v1/access_grant_service_pb";+import { getAccessGrantDisplayStatusText } from "@/utils/accessGrant";vi.mock("react-i18next", () => ({useTranslation: () => ({ t: (key: string) => key }),@@ -45,6 +46,18 @@ describe("grantColumns", () => {const floored = (widths: number[], key: string) =>widths[at(key)] === columns[at(key)].minWidth;+ test("reads status, creator, databases, statement, expiry, creation, then actions", () => {+ expect(columns.map((column) => column.key)).toEqual([+ "status",+ "creator",+ "databases",+ "statement",+ "expiration",+ "created",+ "actions",+ ]);+ });+test("opens both dates whole once the table holds every column", () => {for (const width of [preferred, preferred + 300]) {const widths = distributeColumnWidths(columns, width);@@ -77,7 +90,7 @@ describe("grantColumns", () => {}});- test("lets a reader narrow either date to the date alone", () => {+ test("floors both dates at the timestamp minimum", () => {expect(columns[at("created")].minWidth).toBe(TIMESTAMP_COLUMN_MIN_WIDTH);expect(columns[at("expiration")].minWidth).toBe(TIMESTAMP_COLUMN_MIN_WIDTH);});@@ -91,24 +104,76 @@ describe("AccessGrantRow", () => {}});- test("dates a grant's creation and expiry in one form, each ellipsizing", () => {+ test("puts each cell under its own column", () => {+ const columns = grantColumns((key) => key);const container = document.createElement("div");const root = createRoot(container);roots.push(root);const nowMs = Date.now();+ const createdMs = nowMs - 60_000;+ const expiresMs = nowMs + 86_400_000;act(() =>root.render(<table><tbody><AccessGrantRow+ columns={columns}grant={create(AccessGrantSchema, {name: "projects/p1/accessGrants/1",creator: "users/[email protected]",status: AccessGrant_Status.ACTIVE,- createTime: timestampFromMs(nowMs - 60_000),+ query: "SELECT secret FROM vault",+ createTime: timestampFromMs(createdMs),expiration: {case: "expireTime",- value: timestampFromMs(nowMs + 86_400_000),+ value: timestampFromMs(expiresMs),+ },+ })}+ canActivate={false}+ canRevoke={true}+ onActivate={() => {}}+ onRevoke={() => {}}+ />+ </tbody>+ </table>+ )+ );++ const cells = Array.from(container.querySelectorAll("td"));+ const cell = (key: string) =>+ cells[columns.findIndex((column) => column.key === key)];+ expect(cells).toHaveLength(columns.length);+ expect(cell("status").textContent).toBe(+ getAccessGrantDisplayStatusText("ACTIVE")+ );+ expect(cell("creator").textContent).toBe("[email protected]");+ expect(cell("databases").textContent).toBe("-");+ expect(cell("statement").textContent).toBe("SELECT secret FROM vault");+ expect(shownTimestampInstants(cell("expiration"))).toEqual([+ String(expiresMs),+ ]);+ expect(shownTimestampInstants(cell("created"))).toEqual([+ String(createdMs),+ ]);+ expect(cell("actions").textContent).toBe("sql-editor.revoke-access");+ });++ test("dates a grant's creation and expiry in one form, each ellipsizing", () => {+ const container = document.createElement("div");+ const root = createRoot(container);+ roots.push(root);+ act(() =>+ root.render(+ <table>+ <tbody>+ <AccessGrantRow+ columns={grantColumns((key) => key)}+ grant={create(AccessGrantSchema, {+ name: "projects/p1/accessGrants/1",+ createTime: timestampFromMs(1_000),+ expiration: {+ case: "expireTime",+ value: timestampFromMs(2_000),},})}canActivate={false}@@ -121,15 +186,14 @@ describe("AccessGrantRow", () => {));+ const dates = container.querySelectorAll<HTMLElement>(+ "[data-testid=humanize-ts]"+ );expect(shownTimestampModes(container)).toEqual(["operational","operational",]);- expect(shownTimestampInstants(container)).toEqual([- String(nowMs - 60_000),- String(nowMs + 86_400_000),- ]);- for (const date of container.querySelectorAll("[data-testid=humanize-ts]")) {+ for (const date of dates) {expect(date.className).toContain("truncate");}});diff --git a/frontend/src/routes/project/ProjectAccessGrantsPage.tsx b/frontend/src/routes/project/ProjectAccessGrantsPage.tsxindex 6cffbdcba8..fe3a81704f 100644--- a/frontend/src/routes/project/ProjectAccessGrantsPage.tsx+++ b/frontend/src/routes/project/ProjectAccessGrantsPage.tsx@@ -1,4 +1,11 @@-import { useCallback, useEffect, useMemo, useRef, useState } from "react";+import {+ type ReactNode,+ useCallback,+ useEffect,+ useMemo,+ useRef,+ useState,+} from "react";import { useTranslation } from "react-i18next";import {AdvancedSearch,@@ -72,24 +79,34 @@ import { extractDatabaseResourceName } from "@/utils/v1/database";type SortKey = "creator" | "create_time" | "expire_time";type SortDir = "asc" | "desc";-// Column descriptor for the access-grants table. Position in the array is-// the `<colgroup>` order — keep this in sync with the cell order inside-// `<AccessGrantRow>` (`useColumnWidths` indexes positionally). The width-// fields are `ColumnWithWidth`'s.+type GrantColumnKey =+ | "status"+ | "creator"+ | "databases"+ | "statement"+ | "expiration"+ | "created"+ | "actions";++// Column descriptor for the access-grants table. The width fields are+// `ColumnWithWidth`'s.//// - `title` — header label; omit for a blank header (actions col).// - `sortKey` — present iff the column participates in server sort.// - `resizable` — defaults true; set false for purely action columns where a// too-narrow width clips the button row.type GrantColumn = ColumnWithWidth & {- key: string;+ key: GrantColumnKey;title?: string;minWidth: number;sortKey?: SortKey;resizable?: boolean;};-/** The table's columns, in `<colgroup>` order; titles follow the language. */+/**+ * The table's columns, left to right: the header, `<colgroup>` and every row+ * follow this order. Titles follow the language.+ */export const grantColumns = (t: (key: string) => string): GrantColumn[] => [{key: "status",@@ -106,13 +123,18 @@ export const grantColumns = (t: (key: string) => string): GrantColumn[] => [yieldOrder: 3,},{- key: "created",- title: t("common.created-at"),- defaultWidth: TIMESTAMP_COLUMN_WIDTH.operational,- minWidth: TIMESTAMP_COLUMN_MIN_WIDTH,- grow: false,- sortKey: "create_time",- yieldOrder: 1,+ key: "databases",+ title: t("common.databases"),+ defaultWidth: 240,+ minWidth: 128,+ yieldOrder: 4,+ },+ {+ key: "statement",+ title: t("common.statement"),+ defaultWidth: 400,+ minWidth: 180,+ yieldOrder: 2,},{key: "expiration",@@ -124,18 +146,13 @@ export const grantColumns = (t: (key: string) => string): GrantColumn[] => [yieldOrder: 1,},{- key: "statement",- title: t("common.statement"),- defaultWidth: 400,- minWidth: 180,- yieldOrder: 2,- },- {- key: "databases",- title: t("common.databases"),- defaultWidth: 240,- minWidth: 128,- yieldOrder: 4,+ key: "created",+ title: t("common.created-at"),+ defaultWidth: TIMESTAMP_COLUMN_WIDTH.operational,+ minWidth: TIMESTAMP_COLUMN_MIN_WIDTH,+ grow: false,+ sortKey: "create_time",+ yieldOrder: 1,},// Trailing actions column — no title (blank header), fixed// width sized for two ghost buttons + "View issue".@@ -615,11 +632,6 @@ export function ProjectAccessGrantsPage({ projectId }: { projectId: string }) {className="w-auto table-fixed"style={{ width: `${totalWidth}px` }}>- {/*- `<colgroup>` order mirrors `columns`, which in turn- mirrors the cell order inside `<AccessGrantRow>` —- `useColumnWidths` indexes positionally, not by key.- */}<colgroup>{widths.map((w, i) => (<col key={columns[i].key} style={{ width: `${w}px` }} />@@ -658,6 +670,7 @@ export function ProjectAccessGrantsPage({ projectId }: { projectId: string }) {{paged.dataList.map((grant) => (<AccessGrantRowkey={grant.name}+ columns={columns}grant={grant}issue={issueByGrantName.get(grant.name)}canActivate={canActivate}@@ -733,6 +746,7 @@ export function ProjectAccessGrantsPage({ projectId }: { projectId: string }) {// ---------------------------------------------------------------------------export function AccessGrantRow({+ columns,grant,issue,canActivate,@@ -740,6 +754,7 @@ export function AccessGrantRow({onActivate,onRevoke,}: {+ columns: readonly { key: GrantColumnKey }[];grant: AccessGrant;issue?: Issue;canActivate: boolean;@@ -752,87 +767,87 @@ export function AccessGrantRow({const createdTimeMs = getTimeForPbTimestampProtoEs(grant.createTime);const expireTimeMs = getAccessGrantExpireTimeMs(grant);- return (- <TableRow>- <TableCell>- <Badge variant={statusTagVariant(status)}>- {getAccessGrantDisplayStatusText(status)}- </Badge>- </TableCell>- <TableCell>- <EllipsisText text={extractUserEmail(grant.creator)} />- </TableCell>- <TableCell>- {createdTimeMs !== undefined ? (- <HumanizeTs- className="block truncate"- mode="operational"- tsMs={createdTimeMs}- />- ) : (- "-"+ const cells: Record<GrantColumnKey, ReactNode> = {+ status: (+ <Badge variant={statusTagVariant(status)}>+ {getAccessGrantDisplayStatusText(status)}+ </Badge>+ ),+ creator: <EllipsisText text={extractUserEmail(grant.creator)} />,+ databases: <DatabaseTargets targets={grant.targets} />,+ statement: (+ <div className="flex items-center gap-x-1 overflow-hidden">+ <TruncatedQuery query={grant.query} />+ {grant.unmask && (+ <Badge variant="warning" className="shrink-0">+ {t("sql-editor.grant-type-unmask")}+ </Badge>)}- </TableCell>- <TableCell>- {expireTimeMs !== undefined ? (- <HumanizeTs- className="block truncate"- mode="operational"- tsMs={expireTimeMs}- />- ) : (- "-"+ {grant.export && (+ <Badge variant="default" className="shrink-0">+ {t("sql-editor.grant-type-export")}+ </Badge>)}- </TableCell>- <TableCell>- <div className="flex items-center gap-x-1 overflow-hidden">- <TruncatedQuery query={grant.query} />- {grant.unmask && (- <Badge variant="warning" className="shrink-0">- {t("sql-editor.grant-type-unmask")}- </Badge>- )}- {grant.export && (- <Badge variant="default" className="shrink-0">- {t("sql-editor.grant-type-export")}- </Badge>- )}- </div>- </TableCell>- <TableCell>- <DatabaseTargets targets={grant.targets} />- </TableCell>- <TableCell>- <div className="flex items-center justify-end gap-x-1">- {status === "REVOKED" && canActivate && (- <Button appearance="secondary" size="sm" onClick={onActivate}>- {t("sql-editor.activate-access")}- </Button>- )}- {status === "ACTIVE" && canRevoke && (- <Button- appearance="secondary"- size="sm"- className="text-error"- onClick={onRevoke}- >- {t("sql-editor.revoke-access")}+ </div>+ ),+ expiration:+ expireTimeMs !== undefined ? (+ <HumanizeTs+ className="block truncate"+ mode="operational"+ tsMs={expireTimeMs}+ />+ ) : (+ "-"+ ),+ created:+ createdTimeMs !== undefined ? (+ <HumanizeTs+ className="block truncate"+ mode="operational"+ tsMs={createdTimeMs}+ />+ ) : (+ "-"+ ),+ actions: (+ <div className="flex items-center justify-end gap-x-1">+ {status === "REVOKED" && canActivate && (+ <Button appearance="secondary" size="sm" onClick={onActivate}>+ {t("sql-editor.activate-access")}+ </Button>+ )}+ {status === "ACTIVE" && canRevoke && (+ <Button+ appearance="secondary"+ size="sm"+ className="text-error"+ onClick={onRevoke}+ >+ {t("sql-editor.revoke-access")}+ </Button>+ )}+ {grant.issue && (+ <RouterLink+ to={grant.issue.startsWith("/") ? grant.issue : `/${grant.issue}`}+ target="_blank"+ rel="noreferrer"+ onClick={(e) => e.stopPropagation()}+ >+ <Button appearance="secondary" size="sm">+ {t("sql-editor.view-issue")}</Button>- )}- {grant.issue && (- <RouterLink- to={grant.issue.startsWith("/") ? grant.issue : `/${grant.issue}`}- target="_blank"- rel="noreferrer"- onClick={(e) => e.stopPropagation()}- >- <Button appearance="secondary" size="sm">- {t("sql-editor.view-issue")}- </Button>- </RouterLink>- )}- </div>- </TableCell>+ </RouterLink>+ )}+ </div>+ ),+ };++ return (+ <TableRow>+ {columns.map((column) => (+ <TableCell key={column.key}>{cells[column.key]}</TableCell>+ ))}</TableRow>);}