@rebasepro/studio 0.35.1 → 0.37.0
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/README.md +1 -1
- package/dist/{ApiExplorer-C61w8gCc.js → ApiExplorer-BVQHAjHB.js} +3 -2
- package/dist/{ApiExplorer-C61w8gCc.js.map → ApiExplorer-BVQHAjHB.js.map} +1 -1
- package/dist/{useRunAsUsers-CF7tkGzj.js → AuthSimulationSelector-XogpkeXC.js} +4 -68
- package/dist/AuthSimulationSelector-XogpkeXC.js.map +1 -0
- package/dist/{CronJobsView-DUuyzkJK.js → CronJobsView-DyX9MINh.js} +2 -2
- package/dist/{CronJobsView-DUuyzkJK.js.map → CronJobsView-DyX9MINh.js.map} +1 -1
- package/dist/DatabaseView-Bi0NZS90.js +1897 -0
- package/dist/DatabaseView-Bi0NZS90.js.map +1 -0
- package/dist/{JSEditor-Bi2Aol-Y.js → JSEditor-B4Lazm-z.js} +4 -3
- package/dist/{JSEditor-Bi2Aol-Y.js.map → JSEditor-B4Lazm-z.js.map} +1 -1
- package/dist/RLSEditor-CcHkWFNg.js +973 -0
- package/dist/RLSEditor-CcHkWFNg.js.map +1 -0
- package/dist/{SQLEditor-DRo5kW1h.js → SQLEditorRoute-f5j_ZKdj.js} +1472 -320
- package/dist/SQLEditorRoute-f5j_ZKdj.js.map +1 -0
- package/dist/SchemaDiagramView-CckQobIZ.js +98 -0
- package/dist/SchemaDiagramView-CckQobIZ.js.map +1 -0
- package/dist/{StorageView-D0D8z4lI.js → StorageView-DQEIDFvO.js} +592 -447
- package/dist/StorageView-DQEIDFvO.js.map +1 -0
- package/dist/TableEditorView-BRZNvD6U.js +3615 -0
- package/dist/TableEditorView-BRZNvD6U.js.map +1 -0
- package/dist/TablePolicies-C1-tbC8x.js +1740 -0
- package/dist/TablePolicies-C1-tbC8x.js.map +1 -0
- package/dist/{SchemaVisualizer-Dy4kWKT5.js → TablesDiagram-RTJfwVEN.js} +651 -489
- package/dist/TablesDiagram-RTJfwVEN.js.map +1 -0
- package/dist/{UsersAndRolesView-CKw4SJPj.js → UsersAndRolesView-Cx6xtMVH.js} +2 -2
- package/dist/{UsersAndRolesView-CKw4SJPj.js.map → UsersAndRolesView-Cx6xtMVH.js.map} +1 -1
- package/dist/{WebhooksView-CFPY-N9h.js → WebhooksView-Bn9KB7xG.js} +2 -2
- package/dist/{WebhooksView-CFPY-N9h.js.map → WebhooksView-Bn9KB7xG.js.map} +1 -1
- package/dist/{adminFetch-BfOnfRgU.js → adminFetch-C7Ra8rpP.js} +26 -1
- package/dist/{adminFetch-BfOnfRgU.js.map → adminFetch-C7Ra8rpP.js.map} +1 -1
- package/dist/components/Database/ActivitySection.d.ts +9 -0
- package/dist/components/Database/AdvisorsSection.d.ts +17 -0
- package/dist/components/Database/DatabaseView.d.ts +13 -0
- package/dist/components/Database/ExtensionsSection.d.ts +2 -0
- package/dist/components/Database/FunctionsSection.d.ts +2 -0
- package/dist/components/Database/QueriesSection.d.ts +3 -0
- package/dist/components/Database/TriggersSection.d.ts +2 -0
- package/dist/components/Database/TypesSection.d.ts +2 -0
- package/dist/components/Database/format.d.ts +6 -0
- package/dist/components/Database/links.d.ts +11 -0
- package/dist/components/Database/shared.d.ts +35 -0
- package/dist/components/Database/source.d.ts +12 -0
- package/dist/components/Database/useCatalogList.d.ts +13 -0
- package/dist/components/RLSEditor/RLSEditor.d.ts +2 -0
- package/dist/components/RLSEditor/TablePolicies.d.ts +54 -0
- package/dist/components/SQLEditor/ExplainVisualizer.d.ts +8 -20
- package/dist/components/SQLEditor/ResultChart.d.ts +18 -0
- package/dist/components/SQLEditor/SQLEditor.d.ts +13 -1
- package/dist/components/SQLEditor/SQLEditorRoute.d.ts +13 -0
- package/dist/components/SQLEditor/SQLEditorSidebar.d.ts +7 -1
- package/dist/components/SQLEditor/SqlParamsPanel.d.ts +16 -0
- package/dist/components/SQLEditor/useSqlSnippets.d.ts +47 -0
- package/dist/components/SchemaVisualizer/SchemaDiagramView.d.ts +12 -0
- package/dist/components/SchemaVisualizer/TablesDiagram.d.ts +23 -0
- package/dist/components/SchemaVisualizer/useSchemaGraph.d.ts +32 -1
- package/dist/components/StorageView/StorageView.d.ts +5 -0
- package/dist/components/TableEditor/CreateTableDialog.d.ts +8 -0
- package/dist/components/TableEditor/DdlConfirm.d.ts +23 -0
- package/dist/components/TableEditor/SqlBlock.d.ts +7 -0
- package/dist/components/TableEditor/TableDdlSheet.d.ts +9 -0
- package/dist/components/TableEditor/TableEditorView.d.ts +7 -0
- package/dist/components/TableEditor/tableModel.d.ts +210 -0
- package/dist/components/TableEditor/tabs/DataTab.d.ts +12 -0
- package/dist/components/TableEditor/tabs/PoliciesTab.d.ts +8 -0
- package/dist/components/TableEditor/tabs/RelationsTab.d.ts +8 -0
- package/dist/components/TableEditor/tabs/SettingsTab.d.ts +11 -0
- package/dist/components/TableEditor/tabs/StatsTab.d.ts +8 -0
- package/dist/components/TableEditor/tabs/StructureTab.d.ts +12 -0
- package/dist/index.es.js +29 -15
- package/dist/index.es.js.map +1 -1
- package/dist/{sql_utils-CYcgpgam.js → sql_utils-DkMYltfq.js} +27 -3
- package/dist/sql_utils-DkMYltfq.js.map +1 -0
- package/dist/useRunAsUsers-GPFCxcBC.js +69 -0
- package/dist/useRunAsUsers-GPFCxcBC.js.map +1 -0
- package/dist/utils/adminFetch.d.ts +1 -0
- package/dist/utils/csv_parse.d.ts +11 -0
- package/dist/utils/explain_plan.d.ts +70 -0
- package/dist/utils/sql_params.d.ts +51 -0
- package/dist/utils/sql_utils.d.ts +16 -0
- package/package.json +11 -9
- package/dist/RLSEditor-CTG3jLE7.js +0 -2572
- package/dist/RLSEditor-CTG3jLE7.js.map +0 -1
- package/dist/SQLEditor-DRo5kW1h.js.map +0 -1
- package/dist/SchemaVisualizer-Dy4kWKT5.js.map +0 -1
- package/dist/StorageView-D0D8z4lI.js.map +0 -1
- package/dist/TableEditorView-BKhSBG-K.js +0 -1694
- package/dist/TableEditorView-BKhSBG-K.js.map +0 -1
- package/dist/components/SchemaVisualizer/SchemaVisualizer.d.ts +0 -3
- package/dist/policy-presets-CJKzAvQp.js +0 -167
- package/dist/policy-presets-CJKzAvQp.js.map +0 -1
- package/dist/sql_utils-CYcgpgam.js.map +0 -1
- package/dist/useRunAsUsers-CF7tkGzj.js.map +0 -1
|
@@ -1,2572 +0,0 @@
|
|
|
1
|
-
import { a as asStringArray, i as asString, n as asNullableString, o as isRecord, s as useAdminFetch, t as asBoolean } from "./adminFetch-BfOnfRgU.js";
|
|
2
|
-
import { o as quoteIdentifier } from "./sql_utils-CYcgpgam.js";
|
|
3
|
-
import { i as roleOptionsFor, n as POLICY_PRESETS, t as COMMAND_OPTIONS } from "./policy-presets-CJKzAvQp.js";
|
|
4
|
-
import { t as MonacoEditor } from "./MonacoEditor-7IlHFZU5.js";
|
|
5
|
-
import { r as schemaSourceProblem, t as SchemaSourceProblemAlert } from "./schema-source-C4ekB7WU.js";
|
|
6
|
-
import { ConfirmationDialog, ErrorView, useApiBase, useApiConfig, useRebaseContext, useSnackbarController, useStudioCapabilities, useStudioSchemaEditing, useTableDescriptors, useTranslation } from "@rebasepro/app";
|
|
7
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
|
-
import { Alert, AlertTriangleIcon, BooleanSwitchWithLabel, Button, Card, Chip, CircularProgress, DatabaseIcon, Dialog, DialogActions, DialogContent, DialogTitle, HelpCircleIcon, IconButton, KeyIcon, LockIcon, MultiSelect, MultiSelectItem, Paper, PlusIcon, RefreshCwIcon, ResizablePanels, Select, SelectItem, ShieldIcon, Tab, Table, TableBody, TableCell, TableHeader, TableRow, Tabs, TextField, Tooltip, Trash2Icon, Typography, cls, defaultBorderMixin, iconSize } from "@rebasepro/ui";
|
|
9
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
import { REBASE_ADMIN_REQUEST_ROLE, REBASE_ADMIN_ROLE, RLS_JWT_SQL, RLS_ROLES_SQL, RLS_UID_SQL, isRedactedSecurityRule, rulePatches } from "@rebasepro/types";
|
|
11
|
-
import { adminRequestPolicyName, getPolicyNamesForRule, getPolicyOperations } from "@rebasepro/utils";
|
|
12
|
-
import { JUNCTION_TABLES_SQL, REBASE_INTERNAL_PREFIXES, REBASE_INTERNAL_SCHEMAS, REBASE_USER_ROLE, policyToSecurityRule } from "@rebasepro/common";
|
|
13
|
-
//#region src/components/RLSEditor/PolicyEditor.tsx
|
|
14
|
-
var PolicyEditor = ({ policy, schema, table, roleOptions, onSave, onCancel }) => {
|
|
15
|
-
const { t } = useTranslation();
|
|
16
|
-
const [name, setName] = useState("");
|
|
17
|
-
const [helpOpen, setHelpOpen] = useState(false);
|
|
18
|
-
const [behavior, setBehavior] = useState("PERMISSIVE");
|
|
19
|
-
const [command, setCommand] = useState("ALL");
|
|
20
|
-
const [roles, setRoles] = useState(["public"]);
|
|
21
|
-
const [usingExpr, setUsingExpr] = useState("");
|
|
22
|
-
const [checkExpr, setCheckExpr] = useState("");
|
|
23
|
-
const [selectedPreset, setSelectedPreset] = useState("");
|
|
24
|
-
const availableRoles = useMemo(() => roleOptionsFor(roleOptions, policy?.roles), [roleOptions, policy]);
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
if (policy) {
|
|
27
|
-
setName(policy.policyname || "");
|
|
28
|
-
setBehavior(policy.permissive || "PERMISSIVE");
|
|
29
|
-
setCommand(policy.cmd || "ALL");
|
|
30
|
-
const initialRoles = policy.roles ? Array.isArray(policy.roles) ? policy.roles : [policy.roles] : ["public"];
|
|
31
|
-
setRoles(initialRoles);
|
|
32
|
-
setUsingExpr(policy.qual || "");
|
|
33
|
-
setCheckExpr(policy.with_check || "");
|
|
34
|
-
} else {
|
|
35
|
-
setName("");
|
|
36
|
-
setBehavior("PERMISSIVE");
|
|
37
|
-
setCommand("ALL");
|
|
38
|
-
setRoles(["public"]);
|
|
39
|
-
setUsingExpr("");
|
|
40
|
-
setCheckExpr("");
|
|
41
|
-
setSelectedPreset("");
|
|
42
|
-
}
|
|
43
|
-
}, [policy]);
|
|
44
|
-
const handlePresetChange = (presetId) => {
|
|
45
|
-
const preset = POLICY_PRESETS.find((p) => p.id === presetId);
|
|
46
|
-
if (!preset) return;
|
|
47
|
-
setSelectedPreset(presetId);
|
|
48
|
-
setName(preset.policyname);
|
|
49
|
-
setBehavior(preset.permissive);
|
|
50
|
-
setCommand(preset.cmd);
|
|
51
|
-
setRoles(preset.roles);
|
|
52
|
-
setUsingExpr(preset.qual);
|
|
53
|
-
setCheckExpr(preset.with_check);
|
|
54
|
-
};
|
|
55
|
-
const showCheck = command === "ALL" || command === "INSERT" || command === "UPDATE";
|
|
56
|
-
/**
|
|
57
|
-
* The two expression editors. Save reads what they hold now: an edit
|
|
58
|
-
* reaches `usingExpr` and `checkExpr` only when this re-renders, so a Save
|
|
59
|
-
* right after a paste wrote the expression from before it.
|
|
60
|
-
*/
|
|
61
|
-
const usingEditor = useRef(null);
|
|
62
|
-
const checkEditor = useRef(null);
|
|
63
|
-
const handleSave = () => {
|
|
64
|
-
onSave({
|
|
65
|
-
policyname: name,
|
|
66
|
-
permissive: behavior,
|
|
67
|
-
cmd: command,
|
|
68
|
-
roles,
|
|
69
|
-
qual: usingEditor.current?.getValue() ?? usingExpr,
|
|
70
|
-
with_check: showCheck ? checkEditor.current?.getValue() ?? checkExpr : null
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
74
|
-
/* @__PURE__ */ jsxs(Typography, {
|
|
75
|
-
variant: "h6",
|
|
76
|
-
gutterBottom: true,
|
|
77
|
-
className: "mt-8 mx-8 flex justify-between items-center w-full",
|
|
78
|
-
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", { children: policy ? t("studio_policy_edit") : t("studio_policy_create") }), /* @__PURE__ */ jsxs("div", {
|
|
79
|
-
className: "text-sm font-normal text-text-secondary dark:text-text-secondary-dark tracking-wide mt-1",
|
|
80
|
-
children: [
|
|
81
|
-
t("studio_policy_defining_rules"),
|
|
82
|
-
" ",
|
|
83
|
-
/* @__PURE__ */ jsxs("span", {
|
|
84
|
-
className: "font-mono text-primary bg-primary-bg px-1 py-0.5 rounded",
|
|
85
|
-
children: [
|
|
86
|
-
schema,
|
|
87
|
-
".",
|
|
88
|
-
table
|
|
89
|
-
]
|
|
90
|
-
})
|
|
91
|
-
]
|
|
92
|
-
})] }), /* @__PURE__ */ jsx(IconButton, {
|
|
93
|
-
"aria-label": t("help"),
|
|
94
|
-
size: "small",
|
|
95
|
-
onClick: () => setHelpOpen(true),
|
|
96
|
-
children: /* @__PURE__ */ jsx(HelpCircleIcon, { size: iconSize.smallest })
|
|
97
|
-
})]
|
|
98
|
-
}),
|
|
99
|
-
/* @__PURE__ */ jsx(DialogContent, {
|
|
100
|
-
className: "p-4 md:p-6 border-t border-hairline bg-surface-well",
|
|
101
|
-
includeMargin: false,
|
|
102
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
103
|
-
className: "max-w-4xl mx-auto",
|
|
104
|
-
children: [/* @__PURE__ */ jsxs(Paper, {
|
|
105
|
-
className: cls("p-4 md:p-6 flex flex-col gap-6 bg-surface-card border-none sm:border-solid rounded-none sm:rounded-xl", defaultBorderMixin),
|
|
106
|
-
children: [
|
|
107
|
-
!policy && /* @__PURE__ */ jsxs("div", {
|
|
108
|
-
className: "flex flex-col gap-1.5 bg-primary/5 p-3 sm:p-4 rounded-lg border border-primary/10 dark:border-primary/20",
|
|
109
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
110
|
-
variant: "caption",
|
|
111
|
-
className: "text-primary dark:text-primary-light uppercase tracking-wider",
|
|
112
|
-
children: t("studio_policy_template")
|
|
113
|
-
}), /* @__PURE__ */ jsx(Select, {
|
|
114
|
-
size: "small",
|
|
115
|
-
value: selectedPreset,
|
|
116
|
-
onValueChange: handlePresetChange,
|
|
117
|
-
position: "item-aligned",
|
|
118
|
-
placeholder: t("studio_policy_select_template"),
|
|
119
|
-
className: "bg-surface-card",
|
|
120
|
-
children: POLICY_PRESETS.map((preset) => /* @__PURE__ */ jsx(SelectItem, {
|
|
121
|
-
value: preset.id,
|
|
122
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
123
|
-
className: "flex flex-col text-left",
|
|
124
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
125
|
-
className: "text-sm",
|
|
126
|
-
children: preset.label
|
|
127
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
128
|
-
className: "text-xs text-text-secondary dark:text-text-secondary-dark",
|
|
129
|
-
children: preset.description
|
|
130
|
-
})]
|
|
131
|
-
})
|
|
132
|
-
}, preset.id))
|
|
133
|
-
})]
|
|
134
|
-
}),
|
|
135
|
-
/* @__PURE__ */ jsxs("div", {
|
|
136
|
-
className: "grid grid-cols-1 md:grid-cols-2 gap-4 sm:gap-6",
|
|
137
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
138
|
-
className: "flex flex-col gap-1.5",
|
|
139
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
140
|
-
variant: "caption",
|
|
141
|
-
className: "uppercase tracking-wider text-text-secondary",
|
|
142
|
-
children: t("studio_policy_name")
|
|
143
|
-
}), /* @__PURE__ */ jsx(TextField, {
|
|
144
|
-
value: name,
|
|
145
|
-
"aria-label": t("studio_policy_name"),
|
|
146
|
-
onChange: (e) => setName(e.target.value),
|
|
147
|
-
placeholder: t("studio_policy_name_placeholder"),
|
|
148
|
-
className: "w-full"
|
|
149
|
-
})]
|
|
150
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
151
|
-
className: "flex flex-col gap-1.5",
|
|
152
|
-
children: [/* @__PURE__ */ jsxs(Typography, {
|
|
153
|
-
variant: "caption",
|
|
154
|
-
className: "uppercase tracking-wider text-text-secondary",
|
|
155
|
-
children: [
|
|
156
|
-
t("studio_policy_behavior"),
|
|
157
|
-
" ",
|
|
158
|
-
/* @__PURE__ */ jsx("code", {
|
|
159
|
-
className: "text-xs bg-hairline text-text-secondary dark:text-text-secondary-dark px-1 py-0.5 rounded ml-1",
|
|
160
|
-
children: "AS"
|
|
161
|
-
})
|
|
162
|
-
]
|
|
163
|
-
}), /* @__PURE__ */ jsxs(Select, {
|
|
164
|
-
value: behavior,
|
|
165
|
-
onValueChange: (val) => setBehavior(val),
|
|
166
|
-
position: "item-aligned",
|
|
167
|
-
children: [/* @__PURE__ */ jsx(SelectItem, {
|
|
168
|
-
value: "PERMISSIVE",
|
|
169
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
170
|
-
className: "flex flex-col text-left",
|
|
171
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
172
|
-
className: "",
|
|
173
|
-
children: t("studio_policy_permissive")
|
|
174
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
175
|
-
className: "text-xs text-text-secondary dark:text-text-secondary-dark",
|
|
176
|
-
children: t("studio_policy_permissive_desc")
|
|
177
|
-
})]
|
|
178
|
-
})
|
|
179
|
-
}), /* @__PURE__ */ jsx(SelectItem, {
|
|
180
|
-
value: "RESTRICTIVE",
|
|
181
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
182
|
-
className: "flex flex-col text-left",
|
|
183
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
184
|
-
className: "",
|
|
185
|
-
children: t("studio_policy_restrictive")
|
|
186
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
187
|
-
className: "text-xs text-text-secondary dark:text-text-secondary-dark",
|
|
188
|
-
children: t("studio_policy_restrictive_desc")
|
|
189
|
-
})]
|
|
190
|
-
})
|
|
191
|
-
})]
|
|
192
|
-
})]
|
|
193
|
-
})]
|
|
194
|
-
}),
|
|
195
|
-
/* @__PURE__ */ jsxs("div", {
|
|
196
|
-
className: "flex flex-col gap-1.5",
|
|
197
|
-
children: [/* @__PURE__ */ jsxs(Typography, {
|
|
198
|
-
variant: "caption",
|
|
199
|
-
className: "uppercase tracking-wider text-text-secondary",
|
|
200
|
-
children: [
|
|
201
|
-
t("studio_policy_command"),
|
|
202
|
-
" ",
|
|
203
|
-
/* @__PURE__ */ jsx("code", {
|
|
204
|
-
className: "text-xs bg-hairline text-text-secondary dark:text-text-secondary-dark px-1 py-0.5 rounded ml-1",
|
|
205
|
-
children: "FOR"
|
|
206
|
-
})
|
|
207
|
-
]
|
|
208
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
209
|
-
className: "flex flex-wrap gap-1.5",
|
|
210
|
-
children: COMMAND_OPTIONS.map((cmd) => /* @__PURE__ */ jsx(Button, {
|
|
211
|
-
size: "small",
|
|
212
|
-
variant: command === cmd ? "filled" : "text",
|
|
213
|
-
color: "neutral",
|
|
214
|
-
onClick: () => setCommand(cmd),
|
|
215
|
-
className: "min-w-[80px]",
|
|
216
|
-
children: cmd
|
|
217
|
-
}, cmd))
|
|
218
|
-
})]
|
|
219
|
-
}),
|
|
220
|
-
/* @__PURE__ */ jsxs("div", {
|
|
221
|
-
className: "flex flex-col gap-1.5",
|
|
222
|
-
children: [/* @__PURE__ */ jsxs(Typography, {
|
|
223
|
-
variant: "caption",
|
|
224
|
-
className: "uppercase tracking-wider text-text-secondary",
|
|
225
|
-
children: [
|
|
226
|
-
t("studio_policy_target_roles"),
|
|
227
|
-
" ",
|
|
228
|
-
/* @__PURE__ */ jsx("code", {
|
|
229
|
-
className: "text-xs bg-hairline text-text-secondary dark:text-text-secondary-dark px-1 py-0.5 rounded ml-1",
|
|
230
|
-
children: "TO"
|
|
231
|
-
})
|
|
232
|
-
]
|
|
233
|
-
}), /* @__PURE__ */ jsx(MultiSelect, {
|
|
234
|
-
size: "small",
|
|
235
|
-
value: roles,
|
|
236
|
-
onValueChange: setRoles,
|
|
237
|
-
placeholder: t("studio_policy_roles_placeholder"),
|
|
238
|
-
children: availableRoles.map((role) => /* @__PURE__ */ jsx(MultiSelectItem, {
|
|
239
|
-
value: role,
|
|
240
|
-
children: role
|
|
241
|
-
}, role))
|
|
242
|
-
})]
|
|
243
|
-
})
|
|
244
|
-
]
|
|
245
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
246
|
-
className: "mt-8 flex flex-col gap-4",
|
|
247
|
-
children: [command !== "INSERT" && /* @__PURE__ */ jsxs("div", {
|
|
248
|
-
className: "flex flex-col gap-1.5",
|
|
249
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
250
|
-
className: "flex flex-col gap-0.5",
|
|
251
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
252
|
-
variant: "caption",
|
|
253
|
-
className: "uppercase tracking-wider text-text-secondary",
|
|
254
|
-
children: t("studio_policy_using_expr")
|
|
255
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
256
|
-
variant: "caption",
|
|
257
|
-
className: "text-text-secondary opacity-70",
|
|
258
|
-
children: t("studio_policy_using_expr_desc")
|
|
259
|
-
})]
|
|
260
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
261
|
-
className: cls("h-32 border rounded-md overflow-hidden bg-surface-card", defaultBorderMixin),
|
|
262
|
-
children: /* @__PURE__ */ jsx(MonacoEditor, {
|
|
263
|
-
ref: usingEditor,
|
|
264
|
-
value: usingExpr,
|
|
265
|
-
onChange: (v) => setUsingExpr(v || ""),
|
|
266
|
-
readOnly: false,
|
|
267
|
-
autoFocus: true
|
|
268
|
-
})
|
|
269
|
-
})]
|
|
270
|
-
}), showCheck && /* @__PURE__ */ jsxs("div", {
|
|
271
|
-
className: "flex flex-col gap-1.5 mt-2",
|
|
272
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
273
|
-
className: "flex flex-col gap-0.5",
|
|
274
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
275
|
-
variant: "caption",
|
|
276
|
-
className: "uppercase tracking-wider text-text-secondary",
|
|
277
|
-
children: t("studio_policy_check_expr")
|
|
278
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
279
|
-
variant: "caption",
|
|
280
|
-
className: "text-text-secondary opacity-70",
|
|
281
|
-
children: t("studio_policy_check_expr_desc")
|
|
282
|
-
})]
|
|
283
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
284
|
-
className: cls("h-32 border rounded-md overflow-hidden bg-surface-card", defaultBorderMixin),
|
|
285
|
-
children: /* @__PURE__ */ jsx(MonacoEditor, {
|
|
286
|
-
ref: checkEditor,
|
|
287
|
-
value: checkExpr,
|
|
288
|
-
onChange: (v) => setCheckExpr(v || ""),
|
|
289
|
-
readOnly: false,
|
|
290
|
-
autoFocus: command === "INSERT"
|
|
291
|
-
})
|
|
292
|
-
})]
|
|
293
|
-
})]
|
|
294
|
-
})]
|
|
295
|
-
})
|
|
296
|
-
}),
|
|
297
|
-
/* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
|
|
298
|
-
size: "small",
|
|
299
|
-
variant: "text",
|
|
300
|
-
color: "neutral",
|
|
301
|
-
onClick: onCancel,
|
|
302
|
-
children: t("studio_policy_cancel")
|
|
303
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
304
|
-
size: "small",
|
|
305
|
-
variant: "filled",
|
|
306
|
-
color: "primary",
|
|
307
|
-
onClick: handleSave,
|
|
308
|
-
disabled: !name,
|
|
309
|
-
children: t("studio_policy_save")
|
|
310
|
-
})] }),
|
|
311
|
-
/* @__PURE__ */ jsxs(Dialog, {
|
|
312
|
-
open: helpOpen,
|
|
313
|
-
onOpenChange: setHelpOpen,
|
|
314
|
-
maxWidth: "3xl",
|
|
315
|
-
children: [
|
|
316
|
-
/* @__PURE__ */ jsx(DialogTitle, {
|
|
317
|
-
hidden: true,
|
|
318
|
-
children: t("studio_policy_help_title")
|
|
319
|
-
}),
|
|
320
|
-
/* @__PURE__ */ jsxs(DialogContent, {
|
|
321
|
-
className: "p-4 sm:p-6 lg:p-8 flex flex-col gap-6",
|
|
322
|
-
children: [
|
|
323
|
-
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Typography, {
|
|
324
|
-
variant: "h5",
|
|
325
|
-
className: "mb-2",
|
|
326
|
-
children: t("studio_policy_help_title")
|
|
327
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
328
|
-
className: "text-text-secondary dark:text-text-secondary-dark",
|
|
329
|
-
children: t("studio_policy_help_intro")
|
|
330
|
-
})] }),
|
|
331
|
-
/* @__PURE__ */ jsxs("div", {
|
|
332
|
-
className: "flex flex-col gap-4",
|
|
333
|
-
children: [
|
|
334
|
-
/* @__PURE__ */ jsxs(Paper, {
|
|
335
|
-
className: cls("p-4 sm:p-5 flex flex-col gap-1", defaultBorderMixin),
|
|
336
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
337
|
-
variant: "subtitle2",
|
|
338
|
-
className: "text-primary dark:text-primary-light font-medium",
|
|
339
|
-
children: t("studio_policy_help_step1_title")
|
|
340
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
341
|
-
variant: "body2",
|
|
342
|
-
className: "text-text-secondary dark:text-text-secondary-dark",
|
|
343
|
-
children: t("studio_policy_help_step1_desc")
|
|
344
|
-
})]
|
|
345
|
-
}),
|
|
346
|
-
/* @__PURE__ */ jsxs(Paper, {
|
|
347
|
-
className: cls("p-4 sm:p-5 flex flex-col gap-1", defaultBorderMixin),
|
|
348
|
-
children: [
|
|
349
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
350
|
-
variant: "subtitle2",
|
|
351
|
-
className: "text-primary dark:text-primary-light font-medium",
|
|
352
|
-
children: t("studio_policy_help_step2_title")
|
|
353
|
-
}),
|
|
354
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
355
|
-
variant: "body2",
|
|
356
|
-
className: "text-text-secondary dark:text-text-secondary-dark mb-1",
|
|
357
|
-
children: t("studio_policy_help_step2_desc")
|
|
358
|
-
}),
|
|
359
|
-
/* @__PURE__ */ jsxs("ul", {
|
|
360
|
-
className: "list-disc pl-5 space-y-1 text-sm text-text-secondary dark:text-text-secondary-dark",
|
|
361
|
-
children: [/* @__PURE__ */ jsxs("li", { children: [
|
|
362
|
-
/* @__PURE__ */ jsx("strong", { children: "public" }),
|
|
363
|
-
": ",
|
|
364
|
-
t("studio_policy_help_role_public")
|
|
365
|
-
] }), /* @__PURE__ */ jsxs("li", { children: [
|
|
366
|
-
/* @__PURE__ */ jsx("strong", { children: REBASE_USER_ROLE }),
|
|
367
|
-
": ",
|
|
368
|
-
t("studio_policy_help_role_rebase_user")
|
|
369
|
-
] })]
|
|
370
|
-
}),
|
|
371
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
372
|
-
variant: "body2",
|
|
373
|
-
className: "text-text-secondary dark:text-text-secondary-dark mt-1",
|
|
374
|
-
children: t("studio_policy_help_roles_not_users")
|
|
375
|
-
})
|
|
376
|
-
]
|
|
377
|
-
}),
|
|
378
|
-
/* @__PURE__ */ jsxs(Paper, {
|
|
379
|
-
className: cls("p-4 sm:p-5 flex flex-col gap-1", defaultBorderMixin),
|
|
380
|
-
children: [
|
|
381
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
382
|
-
variant: "subtitle2",
|
|
383
|
-
className: "text-primary dark:text-primary-light font-medium",
|
|
384
|
-
children: t("studio_policy_help_step3_title")
|
|
385
|
-
}),
|
|
386
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
387
|
-
variant: "body2",
|
|
388
|
-
className: "text-text-secondary dark:text-text-secondary-dark mb-1",
|
|
389
|
-
children: t("studio_policy_help_step3_desc")
|
|
390
|
-
}),
|
|
391
|
-
/* @__PURE__ */ jsxs("div", {
|
|
392
|
-
className: cls("bg-surface-well px-3 py-2 rounded-md font-mono text-sm my-2", defaultBorderMixin),
|
|
393
|
-
children: [
|
|
394
|
-
t("studio_policy_help_example"),
|
|
395
|
-
" ",
|
|
396
|
-
RLS_UID_SQL,
|
|
397
|
-
" = uid"
|
|
398
|
-
]
|
|
399
|
-
}),
|
|
400
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
401
|
-
variant: "caption",
|
|
402
|
-
className: "text-text-secondary dark:text-text-secondary-dark",
|
|
403
|
-
children: t("studio_policy_help_step3_example")
|
|
404
|
-
})
|
|
405
|
-
]
|
|
406
|
-
}),
|
|
407
|
-
/* @__PURE__ */ jsxs(Paper, {
|
|
408
|
-
className: cls("p-4 sm:p-5 flex flex-col gap-1", defaultBorderMixin),
|
|
409
|
-
children: [
|
|
410
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
411
|
-
variant: "subtitle2",
|
|
412
|
-
className: "text-primary dark:text-primary-light font-medium",
|
|
413
|
-
children: t("studio_policy_help_step4_title")
|
|
414
|
-
}),
|
|
415
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
416
|
-
variant: "body2",
|
|
417
|
-
className: "text-text-secondary dark:text-text-secondary-dark mb-1",
|
|
418
|
-
children: t("studio_policy_help_step4_desc")
|
|
419
|
-
}),
|
|
420
|
-
/* @__PURE__ */ jsxs("div", {
|
|
421
|
-
className: cls("bg-surface-well px-3 py-2 rounded-md font-mono text-sm my-2", defaultBorderMixin),
|
|
422
|
-
children: [
|
|
423
|
-
t("studio_policy_help_example"),
|
|
424
|
-
" ",
|
|
425
|
-
RLS_UID_SQL,
|
|
426
|
-
" = uid"
|
|
427
|
-
]
|
|
428
|
-
}),
|
|
429
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
430
|
-
variant: "caption",
|
|
431
|
-
className: "text-text-secondary dark:text-text-secondary-dark",
|
|
432
|
-
children: t("studio_policy_help_step4_example")
|
|
433
|
-
})
|
|
434
|
-
]
|
|
435
|
-
}),
|
|
436
|
-
/* @__PURE__ */ jsxs(Paper, {
|
|
437
|
-
className: cls("p-4 sm:p-5 flex flex-col gap-2 bg-primary/5", defaultBorderMixin),
|
|
438
|
-
children: [
|
|
439
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
440
|
-
variant: "subtitle2",
|
|
441
|
-
className: "text-primary dark:text-primary-light font-medium",
|
|
442
|
-
children: t("studio_policy_help_auth_vars_title")
|
|
443
|
-
}),
|
|
444
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
445
|
-
variant: "body2",
|
|
446
|
-
className: "text-text-secondary dark:text-text-secondary-dark",
|
|
447
|
-
children: t("studio_policy_help_auth_vars_desc")
|
|
448
|
-
}),
|
|
449
|
-
/* @__PURE__ */ jsxs("ul", {
|
|
450
|
-
className: "list-disc pl-5 space-y-2 text-sm text-text-secondary dark:text-text-secondary-dark font-normal",
|
|
451
|
-
children: [
|
|
452
|
-
/* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsx("code", {
|
|
453
|
-
className: "bg-surface-well px-1.5 py-0.5 rounded mr-1 whitespace-nowrap",
|
|
454
|
-
children: RLS_UID_SQL
|
|
455
|
-
}), /* @__PURE__ */ jsxs("span", {
|
|
456
|
-
className: "block mt-0.5",
|
|
457
|
-
children: [
|
|
458
|
-
t("studio_policy_help_auth_uid"),
|
|
459
|
-
" ",
|
|
460
|
-
/* @__PURE__ */ jsxs("code", {
|
|
461
|
-
className: "bg-surface-well px-1 py-0.5 rounded text-xs",
|
|
462
|
-
children: [RLS_UID_SQL, " = uid"]
|
|
463
|
-
})
|
|
464
|
-
]
|
|
465
|
-
})] }),
|
|
466
|
-
/* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsx("code", {
|
|
467
|
-
className: "bg-surface-well px-1.5 py-0.5 rounded mr-1 whitespace-nowrap",
|
|
468
|
-
children: RLS_JWT_SQL
|
|
469
|
-
}), /* @__PURE__ */ jsxs("span", {
|
|
470
|
-
className: "block mt-0.5",
|
|
471
|
-
children: [
|
|
472
|
-
t("studio_policy_help_auth_jwt"),
|
|
473
|
-
" ",
|
|
474
|
-
/* @__PURE__ */ jsxs("code", {
|
|
475
|
-
className: "bg-surface-well px-1 py-0.5 rounded text-xs",
|
|
476
|
-
children: [RLS_JWT_SQL, " ->> 'email' = 'admin@example.com'"]
|
|
477
|
-
})
|
|
478
|
-
]
|
|
479
|
-
})] }),
|
|
480
|
-
/* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsx("code", {
|
|
481
|
-
className: "bg-surface-well px-1.5 py-0.5 rounded mr-1 whitespace-nowrap",
|
|
482
|
-
children: RLS_ROLES_SQL
|
|
483
|
-
}), /* @__PURE__ */ jsxs("span", {
|
|
484
|
-
className: "block mt-0.5",
|
|
485
|
-
children: [
|
|
486
|
-
t("studio_policy_help_auth_roles"),
|
|
487
|
-
" ",
|
|
488
|
-
/* @__PURE__ */ jsxs("code", {
|
|
489
|
-
className: "bg-surface-well px-1 py-0.5 rounded text-xs",
|
|
490
|
-
children: [
|
|
491
|
-
"string_to_array(",
|
|
492
|
-
RLS_ROLES_SQL,
|
|
493
|
-
", ',') @> ARRAY['admin']"
|
|
494
|
-
]
|
|
495
|
-
})
|
|
496
|
-
]
|
|
497
|
-
})] })
|
|
498
|
-
]
|
|
499
|
-
})
|
|
500
|
-
]
|
|
501
|
-
})
|
|
502
|
-
]
|
|
503
|
-
}),
|
|
504
|
-
/* @__PURE__ */ jsxs("div", {
|
|
505
|
-
className: cls("mt-2 flex flex-col sm:flex-row justify-between items-start sm:items-center bg-primary/5 p-4 rounded-xl border border-primary/10 dark:border-primary/20", defaultBorderMixin),
|
|
506
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
507
|
-
variant: "body2",
|
|
508
|
-
className: "text-primary dark:text-primary-light mb-4 sm:mb-0 max-w-md",
|
|
509
|
-
children: t("studio_policy_help_docs_cta")
|
|
510
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
511
|
-
component: "a",
|
|
512
|
-
href: "https://www.postgresql.org/docs/current/sql-createpolicy.html",
|
|
513
|
-
target: "_blank",
|
|
514
|
-
variant: "outlined",
|
|
515
|
-
color: "primary",
|
|
516
|
-
size: "small",
|
|
517
|
-
className: "whitespace-nowrap flex-shrink-0",
|
|
518
|
-
children: t("studio_policy_help_read_docs")
|
|
519
|
-
})]
|
|
520
|
-
})
|
|
521
|
-
]
|
|
522
|
-
}),
|
|
523
|
-
/* @__PURE__ */ jsx(DialogActions, {
|
|
524
|
-
className: "p-4 sm:px-6 sm:pb-6 pt-0 border-t-0",
|
|
525
|
-
children: /* @__PURE__ */ jsx(Button, {
|
|
526
|
-
onClick: () => setHelpOpen(false),
|
|
527
|
-
variant: "filled",
|
|
528
|
-
color: "primary",
|
|
529
|
-
children: t("studio_policy_help_got_it")
|
|
530
|
-
})
|
|
531
|
-
})
|
|
532
|
-
]
|
|
533
|
-
})
|
|
534
|
-
] });
|
|
535
|
-
};
|
|
536
|
-
//#endregion
|
|
537
|
-
//#region src/components/RLSEditor/saveSecurityRules.ts
|
|
538
|
-
/**
|
|
539
|
-
* Write a table's rule edits to its source file: `{ patches }` to the
|
|
540
|
-
* source-only schema editor (`/admin/schema-editor/apply`).
|
|
541
|
-
*
|
|
542
|
-
* The schema-editor routes sit behind an admin gate that accepts a bearer token
|
|
543
|
-
* and nothing else — there is no cookie fallback — so a request without an
|
|
544
|
-
* `Authorization` header is a 401 every time. The RLS editor's two write paths
|
|
545
|
-
* ("Create policy" on a mapped table, and "Import to codebase") both sent none,
|
|
546
|
-
* and both reported the failure as a constant "Failed to save policy", which is
|
|
547
|
-
* also what a 501 and a parse error looked like.
|
|
548
|
-
*
|
|
549
|
-
* It lives in its own module rather than inline in the component so that the
|
|
550
|
-
* header can be asserted without rendering the whole RLS editor.
|
|
551
|
-
*/
|
|
552
|
-
async function postTablePatches(options) {
|
|
553
|
-
const { apiBase, patches, getAuthToken } = options;
|
|
554
|
-
const headers = { "Content-Type": "application/json" };
|
|
555
|
-
const token = getAuthToken ? await getAuthToken() : null;
|
|
556
|
-
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
557
|
-
const response = await fetch(`${apiBase}/admin/schema-editor/apply`, {
|
|
558
|
-
method: "POST",
|
|
559
|
-
headers,
|
|
560
|
-
body: JSON.stringify({ patches })
|
|
561
|
-
});
|
|
562
|
-
if (response.ok) return;
|
|
563
|
-
const body = await response.text().catch(() => "");
|
|
564
|
-
let message;
|
|
565
|
-
try {
|
|
566
|
-
const parsed = JSON.parse(body);
|
|
567
|
-
const error = typeof parsed === "object" && parsed !== null && "error" in parsed ? parsed.error : void 0;
|
|
568
|
-
message = typeof error === "object" && error !== null && "message" in error && typeof error.message === "string" ? error.message : void 0;
|
|
569
|
-
} catch {
|
|
570
|
-
message = body.trim() || void 0;
|
|
571
|
-
}
|
|
572
|
-
throw new Error(message ?? `Failed to save policy (HTTP ${response.status}).`);
|
|
573
|
-
}
|
|
574
|
-
//#endregion
|
|
575
|
-
//#region src/components/RLSEditor/saveRules.ts
|
|
576
|
-
/**
|
|
577
|
-
* Where a table's security rules go when the RLS editor saves them — the one
|
|
578
|
-
* function every RLS-editor write to the source goes through.
|
|
579
|
-
*
|
|
580
|
-
* The edit is sent as the rule operations it is (`TablePatch`): the rules the
|
|
581
|
-
* table declares, compared with the rules it should declare, by
|
|
582
|
-
* {@link rulePatches} — one `replaceRule` for an edited rule, one `addRule`
|
|
583
|
-
* for an imported one. A policy's name is a hash of its rule as written, so a
|
|
584
|
-
* rule the edit did not touch is never rewritten. A posture is `setRls`:
|
|
585
|
-
* removing the last rule is `"admin-only"`, never an empty list.
|
|
586
|
-
*
|
|
587
|
-
* A table whose rules are inherited from `defaultRls` keeps `"inherit"`
|
|
588
|
-
* unless the person deliberately detaches it: `confirmDetach` asks (naming
|
|
589
|
-
* what happens), and saying no writes nothing.
|
|
590
|
-
*
|
|
591
|
-
* There are two doors onto one file. With a collection editor mounted, the
|
|
592
|
-
* write goes through its plan/apply flow — planned, shown as SQL, confirmed,
|
|
593
|
-
* applied to the database — arriving over the Studio bridge as
|
|
594
|
-
* {@link StudioSchemaEditing} (`@rebasepro/cms` is a *peer* of
|
|
595
|
-
* `@rebasepro/studio`, which has to run without it). Without one, it goes to
|
|
596
|
-
* the source-only schema editor directly.
|
|
597
|
-
*
|
|
598
|
-
* A separate module from the component so the decision can be asserted
|
|
599
|
-
* without a database and a rendered editor.
|
|
600
|
-
*/
|
|
601
|
-
async function saveRules(schemaEditing, transport, table, rules, options) {
|
|
602
|
-
const patches = await rlsEdit(table, rules.map(asSecurityRule), options.confirmDetach);
|
|
603
|
-
if (patches.length === 0) return;
|
|
604
|
-
if (schemaEditing.available) {
|
|
605
|
-
await schemaEditing.applyTablePatches(table.slug, patches);
|
|
606
|
-
return;
|
|
607
|
-
}
|
|
608
|
-
await postTablePatches({
|
|
609
|
-
apiBase: transport.apiBase,
|
|
610
|
-
patches,
|
|
611
|
-
getAuthToken: transport.getAuthToken
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* A rule the policy editor built — its fields assigned one at a time, so
|
|
616
|
-
* wider than any one variant — as the `SecurityRule` variant its fields make
|
|
617
|
-
* it. Which fields go together is the variants' rule; the editor never sets
|
|
618
|
-
* two that exclude each other ({@link PolicyRule}).
|
|
619
|
-
*/
|
|
620
|
-
function asSecurityRule(rule) {
|
|
621
|
-
const { using, withCheck, ownerField, access, condition, check, redacted, ...rest } = rule;
|
|
622
|
-
const base = rest;
|
|
623
|
-
if (redacted) return {
|
|
624
|
-
...base,
|
|
625
|
-
redacted,
|
|
626
|
-
...access !== void 0 ? { access } : {}
|
|
627
|
-
};
|
|
628
|
-
if (using !== void 0) return {
|
|
629
|
-
...base,
|
|
630
|
-
using,
|
|
631
|
-
...withCheck !== void 0 ? { withCheck } : {}
|
|
632
|
-
};
|
|
633
|
-
if (withCheck !== void 0) return {
|
|
634
|
-
...base,
|
|
635
|
-
withCheck
|
|
636
|
-
};
|
|
637
|
-
if (ownerField !== void 0) return {
|
|
638
|
-
...base,
|
|
639
|
-
ownerField
|
|
640
|
-
};
|
|
641
|
-
if (access !== void 0) {
|
|
642
|
-
if (condition !== void 0) return {
|
|
643
|
-
...base,
|
|
644
|
-
access,
|
|
645
|
-
condition,
|
|
646
|
-
...check !== void 0 ? { check } : {}
|
|
647
|
-
};
|
|
648
|
-
if (check !== void 0) return {
|
|
649
|
-
...base,
|
|
650
|
-
access,
|
|
651
|
-
check
|
|
652
|
-
};
|
|
653
|
-
switch (access) {
|
|
654
|
-
case "public": return {
|
|
655
|
-
...base,
|
|
656
|
-
access: "public"
|
|
657
|
-
};
|
|
658
|
-
case "authenticated": return {
|
|
659
|
-
...base,
|
|
660
|
-
access: "authenticated"
|
|
661
|
-
};
|
|
662
|
-
case "registered": return {
|
|
663
|
-
...base,
|
|
664
|
-
access: "registered"
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
if (condition !== void 0) return {
|
|
669
|
-
...base,
|
|
670
|
-
condition,
|
|
671
|
-
...check !== void 0 ? { check } : {}
|
|
672
|
-
};
|
|
673
|
-
return base;
|
|
674
|
-
}
|
|
675
|
-
/** The person kept `"inherit"`: an answer, matched like the plan dialog's cancellation. */
|
|
676
|
-
var DetachDeclined = class extends Error {
|
|
677
|
-
constructor() {
|
|
678
|
-
super("The table keeps its inherited rules.");
|
|
679
|
-
this.name = "SchemaChangeCancelled";
|
|
680
|
-
}
|
|
681
|
-
};
|
|
682
|
-
/**
|
|
683
|
-
* The operations that make `table` declare `rules`.
|
|
684
|
-
*
|
|
685
|
-
* Exported for the tests: the decision is the whole of what this module adds.
|
|
686
|
-
*/
|
|
687
|
-
async function rlsEdit(table, rules, confirmDetach) {
|
|
688
|
-
const declared = table.rls.posture === "rules" ? table.rls.rules : [];
|
|
689
|
-
if (table.rls.inherited) {
|
|
690
|
-
if (rules.length === 0 || JSON.stringify(rules) === JSON.stringify(declared)) return [];
|
|
691
|
-
if (!await confirmDetach(table.slug)) throw new DetachDeclined();
|
|
692
|
-
return [{
|
|
693
|
-
op: "setRls",
|
|
694
|
-
table: table.slug,
|
|
695
|
-
rls: [rules[0], ...rules.slice(1)]
|
|
696
|
-
}];
|
|
697
|
-
}
|
|
698
|
-
if (rules.length === 0) return declared.length === 0 ? [] : [{
|
|
699
|
-
op: "setRls",
|
|
700
|
-
table: table.slug,
|
|
701
|
-
rls: "admin-only"
|
|
702
|
-
}];
|
|
703
|
-
if (declared.length === 0) return [{
|
|
704
|
-
op: "setRls",
|
|
705
|
-
table: table.slug,
|
|
706
|
-
rls: [rules[0], ...rules.slice(1)]
|
|
707
|
-
}];
|
|
708
|
-
return rulePatches(table.slug, declared, rules);
|
|
709
|
-
}
|
|
710
|
-
/**
|
|
711
|
-
* Was this rejection the person closing the plan dialog, or keeping a table's
|
|
712
|
-
* inherited rules?
|
|
713
|
-
*
|
|
714
|
-
* Either is an answer, not a failure, and a caller that treats every
|
|
715
|
-
* rejection as an error reports someone's own choice back to them in red — as
|
|
716
|
-
* the collection editor once did, with "Error persisting collection: The schema
|
|
717
|
-
* change was not applied."
|
|
718
|
-
*
|
|
719
|
-
* Matched by name rather than `instanceof`: `SchemaChangeCancelled` is declared
|
|
720
|
-
* in `@rebasepro/cms`, which this package cannot import, and two copies of a
|
|
721
|
-
* class in one bundle make `instanceof` silently false anyway.
|
|
722
|
-
*/
|
|
723
|
-
function isCancellation(err) {
|
|
724
|
-
return err instanceof Error && err.name === "SchemaChangeCancelled";
|
|
725
|
-
}
|
|
726
|
-
//#endregion
|
|
727
|
-
//#region src/components/RLSEditor/policyRules.ts
|
|
728
|
-
/** The {@link PolicyRuleForm} of a declared rule. */
|
|
729
|
-
function ruleForm(rule) {
|
|
730
|
-
if (isRedactedSecurityRule(rule)) return "redacted";
|
|
731
|
-
if (rule.using != null || rule.withCheck != null) return "raw";
|
|
732
|
-
if (rule.ownerField != null) return "owner";
|
|
733
|
-
if (rule.access !== void 0) return rule.condition != null || rule.check != null ? "conditional_access" : "access";
|
|
734
|
-
if (rule.condition != null || rule.check != null) return "structured";
|
|
735
|
-
return "roles_only";
|
|
736
|
-
}
|
|
737
|
-
/**
|
|
738
|
-
* Write an edit of one policy back to the declared rule it compiles from.
|
|
739
|
-
*
|
|
740
|
-
* The rule is the one the server says the policy was compiled from (the
|
|
741
|
-
* served policy's `rule` index, carried on the listed row) — the server is the
|
|
742
|
-
* one compiler, so the editor never guesses it from names. A policy with no
|
|
743
|
-
* rule is Rebase's own (`generated`: the admin baseline, tenancy, a junction's
|
|
744
|
-
* derived policies) or exists only in the database.
|
|
745
|
-
*
|
|
746
|
-
* A rule over several operations is refused rather than split: taking one
|
|
747
|
-
* operation out renames every policy the rule compiles to.
|
|
748
|
-
*
|
|
749
|
-
* @param declared The table's declared rules (`rls.rules`), as written.
|
|
750
|
-
* @param original The listed policy the editor was opened with.
|
|
751
|
-
*/
|
|
752
|
-
function applyPolicyEdit(declared, original, edited) {
|
|
753
|
-
const index = original.rule;
|
|
754
|
-
if (index === void 0 || declared[index] === void 0) return {
|
|
755
|
-
ok: false,
|
|
756
|
-
reason: original.generated ? "generated" : "not_declared"
|
|
757
|
-
};
|
|
758
|
-
const rule = declared[index];
|
|
759
|
-
if (ruleForm(rule) === "redacted") return {
|
|
760
|
-
ok: false,
|
|
761
|
-
reason: "redacted"
|
|
762
|
-
};
|
|
763
|
-
if (getPolicyOperations(rule).length > 1) return {
|
|
764
|
-
ok: false,
|
|
765
|
-
reason: "several_operations"
|
|
766
|
-
};
|
|
767
|
-
return {
|
|
768
|
-
ok: true,
|
|
769
|
-
rules: declared.map((r, i) => i === index ? editedRule(r, original, edited) : r)
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
/**
|
|
773
|
-
* The rule with what the editor changed, and nothing else.
|
|
774
|
-
*
|
|
775
|
-
* The editor shows a rule as a policy — name, command, mode, `TO` list and raw
|
|
776
|
-
* USING / WITH CHECK — and an `ownerField` or `access` rule has no raw clause
|
|
777
|
-
* to show. So a field is only written when it differs from what the editor was
|
|
778
|
-
* opened with: renaming an `access: "public"` rule keeps it public, and an
|
|
779
|
-
* unnamed rule stays unnamed unless the name was changed. A condition typed in
|
|
780
|
-
* replaces the rule's condition whole — the forms are exclusive.
|
|
781
|
-
*/
|
|
782
|
-
function editedRule(rule, original, edited) {
|
|
783
|
-
const next = policyToSecurityRule(edited);
|
|
784
|
-
const result = { ...rule };
|
|
785
|
-
if ((edited.policyname ?? "") !== original.policyname) if (next.name) result.name = next.name;
|
|
786
|
-
else delete result.name;
|
|
787
|
-
if (edited.cmd !== original.cmd) {
|
|
788
|
-
delete result.operations;
|
|
789
|
-
result.operation = next.operation;
|
|
790
|
-
}
|
|
791
|
-
if (edited.permissive !== original.permissive) result.mode = next.mode;
|
|
792
|
-
if (!sameRoles$1(edited.roles, original.roles)) if (next.pgRoles) result.pgRoles = next.pgRoles;
|
|
793
|
-
else delete result.pgRoles;
|
|
794
|
-
if ((edited.qual || null) !== (original.qual || null) || (edited.with_check || null) !== (original.with_check || null)) {
|
|
795
|
-
delete result.ownerField;
|
|
796
|
-
delete result.access;
|
|
797
|
-
delete result.condition;
|
|
798
|
-
delete result.check;
|
|
799
|
-
delete result.using;
|
|
800
|
-
delete result.withCheck;
|
|
801
|
-
if (next.using) result.using = next.using;
|
|
802
|
-
if (next.withCheck) result.withCheck = next.withCheck;
|
|
803
|
-
}
|
|
804
|
-
return result;
|
|
805
|
-
}
|
|
806
|
-
function sameRoles$1(a, b) {
|
|
807
|
-
const left = [...a ?? []].sort();
|
|
808
|
-
const right = [...b ?? []].sort();
|
|
809
|
-
return left.length === right.length && left.every((role, i) => role === right[i]);
|
|
810
|
-
}
|
|
811
|
-
//#endregion
|
|
812
|
-
//#region src/components/RLSEditor/policyListing.ts
|
|
813
|
-
/**
|
|
814
|
-
* The roles of a `pg_policies` row, from its `roles` column.
|
|
815
|
-
*
|
|
816
|
-
* A driver hands a `name[]` back as an array or as Postgres's text for one:
|
|
817
|
-
* `{public}`, `{anon,authenticated}`, and with an element quoted — a `"` or
|
|
818
|
-
* `\` in it escaped by a backslash — when it holds a comma, a brace, a quote,
|
|
819
|
-
* a backslash or a space: `{"my role",anon}`. Split on commas, that last one
|
|
820
|
-
* reads as the role `"my role"`, quotes and all: the policy shows drift that
|
|
821
|
-
* is not there, and an edit of it names a role that does not exist.
|
|
822
|
-
*/
|
|
823
|
-
function readPolicyRoles(value) {
|
|
824
|
-
if (Array.isArray(value)) return value.filter((role) => typeof role === "string");
|
|
825
|
-
if (typeof value !== "string") return [];
|
|
826
|
-
const body = value.trim().replace(/^\{/, "").replace(/\}$/, "");
|
|
827
|
-
const roles = [];
|
|
828
|
-
let i = 0;
|
|
829
|
-
while (i < body.length) {
|
|
830
|
-
if (body[i] === "\"") {
|
|
831
|
-
let role = "";
|
|
832
|
-
i++;
|
|
833
|
-
while (i < body.length && body[i] !== "\"") {
|
|
834
|
-
if (body[i] === "\\") i++;
|
|
835
|
-
role += body[i] ?? "";
|
|
836
|
-
i++;
|
|
837
|
-
}
|
|
838
|
-
roles.push(role);
|
|
839
|
-
i++;
|
|
840
|
-
} else {
|
|
841
|
-
const comma = body.indexOf(",", i);
|
|
842
|
-
const end = comma === -1 ? body.length : comma;
|
|
843
|
-
const role = body.slice(i, end).trim();
|
|
844
|
-
if (role) roles.push(role);
|
|
845
|
-
i = end;
|
|
846
|
-
}
|
|
847
|
-
while (i < body.length && body[i] !== ",") i++;
|
|
848
|
-
i++;
|
|
849
|
-
}
|
|
850
|
-
return roles;
|
|
851
|
-
}
|
|
852
|
-
var COMMANDS$1 = {
|
|
853
|
-
select: "SELECT",
|
|
854
|
-
insert: "INSERT",
|
|
855
|
-
update: "UPDATE",
|
|
856
|
-
delete: "DELETE",
|
|
857
|
-
all: "ALL"
|
|
858
|
-
};
|
|
859
|
-
function commandOf(operation) {
|
|
860
|
-
return operation in COMMANDS$1 ? COMMANDS$1[operation] : "ALL";
|
|
861
|
-
}
|
|
862
|
-
/** A policy the server compiled, in the shape `pg_policies` describes one. */
|
|
863
|
-
function servedAsPostgresPolicy(served, tableName) {
|
|
864
|
-
return {
|
|
865
|
-
policyname: served.name,
|
|
866
|
-
tablename: tableName,
|
|
867
|
-
permissive: served.mode === "restrictive" ? "RESTRICTIVE" : "PERMISSIVE",
|
|
868
|
-
cmd: commandOf(served.operation),
|
|
869
|
-
roles: [...served.roles],
|
|
870
|
-
qual: served.using,
|
|
871
|
-
with_check: served.withCheck
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
/**
|
|
875
|
-
* The rule's own clauses, for a declared rule the server compiled no policy
|
|
876
|
-
* from — an `existsIn` naming a table the backend does not hold, say. Only
|
|
877
|
-
* ever a `code_only` row's content: nothing is compared against it.
|
|
878
|
-
*/
|
|
879
|
-
function uncompiledPolicy(rule, operation, name, tableName) {
|
|
880
|
-
return {
|
|
881
|
-
policyname: name,
|
|
882
|
-
tablename: tableName,
|
|
883
|
-
permissive: rule.mode === "restrictive" ? "RESTRICTIVE" : "PERMISSIVE",
|
|
884
|
-
cmd: COMMANDS$1[operation],
|
|
885
|
-
roles: [...rule.pgRoles ?? ["public"]],
|
|
886
|
-
qual: rule.using || null,
|
|
887
|
-
with_check: rule.withCheck || null
|
|
888
|
-
};
|
|
889
|
-
}
|
|
890
|
-
function sameRoles(a, b) {
|
|
891
|
-
const left = [...a].sort();
|
|
892
|
-
const right = [...b].sort();
|
|
893
|
-
return left.length === right.length && left.every((role, i) => role === right[i]);
|
|
894
|
-
}
|
|
895
|
-
/**
|
|
896
|
-
* Where a live policy differs from the one the code compiles to.
|
|
897
|
-
*
|
|
898
|
-
* The same comparison `rebase doctor` makes: the `TO` list, the command, the
|
|
899
|
-
* mode, and whether each clause is there at all. Never the clause text —
|
|
900
|
-
* Postgres rewrites an expression when it stores it, so the text of a policy
|
|
901
|
-
* that matches its declaration exactly still differs from the declaration's.
|
|
902
|
-
* A clause that is missing is not a rewrite, though: a `USING` that is gone
|
|
903
|
-
* changes who the policy admits.
|
|
904
|
-
*/
|
|
905
|
-
function policyDrift(declared, live) {
|
|
906
|
-
const drift = [];
|
|
907
|
-
if (!sameRoles(declared.roles, live.roles)) drift.push("roles");
|
|
908
|
-
if (declared.cmd !== live.cmd) drift.push("command");
|
|
909
|
-
if (declared.permissive !== live.permissive) drift.push("mode");
|
|
910
|
-
if (declared.qual != null !== (live.qual != null)) drift.push("USING");
|
|
911
|
-
if (declared.with_check != null !== (live.with_check != null)) drift.push("WITH CHECK");
|
|
912
|
-
return drift;
|
|
913
|
-
}
|
|
914
|
-
/** The {@link DeclaredPolicies} of a served table, when the server included its compiled policies. */
|
|
915
|
-
function declaredPoliciesOf(rls) {
|
|
916
|
-
return rls.policies ? {
|
|
917
|
-
rules: rls.rules,
|
|
918
|
-
policies: rls.policies
|
|
919
|
-
} : void 0;
|
|
920
|
-
}
|
|
921
|
-
/**
|
|
922
|
-
* The policies of one table: every policy the database has, as the database
|
|
923
|
-
* has it, and every policy the server compiles for the table that it does not.
|
|
924
|
-
*
|
|
925
|
-
* The server is the one compiler: what it serves in `rls.policies` (and
|
|
926
|
-
* `rls.junctions`) is exactly what `db push` and every server start write.
|
|
927
|
-
* This only compares it with `pg_policies`. A policy in both keeps the
|
|
928
|
-
* database's fields — this list is what Postgres enforces — and carries the
|
|
929
|
-
* declaration beside them, with where the two differ.
|
|
930
|
-
*
|
|
931
|
-
* @param live The table's `pg_policies` rows.
|
|
932
|
-
* @param declared What the server serves for the table, if anything.
|
|
933
|
-
*/
|
|
934
|
-
function listPolicies(live, declared, tableName) {
|
|
935
|
-
const listed = /* @__PURE__ */ new Map();
|
|
936
|
-
for (const policy of live) listed.set(policy.policyname, {
|
|
937
|
-
...policy,
|
|
938
|
-
status: "live"
|
|
939
|
-
});
|
|
940
|
-
if (!declared) return [...listed.values()];
|
|
941
|
-
const livePolicies = new Map(live.map((policy) => [policy.policyname, policy]));
|
|
942
|
-
const compiledRules = /* @__PURE__ */ new Set();
|
|
943
|
-
for (const served of declared.policies) {
|
|
944
|
-
if (served.rule !== void 0) compiledRules.add(served.rule);
|
|
945
|
-
const existing = livePolicies.get(served.name);
|
|
946
|
-
if (served.roles.includes(REBASE_ADMIN_REQUEST_ROLE) && !existing) continue;
|
|
947
|
-
const compiled = servedAsPostgresPolicy(served, tableName);
|
|
948
|
-
const declaredPolicy = existing !== void 0 && sameRoles(compiled.roles, [REBASE_ADMIN_ROLE]) && sameRoles(existing.roles, ["public"]) ? {
|
|
949
|
-
...compiled,
|
|
950
|
-
roles: ["public"]
|
|
951
|
-
} : compiled;
|
|
952
|
-
const rule = served.rule !== void 0 ? { rule: served.rule } : {};
|
|
953
|
-
if (existing) listed.set(served.name, {
|
|
954
|
-
...existing,
|
|
955
|
-
status: "both",
|
|
956
|
-
declared: declaredPolicy,
|
|
957
|
-
drift: policyDrift(declaredPolicy, existing),
|
|
958
|
-
generated: served.injected,
|
|
959
|
-
...rule
|
|
960
|
-
});
|
|
961
|
-
else listed.set(served.name, {
|
|
962
|
-
...declaredPolicy,
|
|
963
|
-
status: "code_only",
|
|
964
|
-
generated: served.injected,
|
|
965
|
-
...rule
|
|
966
|
-
});
|
|
967
|
-
}
|
|
968
|
-
declared.rules.forEach((rule, index) => {
|
|
969
|
-
if (compiledRules.has(index) || isRedactedSecurityRule(rule)) return;
|
|
970
|
-
const operations = getPolicyOperations(rule);
|
|
971
|
-
getPolicyNamesForRule(rule, tableName).forEach((name, position) => {
|
|
972
|
-
const existing = listed.get(name);
|
|
973
|
-
if (existing) {
|
|
974
|
-
if (existing.status === "live") listed.set(name, {
|
|
975
|
-
...existing,
|
|
976
|
-
status: "both",
|
|
977
|
-
generated: false,
|
|
978
|
-
rule: index
|
|
979
|
-
});
|
|
980
|
-
return;
|
|
981
|
-
}
|
|
982
|
-
listed.set(name, {
|
|
983
|
-
...uncompiledPolicy(rule, operations[position] ?? "all", name, tableName),
|
|
984
|
-
status: "code_only",
|
|
985
|
-
generated: false,
|
|
986
|
-
rule: index
|
|
987
|
-
});
|
|
988
|
-
});
|
|
989
|
-
});
|
|
990
|
-
return [...listed.values()];
|
|
991
|
-
}
|
|
992
|
-
//#endregion
|
|
993
|
-
//#region src/components/RLSEditor/DirectRlsPoliciesPanel.tsx
|
|
994
|
-
var COMMANDS = [
|
|
995
|
-
"ALL",
|
|
996
|
-
"SELECT",
|
|
997
|
-
"INSERT",
|
|
998
|
-
"UPDATE",
|
|
999
|
-
"DELETE"
|
|
1000
|
-
];
|
|
1001
|
-
var POLICY_TEMPLATES = [
|
|
1002
|
-
{
|
|
1003
|
-
labelKey: "studio_rls_direct_tpl_public_read",
|
|
1004
|
-
name: "public_read",
|
|
1005
|
-
command: "SELECT",
|
|
1006
|
-
using: "true",
|
|
1007
|
-
withCheck: ""
|
|
1008
|
-
},
|
|
1009
|
-
{
|
|
1010
|
-
labelKey: "studio_rls_direct_tpl_authenticated",
|
|
1011
|
-
name: "authenticated_all",
|
|
1012
|
-
command: "ALL",
|
|
1013
|
-
using: "rebase.uid() IS NOT NULL",
|
|
1014
|
-
withCheck: "rebase.uid() IS NOT NULL"
|
|
1015
|
-
},
|
|
1016
|
-
{
|
|
1017
|
-
labelKey: "studio_rls_direct_tpl_owner",
|
|
1018
|
-
name: "owner_all",
|
|
1019
|
-
command: "ALL",
|
|
1020
|
-
using: "user_id = rebase.uid()",
|
|
1021
|
-
withCheck: "user_id = rebase.uid()"
|
|
1022
|
-
},
|
|
1023
|
-
{
|
|
1024
|
-
labelKey: "studio_rls_direct_tpl_admin",
|
|
1025
|
-
name: "admin_all",
|
|
1026
|
-
command: "ALL",
|
|
1027
|
-
using: "'admin' = ANY(string_to_array(rebase.roles(), ','))",
|
|
1028
|
-
withCheck: "'admin' = ANY(string_to_array(rebase.roles(), ','))"
|
|
1029
|
-
}
|
|
1030
|
-
];
|
|
1031
|
-
function parsePolicy(raw) {
|
|
1032
|
-
if (!isRecord(raw) || typeof raw.name !== "string") return null;
|
|
1033
|
-
return {
|
|
1034
|
-
name: raw.name,
|
|
1035
|
-
command: asString(raw.operation ?? raw.command, "ALL"),
|
|
1036
|
-
roles: asStringArray(raw.roles),
|
|
1037
|
-
using: asNullableString(raw.using),
|
|
1038
|
-
withCheck: asNullableString(raw.withCheck)
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1041
|
-
function parseTable(raw) {
|
|
1042
|
-
if (!isRecord(raw) || typeof raw.name !== "string") return null;
|
|
1043
|
-
const policies = Array.isArray(raw.policies) ? raw.policies.map(parsePolicy).filter((p) => p !== null) : [];
|
|
1044
|
-
return {
|
|
1045
|
-
schema: asString(raw.schema, "public"),
|
|
1046
|
-
name: raw.name,
|
|
1047
|
-
rlsEnabled: asBoolean(raw.rlsEnabled, false),
|
|
1048
|
-
policies
|
|
1049
|
-
};
|
|
1050
|
-
}
|
|
1051
|
-
/**
|
|
1052
|
-
* Direct PostgreSQL RLS policy manager over `/api/admin/db/tables`.
|
|
1053
|
-
* Works with zero `backend/schema` source files — every change applies live
|
|
1054
|
-
* to Postgres and reloads the data API immediately.
|
|
1055
|
-
*/
|
|
1056
|
-
function DirectRlsPoliciesPanel() {
|
|
1057
|
-
const { requestJson } = useAdminFetch();
|
|
1058
|
-
const snackbar = useSnackbarController();
|
|
1059
|
-
const { t } = useTranslation();
|
|
1060
|
-
const [tables, setTables] = useState([]);
|
|
1061
|
-
const [loading, setLoading] = useState(true);
|
|
1062
|
-
const [error, setError] = useState(null);
|
|
1063
|
-
const [selectedName, setSelectedName] = useState(null);
|
|
1064
|
-
const [dialogOpen, setDialogOpen] = useState(false);
|
|
1065
|
-
const [policyName, setPolicyName] = useState("");
|
|
1066
|
-
const [command, setCommand] = useState("ALL");
|
|
1067
|
-
const [usingExpr, setUsingExpr] = useState("rebase.uid() IS NOT NULL");
|
|
1068
|
-
const [withCheckExpr, setWithCheckExpr] = useState("");
|
|
1069
|
-
const [saving, setSaving] = useState(false);
|
|
1070
|
-
const load = useCallback(async () => {
|
|
1071
|
-
setLoading(true);
|
|
1072
|
-
setError(null);
|
|
1073
|
-
try {
|
|
1074
|
-
const raw = await requestJson("/admin/db/tables");
|
|
1075
|
-
const list = isRecord(raw) && Array.isArray(raw.tables) ? raw.tables.map(parseTable).filter((t) => t !== null) : [];
|
|
1076
|
-
setTables(list);
|
|
1077
|
-
setSelectedName((prev) => prev && list.some((t) => t.name === prev) ? prev : list[0]?.name ?? null);
|
|
1078
|
-
} catch (err) {
|
|
1079
|
-
setError(err instanceof Error ? err.message : t("studio_rls_direct_load_failed"));
|
|
1080
|
-
} finally {
|
|
1081
|
-
setLoading(false);
|
|
1082
|
-
}
|
|
1083
|
-
}, [requestJson, t]);
|
|
1084
|
-
useEffect(() => {
|
|
1085
|
-
load();
|
|
1086
|
-
}, [load]);
|
|
1087
|
-
const selected = useMemo(() => tables.find((t) => t.name === selectedName) ?? null, [tables, selectedName]);
|
|
1088
|
-
const handleToggleRls = async (enabled) => {
|
|
1089
|
-
if (!selected) return;
|
|
1090
|
-
try {
|
|
1091
|
-
await requestJson(`/admin/db/tables/${encodeURIComponent(selected.name)}`, {
|
|
1092
|
-
method: "PATCH",
|
|
1093
|
-
body: { rlsEnabled: enabled }
|
|
1094
|
-
});
|
|
1095
|
-
snackbar.open({
|
|
1096
|
-
type: "success",
|
|
1097
|
-
message: t(enabled ? "studio_tables_rls_enabled_on" : "studio_tables_rls_disabled_on", { name: selected.name })
|
|
1098
|
-
});
|
|
1099
|
-
await load();
|
|
1100
|
-
} catch (err) {
|
|
1101
|
-
snackbar.open({
|
|
1102
|
-
type: "error",
|
|
1103
|
-
message: err instanceof Error ? err.message : t("studio_rls_direct_update_failed")
|
|
1104
|
-
});
|
|
1105
|
-
}
|
|
1106
|
-
};
|
|
1107
|
-
const handleCreatePolicy = async () => {
|
|
1108
|
-
if (!selected || !policyName.trim()) return;
|
|
1109
|
-
setSaving(true);
|
|
1110
|
-
try {
|
|
1111
|
-
await requestJson(`/admin/db/tables/${encodeURIComponent(selected.name)}/policies`, {
|
|
1112
|
-
method: "POST",
|
|
1113
|
-
body: {
|
|
1114
|
-
name: policyName.trim(),
|
|
1115
|
-
operation: command,
|
|
1116
|
-
...usingExpr.trim() ? { using: usingExpr.trim() } : {},
|
|
1117
|
-
...withCheckExpr.trim() ? { withCheck: withCheckExpr.trim() } : {}
|
|
1118
|
-
}
|
|
1119
|
-
});
|
|
1120
|
-
snackbar.open({
|
|
1121
|
-
type: "success",
|
|
1122
|
-
message: t("studio_rls_direct_policy_created", { name: policyName.trim() })
|
|
1123
|
-
});
|
|
1124
|
-
setDialogOpen(false);
|
|
1125
|
-
setPolicyName("");
|
|
1126
|
-
await load();
|
|
1127
|
-
} catch (err) {
|
|
1128
|
-
snackbar.open({
|
|
1129
|
-
type: "error",
|
|
1130
|
-
message: err instanceof Error ? err.message : t("studio_rls_direct_policy_create_failed")
|
|
1131
|
-
});
|
|
1132
|
-
} finally {
|
|
1133
|
-
setSaving(false);
|
|
1134
|
-
}
|
|
1135
|
-
};
|
|
1136
|
-
const handleDropPolicy = async (name) => {
|
|
1137
|
-
if (!selected) return;
|
|
1138
|
-
try {
|
|
1139
|
-
await requestJson(`/admin/db/tables/${encodeURIComponent(selected.name)}/policies/${encodeURIComponent(name)}`, { method: "DELETE" });
|
|
1140
|
-
snackbar.open({
|
|
1141
|
-
type: "success",
|
|
1142
|
-
message: t("studio_rls_direct_policy_dropped", { name })
|
|
1143
|
-
});
|
|
1144
|
-
await load();
|
|
1145
|
-
} catch (err) {
|
|
1146
|
-
snackbar.open({
|
|
1147
|
-
type: "error",
|
|
1148
|
-
message: err instanceof Error ? err.message : t("studio_rls_direct_policy_drop_failed")
|
|
1149
|
-
});
|
|
1150
|
-
}
|
|
1151
|
-
};
|
|
1152
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1153
|
-
className: "flex h-full w-full overflow-hidden bg-surface-card",
|
|
1154
|
-
children: [
|
|
1155
|
-
/* @__PURE__ */ jsxs("aside", {
|
|
1156
|
-
className: cls("w-64 shrink-0 border-r bg-surface-card flex flex-col", defaultBorderMixin),
|
|
1157
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
1158
|
-
className: cls("h-[42px] px-3 border-b bg-surface-sheet flex items-center justify-between shrink-0", defaultBorderMixin),
|
|
1159
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1160
|
-
variant: "caption",
|
|
1161
|
-
className: "font-semibold uppercase tracking-wider text-text-disabled dark:text-text-disabled-dark",
|
|
1162
|
-
children: t("studio_rls_direct_tables_heading")
|
|
1163
|
-
}), /* @__PURE__ */ jsx(Tooltip, {
|
|
1164
|
-
title: t("refresh"),
|
|
1165
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1166
|
-
size: "small",
|
|
1167
|
-
"aria-label": t("studio_rls_direct_refresh_aria"),
|
|
1168
|
-
onClick: () => void load(),
|
|
1169
|
-
children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
|
|
1170
|
-
})
|
|
1171
|
-
})]
|
|
1172
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
1173
|
-
className: "flex-1 overflow-y-auto p-2 flex flex-col gap-1",
|
|
1174
|
-
children: loading ? /* @__PURE__ */ jsx("div", {
|
|
1175
|
-
className: "flex justify-center py-8",
|
|
1176
|
-
children: /* @__PURE__ */ jsx(CircularProgress, { size: "small" })
|
|
1177
|
-
}) : tables.map((table) => /* @__PURE__ */ jsxs("button", {
|
|
1178
|
-
type: "button",
|
|
1179
|
-
onClick: () => setSelectedName(table.name),
|
|
1180
|
-
className: cls("w-full text-left px-2.5 h-8 rounded-lg flex items-center justify-between gap-2 text-[13px] transition-colors cursor-pointer", table.name === selectedName ? "bg-surface-active text-text-primary dark:text-text-primary-dark font-medium" : "text-text-secondary dark:text-text-secondary-dark hover:bg-surface-hover hover:text-text-primary dark:hover:text-text-primary-dark"),
|
|
1181
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
1182
|
-
className: "font-mono truncate",
|
|
1183
|
-
children: table.name
|
|
1184
|
-
}), /* @__PURE__ */ jsx(Chip, {
|
|
1185
|
-
size: "small",
|
|
1186
|
-
colorScheme: table.rlsEnabled ? "greenLight" : "grayLight",
|
|
1187
|
-
children: table.policies.length
|
|
1188
|
-
})]
|
|
1189
|
-
}, table.name))
|
|
1190
|
-
})]
|
|
1191
|
-
}),
|
|
1192
|
-
/* @__PURE__ */ jsxs("main", {
|
|
1193
|
-
className: "flex-1 flex flex-col min-w-0 h-full overflow-hidden bg-surface-sheet",
|
|
1194
|
-
children: [error && /* @__PURE__ */ jsx("div", {
|
|
1195
|
-
className: "p-5 pb-0",
|
|
1196
|
-
children: /* @__PURE__ */ jsx(Alert, {
|
|
1197
|
-
color: "error",
|
|
1198
|
-
children: error
|
|
1199
|
-
})
|
|
1200
|
-
}), !selected ? /* @__PURE__ */ jsx("div", {
|
|
1201
|
-
className: "p-5",
|
|
1202
|
-
children: /* @__PURE__ */ jsx(Card, {
|
|
1203
|
-
className: "p-8 text-center",
|
|
1204
|
-
children: /* @__PURE__ */ jsx(Typography, {
|
|
1205
|
-
variant: "body2",
|
|
1206
|
-
color: "secondary",
|
|
1207
|
-
children: t("studio_rls_direct_select_table")
|
|
1208
|
-
})
|
|
1209
|
-
})
|
|
1210
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
1211
|
-
className: cls("h-[42px] px-4 border-b bg-surface-sheet flex items-center justify-between gap-4 shrink-0", defaultBorderMixin),
|
|
1212
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
1213
|
-
className: "flex items-center gap-2.5 min-w-0",
|
|
1214
|
-
children: [
|
|
1215
|
-
/* @__PURE__ */ jsx(ShieldIcon, {
|
|
1216
|
-
size: iconSize.small,
|
|
1217
|
-
className: "text-text-secondary shrink-0"
|
|
1218
|
-
}),
|
|
1219
|
-
/* @__PURE__ */ jsxs(Typography, {
|
|
1220
|
-
variant: "subtitle2",
|
|
1221
|
-
className: "font-mono truncate",
|
|
1222
|
-
children: [
|
|
1223
|
-
selected.schema,
|
|
1224
|
-
".",
|
|
1225
|
-
selected.name
|
|
1226
|
-
]
|
|
1227
|
-
}),
|
|
1228
|
-
/* @__PURE__ */ jsx(Chip, {
|
|
1229
|
-
size: "smallest",
|
|
1230
|
-
colorScheme: selected.rlsEnabled ? "greenLight" : "orangeLight",
|
|
1231
|
-
children: selected.rlsEnabled ? t("studio_rls_enabled") : t("studio_rls_disabled")
|
|
1232
|
-
})
|
|
1233
|
-
]
|
|
1234
|
-
}), /* @__PURE__ */ jsxs(Button, {
|
|
1235
|
-
size: "small",
|
|
1236
|
-
color: "primary",
|
|
1237
|
-
variant: "filled",
|
|
1238
|
-
onClick: () => setDialogOpen(true),
|
|
1239
|
-
children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_new_policy")]
|
|
1240
|
-
})]
|
|
1241
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
1242
|
-
className: "flex-1 overflow-auto p-5 flex flex-col gap-4",
|
|
1243
|
-
children: [/* @__PURE__ */ jsx(Card, {
|
|
1244
|
-
className: "p-4",
|
|
1245
|
-
children: /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
|
|
1246
|
-
label: t("studio_rls_direct_enabled_label"),
|
|
1247
|
-
value: selected.rlsEnabled,
|
|
1248
|
-
onValueChange: (v) => void handleToggleRls(v)
|
|
1249
|
-
})
|
|
1250
|
-
}), selected.policies.length === 0 ? /* @__PURE__ */ jsxs(Card, {
|
|
1251
|
-
className: "p-8 text-center flex flex-col items-center gap-3",
|
|
1252
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1253
|
-
variant: "body2",
|
|
1254
|
-
color: "secondary",
|
|
1255
|
-
children: t("studio_rls_direct_no_policies", { name: selected.name })
|
|
1256
|
-
}), /* @__PURE__ */ jsxs(Button, {
|
|
1257
|
-
size: "small",
|
|
1258
|
-
color: "primary",
|
|
1259
|
-
variant: "filled",
|
|
1260
|
-
onClick: () => setDialogOpen(true),
|
|
1261
|
-
children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small }), t("studio_rls_direct_add_first_policy")]
|
|
1262
|
-
})]
|
|
1263
|
-
}) : /* @__PURE__ */ jsx("div", {
|
|
1264
|
-
className: cls("overflow-x-auto rounded-lg border", defaultBorderMixin),
|
|
1265
|
-
children: /* @__PURE__ */ jsxs(Table, {
|
|
1266
|
-
className: "w-full",
|
|
1267
|
-
children: [/* @__PURE__ */ jsxs(TableHeader, { children: [
|
|
1268
|
-
/* @__PURE__ */ jsx(TableCell, {
|
|
1269
|
-
header: true,
|
|
1270
|
-
children: t("studio_policy_name")
|
|
1271
|
-
}),
|
|
1272
|
-
/* @__PURE__ */ jsx(TableCell, {
|
|
1273
|
-
header: true,
|
|
1274
|
-
children: t("studio_rls_direct_command")
|
|
1275
|
-
}),
|
|
1276
|
-
/* @__PURE__ */ jsx(TableCell, {
|
|
1277
|
-
header: true,
|
|
1278
|
-
children: "USING"
|
|
1279
|
-
}),
|
|
1280
|
-
/* @__PURE__ */ jsx(TableCell, {
|
|
1281
|
-
header: true,
|
|
1282
|
-
children: "WITH CHECK"
|
|
1283
|
-
}),
|
|
1284
|
-
/* @__PURE__ */ jsx(TableCell, {
|
|
1285
|
-
header: true,
|
|
1286
|
-
className: "text-right",
|
|
1287
|
-
children: t("actions")
|
|
1288
|
-
})
|
|
1289
|
-
] }), /* @__PURE__ */ jsx(TableBody, { children: selected.policies.map((p) => /* @__PURE__ */ jsxs(TableRow, { children: [
|
|
1290
|
-
/* @__PURE__ */ jsx(TableCell, {
|
|
1291
|
-
className: "font-mono text-sm font-medium",
|
|
1292
|
-
children: p.name
|
|
1293
|
-
}),
|
|
1294
|
-
/* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Chip, {
|
|
1295
|
-
size: "small",
|
|
1296
|
-
colorScheme: "blueLight",
|
|
1297
|
-
children: p.command
|
|
1298
|
-
}) }),
|
|
1299
|
-
/* @__PURE__ */ jsx(TableCell, {
|
|
1300
|
-
className: "font-mono text-xs text-text-secondary",
|
|
1301
|
-
children: p.using ?? "—"
|
|
1302
|
-
}),
|
|
1303
|
-
/* @__PURE__ */ jsx(TableCell, {
|
|
1304
|
-
className: "font-mono text-xs text-text-secondary",
|
|
1305
|
-
children: p.withCheck ?? "—"
|
|
1306
|
-
}),
|
|
1307
|
-
/* @__PURE__ */ jsx(TableCell, {
|
|
1308
|
-
className: "text-right",
|
|
1309
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1310
|
-
size: "small",
|
|
1311
|
-
"aria-label": t("studio_rls_direct_drop_policy_aria", { name: p.name }),
|
|
1312
|
-
onClick: () => void handleDropPolicy(p.name),
|
|
1313
|
-
children: /* @__PURE__ */ jsx(Trash2Icon, {
|
|
1314
|
-
size: iconSize.small,
|
|
1315
|
-
className: "text-red-500"
|
|
1316
|
-
})
|
|
1317
|
-
})
|
|
1318
|
-
})
|
|
1319
|
-
] }, p.name)) })]
|
|
1320
|
-
})
|
|
1321
|
-
})]
|
|
1322
|
-
})] })]
|
|
1323
|
-
}),
|
|
1324
|
-
/* @__PURE__ */ jsxs(Dialog, {
|
|
1325
|
-
open: dialogOpen,
|
|
1326
|
-
onOpenChange: setDialogOpen,
|
|
1327
|
-
maxWidth: "md",
|
|
1328
|
-
fullWidth: true,
|
|
1329
|
-
children: [
|
|
1330
|
-
/* @__PURE__ */ jsx(DialogTitle, { children: t("studio_rls_direct_new_policy_title", { name: selected?.name ?? "" }) }),
|
|
1331
|
-
/* @__PURE__ */ jsxs(DialogContent, {
|
|
1332
|
-
className: "flex flex-col gap-3",
|
|
1333
|
-
children: [
|
|
1334
|
-
/* @__PURE__ */ jsx("div", {
|
|
1335
|
-
className: "flex items-center gap-1.5 flex-wrap",
|
|
1336
|
-
children: POLICY_TEMPLATES.map((tpl) => /* @__PURE__ */ jsx(Chip, {
|
|
1337
|
-
size: "small",
|
|
1338
|
-
colorScheme: "grayLight",
|
|
1339
|
-
onClick: () => {
|
|
1340
|
-
setPolicyName(tpl.name);
|
|
1341
|
-
setCommand(tpl.command);
|
|
1342
|
-
setUsingExpr(tpl.using);
|
|
1343
|
-
setWithCheckExpr(tpl.withCheck);
|
|
1344
|
-
},
|
|
1345
|
-
children: t(tpl.labelKey)
|
|
1346
|
-
}, tpl.name))
|
|
1347
|
-
}),
|
|
1348
|
-
/* @__PURE__ */ jsx(TextField, {
|
|
1349
|
-
label: t("studio_policy_name"),
|
|
1350
|
-
value: policyName,
|
|
1351
|
-
onChange: (e) => setPolicyName(e.target.value),
|
|
1352
|
-
placeholder: "owner_all"
|
|
1353
|
-
}),
|
|
1354
|
-
/* @__PURE__ */ jsx(Select, {
|
|
1355
|
-
label: t("studio_rls_direct_command"),
|
|
1356
|
-
value: command,
|
|
1357
|
-
onValueChange: (v) => setCommand(String(v)),
|
|
1358
|
-
children: COMMANDS.map((cmd) => /* @__PURE__ */ jsx(SelectItem, {
|
|
1359
|
-
value: cmd,
|
|
1360
|
-
children: cmd
|
|
1361
|
-
}, cmd))
|
|
1362
|
-
}),
|
|
1363
|
-
/* @__PURE__ */ jsx(TextField, {
|
|
1364
|
-
label: t("studio_policy_using_expr"),
|
|
1365
|
-
value: usingExpr,
|
|
1366
|
-
onChange: (e) => setUsingExpr(e.target.value),
|
|
1367
|
-
placeholder: "user_id = rebase.uid()"
|
|
1368
|
-
}),
|
|
1369
|
-
/* @__PURE__ */ jsx(TextField, {
|
|
1370
|
-
label: t("studio_rls_direct_with_check_label"),
|
|
1371
|
-
value: withCheckExpr,
|
|
1372
|
-
onChange: (e) => setWithCheckExpr(e.target.value),
|
|
1373
|
-
placeholder: "user_id = rebase.uid()"
|
|
1374
|
-
})
|
|
1375
|
-
]
|
|
1376
|
-
}),
|
|
1377
|
-
/* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
|
|
1378
|
-
variant: "text",
|
|
1379
|
-
onClick: () => setDialogOpen(false),
|
|
1380
|
-
children: t("cancel")
|
|
1381
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
1382
|
-
variant: "filled",
|
|
1383
|
-
disabled: saving || !policyName.trim(),
|
|
1384
|
-
onClick: () => void handleCreatePolicy(),
|
|
1385
|
-
children: saving ? t("saving") : t("studio_rls_create_policy")
|
|
1386
|
-
})] })
|
|
1387
|
-
]
|
|
1388
|
-
})
|
|
1389
|
-
]
|
|
1390
|
-
});
|
|
1391
|
-
}
|
|
1392
|
-
//#endregion
|
|
1393
|
-
//#region src/components/RLSEditor/RLSEditor.tsx
|
|
1394
|
-
/**
|
|
1395
|
-
* Whether `descriptor` is the table the server declares for a live table: the
|
|
1396
|
-
* same SQL table in the same schema, as the server resolved both.
|
|
1397
|
-
*
|
|
1398
|
-
* Matched once by name, a table was taken for any collection whose `id`,
|
|
1399
|
-
* `path`, `table`, `slug` or `collectionId` equalled its name, in any schema.
|
|
1400
|
-
* So an unmapped table named like another table's slug, or a same-named table
|
|
1401
|
-
* in another schema, was taken for that table: it listed the declared
|
|
1402
|
-
* policies as missing from the table, and offered to import the table's own
|
|
1403
|
-
* policies into the declaration. A view is never a `pg_tables` row.
|
|
1404
|
-
*/
|
|
1405
|
-
function mapsTable(descriptor, table) {
|
|
1406
|
-
return descriptor.kind === "table" && descriptor.table === table.tableName && descriptor.schema === table.schemaName;
|
|
1407
|
-
}
|
|
1408
|
-
/** What the editor says when an edit has no declared rule to go back to. */
|
|
1409
|
-
var POLICY_EDIT_REFUSALS = {
|
|
1410
|
-
generated: "studio_rls_edit_generated",
|
|
1411
|
-
not_declared: "studio_rls_edit_not_declared",
|
|
1412
|
-
several_operations: "studio_rls_edit_several_operations",
|
|
1413
|
-
redacted: "studio_rls_edit_redacted"
|
|
1414
|
-
};
|
|
1415
|
-
function classifyTableClient(tableName, schemaName, isJunction, isMappedToCollection) {
|
|
1416
|
-
if (isMappedToCollection) return "collection";
|
|
1417
|
-
if (REBASE_INTERNAL_SCHEMAS.includes(schemaName) || REBASE_INTERNAL_PREFIXES.some((prefix) => tableName.startsWith(prefix))) return "internal";
|
|
1418
|
-
if (isJunction) return "junction";
|
|
1419
|
-
return "other";
|
|
1420
|
-
}
|
|
1421
|
-
function SidebarSection({ title, icon, expanded, onToggle, count, children }) {
|
|
1422
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1423
|
-
className: "mb-2",
|
|
1424
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
1425
|
-
className: "flex items-center p-1.5 cursor-pointer hover:bg-surface-hover rounded transition-colors",
|
|
1426
|
-
onClick: onToggle,
|
|
1427
|
-
children: [
|
|
1428
|
-
/* @__PURE__ */ jsx("svg", {
|
|
1429
|
-
className: cls("w-3 h-3 mr-1.5 transition-transform text-text-disabled dark:text-text-disabled-dark", expanded ? "rotate-90" : ""),
|
|
1430
|
-
fill: "currentColor",
|
|
1431
|
-
viewBox: "0 0 20 20",
|
|
1432
|
-
children: /* @__PURE__ */ jsx("path", { d: "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" })
|
|
1433
|
-
}),
|
|
1434
|
-
icon,
|
|
1435
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
1436
|
-
variant: "body2",
|
|
1437
|
-
className: "text-text-primary dark:text-text-primary-dark font-medium text-xs truncate flex-grow ml-1.5",
|
|
1438
|
-
children: title
|
|
1439
|
-
}),
|
|
1440
|
-
count !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
1441
|
-
className: "text-[10px] text-text-disabled dark:text-text-disabled-dark font-medium tabular-nums mr-1",
|
|
1442
|
-
children: count
|
|
1443
|
-
})
|
|
1444
|
-
]
|
|
1445
|
-
}), expanded && /* @__PURE__ */ jsx("div", {
|
|
1446
|
-
className: "ml-3 mt-0.5 space-y-0.5",
|
|
1447
|
-
children
|
|
1448
|
-
})]
|
|
1449
|
-
});
|
|
1450
|
-
}
|
|
1451
|
-
function SidebarTableRow({ table, isSelected, onSelect, badge, dimmed, t }) {
|
|
1452
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1453
|
-
onClick: onSelect,
|
|
1454
|
-
className: cls("flex items-center p-1 cursor-pointer rounded transition-colors group relative", isSelected ? "bg-primary/10 text-primary dark:bg-primary/20 dark:text-primary-light" : "hover:bg-surface-hover text-text-secondary dark:text-text-secondary-dark", dimmed && !isSelected && "opacity-60"),
|
|
1455
|
-
children: [
|
|
1456
|
-
/* @__PURE__ */ jsx("svg", {
|
|
1457
|
-
className: "w-3.5 h-3.5 mr-1 shrink-0 text-text-disabled dark:text-text-disabled-dark",
|
|
1458
|
-
fill: "none",
|
|
1459
|
-
stroke: "currentColor",
|
|
1460
|
-
viewBox: "0 0 24 24",
|
|
1461
|
-
children: /* @__PURE__ */ jsx("path", {
|
|
1462
|
-
strokeLinecap: "round",
|
|
1463
|
-
strokeLinejoin: "round",
|
|
1464
|
-
strokeWidth: 2,
|
|
1465
|
-
d: "M3 10h18M3 14h18m-9-4v8m-7 0h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"
|
|
1466
|
-
})
|
|
1467
|
-
}),
|
|
1468
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
1469
|
-
variant: "body2",
|
|
1470
|
-
className: "text-xs truncate flex-1 min-w-0",
|
|
1471
|
-
children: table.tableName
|
|
1472
|
-
}),
|
|
1473
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1474
|
-
className: "flex items-center gap-1.5 shrink-0 ml-2",
|
|
1475
|
-
children: [
|
|
1476
|
-
badge && /* @__PURE__ */ jsx("span", {
|
|
1477
|
-
className: "text-[9px] uppercase tracking-wider font-semibold text-text-disabled dark:text-text-disabled-dark bg-surface-raised rounded px-1 py-px",
|
|
1478
|
-
children: badge
|
|
1479
|
-
}),
|
|
1480
|
-
table.rlsEnabled ? /* @__PURE__ */ jsx(Tooltip, {
|
|
1481
|
-
title: t("studio_rls_enabled"),
|
|
1482
|
-
children: /* @__PURE__ */ jsx("div", { className: "w-1.5 h-1.5 rounded-full bg-green-500" })
|
|
1483
|
-
}) : /* @__PURE__ */ jsx(Tooltip, {
|
|
1484
|
-
title: t("studio_rls_disabled"),
|
|
1485
|
-
children: /* @__PURE__ */ jsx("div", { className: "w-1.5 h-1.5 rounded-full bg-orange-400 opacity-50" })
|
|
1486
|
-
}),
|
|
1487
|
-
/* @__PURE__ */ jsx("span", {
|
|
1488
|
-
className: "text-[10px] opacity-40 group-hover:opacity-100 min-w-[1.2rem] text-right font-medium",
|
|
1489
|
-
children: table.policies.length
|
|
1490
|
-
})
|
|
1491
|
-
]
|
|
1492
|
-
})
|
|
1493
|
-
]
|
|
1494
|
-
});
|
|
1495
|
-
}
|
|
1496
|
-
var RLSEditor = ({ apiUrl = "" }) => {
|
|
1497
|
-
const [mode, setMode] = useState("inspector");
|
|
1498
|
-
const { t } = useTranslation();
|
|
1499
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1500
|
-
className: "flex flex-col h-full w-full overflow-hidden",
|
|
1501
|
-
children: [/* @__PURE__ */ jsxs(Tabs, {
|
|
1502
|
-
value: mode,
|
|
1503
|
-
onValueChange: (v) => {
|
|
1504
|
-
if (v === "inspector" || v === "direct") setMode(v);
|
|
1505
|
-
},
|
|
1506
|
-
variant: "boxy",
|
|
1507
|
-
className: "border-b border-hairline px-4 bg-surface-sheet shrink-0",
|
|
1508
|
-
children: [/* @__PURE__ */ jsx(Tab, {
|
|
1509
|
-
value: "inspector",
|
|
1510
|
-
children: t("studio_rls_tab_inspector")
|
|
1511
|
-
}), /* @__PURE__ */ jsx(Tab, {
|
|
1512
|
-
value: "direct",
|
|
1513
|
-
children: t("studio_rls_tab_direct")
|
|
1514
|
-
})]
|
|
1515
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
1516
|
-
className: "flex-1 min-h-0 overflow-hidden",
|
|
1517
|
-
children: mode === "direct" ? /* @__PURE__ */ jsx(DirectRlsPoliciesPanel, {}) : /* @__PURE__ */ jsx(RLSEditorInspector, { apiUrl })
|
|
1518
|
-
})]
|
|
1519
|
-
});
|
|
1520
|
-
};
|
|
1521
|
-
var RLSEditorInspector = ({ apiUrl = "" }) => {
|
|
1522
|
-
const { databaseAdmin } = useRebaseContext();
|
|
1523
|
-
const snackbarController = useSnackbarController();
|
|
1524
|
-
const descriptors = useTableDescriptors();
|
|
1525
|
-
const schemaProblem = schemaSourceProblem(descriptors);
|
|
1526
|
-
const declaredTables = descriptors.tables;
|
|
1527
|
-
const { codebase: hasCodebase } = useStudioCapabilities();
|
|
1528
|
-
const apiConfig = useApiConfig();
|
|
1529
|
-
const apiBase = useApiBase() ?? `${apiUrl.replace(/\/+$/, "")}/api`;
|
|
1530
|
-
const schemaEditing = useStudioSchemaEditing();
|
|
1531
|
-
/**
|
|
1532
|
-
* Through the plan/apply dialog when there is one — see `saveRules`. A
|
|
1533
|
-
* save changes the source the served tables come from, so they are asked
|
|
1534
|
-
* for again: the declared side of the list follows the edit.
|
|
1535
|
-
*/
|
|
1536
|
-
const reloadDeclared = descriptors.reload;
|
|
1537
|
-
/**
|
|
1538
|
-
* Saving rules on a table that inherits them from `defaultRls` detaches it
|
|
1539
|
-
* into rules of its own: asked here, never done silently. Settled by the
|
|
1540
|
-
* dialog below — "OK" detaches, "Cancel" keeps `"inherit"`.
|
|
1541
|
-
*/
|
|
1542
|
-
const [detaching, setDetaching] = useState(null);
|
|
1543
|
-
const settleDetach = useRef(null);
|
|
1544
|
-
const confirmDetach = useCallback((slug) => new Promise((resolve) => {
|
|
1545
|
-
settleDetach.current?.(false);
|
|
1546
|
-
settleDetach.current = resolve;
|
|
1547
|
-
setDetaching(slug);
|
|
1548
|
-
}), []);
|
|
1549
|
-
const answerDetach = useCallback((detach) => {
|
|
1550
|
-
settleDetach.current?.(detach);
|
|
1551
|
-
settleDetach.current = null;
|
|
1552
|
-
setDetaching(null);
|
|
1553
|
-
}, []);
|
|
1554
|
-
const saveSecurityRules = useCallback(async (table, securityRules) => {
|
|
1555
|
-
await saveRules(schemaEditing, {
|
|
1556
|
-
apiBase,
|
|
1557
|
-
getAuthToken: apiConfig?.getAuthToken
|
|
1558
|
-
}, table, securityRules, { confirmDetach });
|
|
1559
|
-
reloadDeclared();
|
|
1560
|
-
}, [
|
|
1561
|
-
apiBase,
|
|
1562
|
-
apiConfig,
|
|
1563
|
-
schemaEditing,
|
|
1564
|
-
reloadDeclared,
|
|
1565
|
-
confirmDetach
|
|
1566
|
-
]);
|
|
1567
|
-
/** Closing the plan dialog is an answer, not a failure — see `saveRules`. */
|
|
1568
|
-
const reportSaveFailure = useCallback((e) => {
|
|
1569
|
-
if (isCancellation(e)) return;
|
|
1570
|
-
snackbarController.open({
|
|
1571
|
-
type: "error",
|
|
1572
|
-
message: e instanceof Error ? e.message : String(e)
|
|
1573
|
-
});
|
|
1574
|
-
}, [snackbarController]);
|
|
1575
|
-
const [editingPolicy, setEditingPolicy] = useState(null);
|
|
1576
|
-
/**
|
|
1577
|
-
* The two destructive actions used `window.confirm`, which is the browser's
|
|
1578
|
-
* dialog and not this app's: it cannot be styled, cannot be translated, and
|
|
1579
|
-
* is suppressed outright in a sandboxed iframe — where the click then did
|
|
1580
|
-
* the thing silently, with no confirmation at all.
|
|
1581
|
-
*/
|
|
1582
|
-
const [confirmToggleRls, setConfirmToggleRls] = useState(null);
|
|
1583
|
-
const [confirmDropPolicy, setConfirmDropPolicy] = useState(null);
|
|
1584
|
-
const [confirming, setConfirming] = useState(false);
|
|
1585
|
-
const applyToggleRls = useCallback(async () => {
|
|
1586
|
-
if (!confirmToggleRls) return;
|
|
1587
|
-
const { table, schema, enabled } = confirmToggleRls;
|
|
1588
|
-
const action = enabled ? "DISABLE" : "ENABLE";
|
|
1589
|
-
setConfirming(true);
|
|
1590
|
-
try {
|
|
1591
|
-
await databaseAdmin.executeSql(`ALTER TABLE ${quoteIdentifier(schema)}.${quoteIdentifier(table)} ${action} ROW LEVEL SECURITY`);
|
|
1592
|
-
snackbarController.open({
|
|
1593
|
-
type: "success",
|
|
1594
|
-
message: `RLS ${action.toLowerCase()}d on ${table}`
|
|
1595
|
-
});
|
|
1596
|
-
setConfirmToggleRls(null);
|
|
1597
|
-
fetchRLSData();
|
|
1598
|
-
} catch (e) {
|
|
1599
|
-
snackbarController.open({
|
|
1600
|
-
type: "error",
|
|
1601
|
-
message: e instanceof Error ? e.message : String(e)
|
|
1602
|
-
});
|
|
1603
|
-
} finally {
|
|
1604
|
-
setConfirming(false);
|
|
1605
|
-
}
|
|
1606
|
-
}, [
|
|
1607
|
-
confirmToggleRls,
|
|
1608
|
-
databaseAdmin,
|
|
1609
|
-
snackbarController
|
|
1610
|
-
]);
|
|
1611
|
-
const applyDropPolicy = useCallback(async () => {
|
|
1612
|
-
if (!confirmDropPolicy) return;
|
|
1613
|
-
const { policyName, table, schema } = confirmDropPolicy;
|
|
1614
|
-
setConfirming(true);
|
|
1615
|
-
try {
|
|
1616
|
-
const target = `${quoteIdentifier(schema)}.${quoteIdentifier(table)}`;
|
|
1617
|
-
await databaseAdmin.executeSql(`DROP POLICY ${quoteIdentifier(policyName)} ON ${target}; DROP POLICY IF EXISTS ${quoteIdentifier(adminRequestPolicyName(policyName))} ON ${target}`);
|
|
1618
|
-
snackbarController.open({
|
|
1619
|
-
type: "success",
|
|
1620
|
-
message: `Policy "${policyName}" dropped`
|
|
1621
|
-
});
|
|
1622
|
-
setConfirmDropPolicy(null);
|
|
1623
|
-
fetchRLSData();
|
|
1624
|
-
} catch (e) {
|
|
1625
|
-
snackbarController.open({
|
|
1626
|
-
type: "error",
|
|
1627
|
-
message: e instanceof Error ? e.message : String(e)
|
|
1628
|
-
});
|
|
1629
|
-
} finally {
|
|
1630
|
-
setConfirming(false);
|
|
1631
|
-
}
|
|
1632
|
-
}, [
|
|
1633
|
-
confirmDropPolicy,
|
|
1634
|
-
databaseAdmin,
|
|
1635
|
-
snackbarController
|
|
1636
|
-
]);
|
|
1637
|
-
const { t } = useTranslation();
|
|
1638
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
1639
|
-
const [error, setError] = useState(null);
|
|
1640
|
-
const [tables, setTables] = useState([]);
|
|
1641
|
-
const [selectedTable, setSelectedTable] = useState(null);
|
|
1642
|
-
const [activeTab, setActiveTab] = useState(0);
|
|
1643
|
-
const [junctionTableNames, setJunctionTableNames] = useState(/* @__PURE__ */ new Set());
|
|
1644
|
-
/**
|
|
1645
|
-
* Native PostgreSQL roles, for the policy editor's `TO` list.
|
|
1646
|
-
*
|
|
1647
|
-
* `fetchAvailableRoles` and not `fetchApplicationRoles`: a policy's `TO`
|
|
1648
|
-
* clause names database roles, and an application role put there produces a
|
|
1649
|
-
* policy that either fails to create or matches nothing. The editor falls
|
|
1650
|
-
* back to a static pair when the driver cannot answer.
|
|
1651
|
-
*/
|
|
1652
|
-
const [pgRoleOptions, setPgRoleOptions] = useState([]);
|
|
1653
|
-
useEffect(() => {
|
|
1654
|
-
let mounted = true;
|
|
1655
|
-
if (!databaseAdmin?.fetchAvailableRoles) return;
|
|
1656
|
-
databaseAdmin.fetchAvailableRoles().then((roles) => {
|
|
1657
|
-
if (mounted) setPgRoleOptions(roles);
|
|
1658
|
-
}).catch((e) => console.error("Failed to fetch database roles", e));
|
|
1659
|
-
return () => {
|
|
1660
|
-
mounted = false;
|
|
1661
|
-
};
|
|
1662
|
-
}, [databaseAdmin]);
|
|
1663
|
-
const [sidebarSize, setSidebarSize] = useState(() => {
|
|
1664
|
-
try {
|
|
1665
|
-
const saved = localStorage.getItem("rebase_rls_editor_sidebar_size");
|
|
1666
|
-
return saved !== null ? parseFloat(saved) : 20;
|
|
1667
|
-
} catch (e) {
|
|
1668
|
-
return 20;
|
|
1669
|
-
}
|
|
1670
|
-
});
|
|
1671
|
-
const [expandedSections, setExpandedSections] = useState({
|
|
1672
|
-
collection: true,
|
|
1673
|
-
other: true,
|
|
1674
|
-
internal: false
|
|
1675
|
-
});
|
|
1676
|
-
const [sidebarTab, setSidebarTab] = useState("tables");
|
|
1677
|
-
useEffect(() => {
|
|
1678
|
-
try {
|
|
1679
|
-
localStorage.setItem("rebase_rls_editor_sidebar_size", sidebarSize.toString());
|
|
1680
|
-
} catch (e) {}
|
|
1681
|
-
}, [sidebarSize]);
|
|
1682
|
-
const fetchRLSData = useCallback(async () => {
|
|
1683
|
-
if (!databaseAdmin?.executeSql) {
|
|
1684
|
-
setError(t("studio_sql_sql_not_supported"));
|
|
1685
|
-
setIsLoading(false);
|
|
1686
|
-
return;
|
|
1687
|
-
}
|
|
1688
|
-
setIsLoading(true);
|
|
1689
|
-
setError(null);
|
|
1690
|
-
try {
|
|
1691
|
-
const tablesResult = await databaseAdmin.executeSql(`
|
|
1692
|
-
SELECT
|
|
1693
|
-
schemaname,
|
|
1694
|
-
tablename,
|
|
1695
|
-
rowsecurity
|
|
1696
|
-
FROM pg_tables
|
|
1697
|
-
WHERE schemaname NOT IN ('information_schema', 'pg_catalog')
|
|
1698
|
-
ORDER BY schemaname, tablename;
|
|
1699
|
-
`);
|
|
1700
|
-
const policiesResult = await databaseAdmin.executeSql(`
|
|
1701
|
-
SELECT
|
|
1702
|
-
schemaname,
|
|
1703
|
-
tablename,
|
|
1704
|
-
policyname,
|
|
1705
|
-
permissive,
|
|
1706
|
-
roles,
|
|
1707
|
-
cmd,
|
|
1708
|
-
qual,
|
|
1709
|
-
with_check
|
|
1710
|
-
FROM pg_policies
|
|
1711
|
-
WHERE schemaname NOT IN ('information_schema', 'pg_catalog');
|
|
1712
|
-
`);
|
|
1713
|
-
const extractRows = (result) => {
|
|
1714
|
-
if (result && typeof result === "object" && "rows" in result && Array.isArray(result.rows)) return result.rows;
|
|
1715
|
-
if (Array.isArray(result)) return result;
|
|
1716
|
-
return [];
|
|
1717
|
-
};
|
|
1718
|
-
const tRows = extractRows(tablesResult);
|
|
1719
|
-
const pRows = extractRows(policiesResult);
|
|
1720
|
-
const tableMap = {};
|
|
1721
|
-
tRows.forEach((tRow) => {
|
|
1722
|
-
const t = tRow;
|
|
1723
|
-
const schema = t.schemaname || t.SCHEMANAME || "public";
|
|
1724
|
-
const table = t.tablename || t.TABLENAME || "";
|
|
1725
|
-
const rlsEnabled = t.rowsecurity || t.ROWSECURITY || false;
|
|
1726
|
-
const key = `${schema}.${table}`;
|
|
1727
|
-
tableMap[key] = {
|
|
1728
|
-
schemaName: schema,
|
|
1729
|
-
tableName: table,
|
|
1730
|
-
rlsEnabled,
|
|
1731
|
-
policies: []
|
|
1732
|
-
};
|
|
1733
|
-
});
|
|
1734
|
-
pRows.forEach((pRow) => {
|
|
1735
|
-
const p = pRow;
|
|
1736
|
-
const schema = p.schemaname || p.SCHEMANAME || "public";
|
|
1737
|
-
const table = p.tablename || p.TABLENAME || "";
|
|
1738
|
-
const key = `${schema}.${table}`;
|
|
1739
|
-
if (tableMap[key]) {
|
|
1740
|
-
const parsedRoles = readPolicyRoles(p.roles || p.ROLES);
|
|
1741
|
-
tableMap[key].policies.push({
|
|
1742
|
-
policyname: p.policyname || p.POLICYNAME || "",
|
|
1743
|
-
tablename: table,
|
|
1744
|
-
permissive: p.permissive || p.PERMISSIVE || "PERMISSIVE",
|
|
1745
|
-
roles: parsedRoles,
|
|
1746
|
-
cmd: p.cmd || p.CMD || "ALL",
|
|
1747
|
-
qual: p.qual || p.QUAL || null,
|
|
1748
|
-
with_check: p.with_check || p.WITH_CHECK || null
|
|
1749
|
-
});
|
|
1750
|
-
}
|
|
1751
|
-
});
|
|
1752
|
-
const sortedTables = Object.values(tableMap).sort((a, b) => a.tableName.localeCompare(b.tableName));
|
|
1753
|
-
setTables(sortedTables);
|
|
1754
|
-
try {
|
|
1755
|
-
const jRows = extractRows(await databaseAdmin.executeSql(JUNCTION_TABLES_SQL));
|
|
1756
|
-
setJunctionTableNames(new Set(jRows.map((r) => r.table_name).filter(Boolean)));
|
|
1757
|
-
} catch {}
|
|
1758
|
-
if (sortedTables.length > 0) {
|
|
1759
|
-
const firstUserTable = sortedTables.find((t) => !REBASE_INTERNAL_SCHEMAS.includes(t.schemaName)) ?? sortedTables[0];
|
|
1760
|
-
setSelectedTable((previous) => previous ?? `${firstUserTable.schemaName}.${firstUserTable.tableName}`);
|
|
1761
|
-
}
|
|
1762
|
-
} catch (e) {
|
|
1763
|
-
console.error("RLS fetch error:", e);
|
|
1764
|
-
setError("Failed to fetch RLS policies: " + (e instanceof Error ? e.message : String(e)));
|
|
1765
|
-
} finally {
|
|
1766
|
-
setIsLoading(false);
|
|
1767
|
-
}
|
|
1768
|
-
}, [databaseAdmin]);
|
|
1769
|
-
useEffect(() => {
|
|
1770
|
-
setEditingPolicy(null);
|
|
1771
|
-
}, [selectedTable]);
|
|
1772
|
-
useEffect(() => {
|
|
1773
|
-
fetchRLSData();
|
|
1774
|
-
}, [fetchRLSData]);
|
|
1775
|
-
const activeTableData = useMemo(() => {
|
|
1776
|
-
if (!selectedTable) return null;
|
|
1777
|
-
return tables.find((t) => `${t.schemaName}.${t.tableName}` === selectedTable) || null;
|
|
1778
|
-
}, [selectedTable, tables]);
|
|
1779
|
-
/**
|
|
1780
|
-
* Every junction the server derives, with its policies, by
|
|
1781
|
-
* `schema.table`. A junction has no descriptor of its own: it is listed
|
|
1782
|
-
* under each table that declares a relation through it.
|
|
1783
|
-
*/
|
|
1784
|
-
const servedJunctions = useMemo(() => {
|
|
1785
|
-
const junctions = /* @__PURE__ */ new Map();
|
|
1786
|
-
for (const table of declaredTables) {
|
|
1787
|
-
for (const junction of table.rls.junctions ?? []) junctions.set(`${junction.schema}.${junction.table}`, junction);
|
|
1788
|
-
for (const relation of table.relations) {
|
|
1789
|
-
if (relation.kind !== "manyToMany") continue;
|
|
1790
|
-
const key = `${table.schema}.${relation.through.table}`;
|
|
1791
|
-
if (!junctions.has(key)) junctions.set(key, {
|
|
1792
|
-
table: relation.through.table,
|
|
1793
|
-
schema: table.schema,
|
|
1794
|
-
policies: []
|
|
1795
|
-
});
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
return junctions;
|
|
1799
|
-
}, [declaredTables]);
|
|
1800
|
-
/** Categorize tables into 4 buckets for the sidebar. */
|
|
1801
|
-
const categorizedTables = useMemo(() => {
|
|
1802
|
-
const groups = {
|
|
1803
|
-
collection: [],
|
|
1804
|
-
junction: [],
|
|
1805
|
-
internal: [],
|
|
1806
|
-
other: []
|
|
1807
|
-
};
|
|
1808
|
-
tables.forEach((table) => {
|
|
1809
|
-
const isMapped = declaredTables.some((descriptor) => mapsTable(descriptor, table));
|
|
1810
|
-
const isJunction = junctionTableNames.has(table.tableName) || servedJunctions.has(`${table.schemaName}.${table.tableName}`);
|
|
1811
|
-
const cat = classifyTableClient(table.tableName, table.schemaName, isJunction, isMapped);
|
|
1812
|
-
groups[cat].push(table);
|
|
1813
|
-
});
|
|
1814
|
-
return groups;
|
|
1815
|
-
}, [
|
|
1816
|
-
tables,
|
|
1817
|
-
junctionTableNames,
|
|
1818
|
-
servedJunctions,
|
|
1819
|
-
declaredTables
|
|
1820
|
-
]);
|
|
1821
|
-
/** The table the server declares for the selected one, if any. */
|
|
1822
|
-
const activeDescriptor = useMemo(() => {
|
|
1823
|
-
if (!activeTableData) return null;
|
|
1824
|
-
return declaredTables.find((descriptor) => mapsTable(descriptor, activeTableData)) ?? null;
|
|
1825
|
-
}, [activeTableData, declaredTables]);
|
|
1826
|
-
/**
|
|
1827
|
-
* The junction a relation derives this table as, when it is one. Its
|
|
1828
|
-
* policies are Rebase's — derived from the endpoints' relations — and the
|
|
1829
|
-
* server re-creates them on every start, like a declared table's.
|
|
1830
|
-
*/
|
|
1831
|
-
const activeJunction = useMemo(() => {
|
|
1832
|
-
if (!activeTableData || activeDescriptor) return null;
|
|
1833
|
-
return servedJunctions.get(`${activeTableData.schemaName}.${activeTableData.tableName}`) ?? null;
|
|
1834
|
-
}, [
|
|
1835
|
-
activeTableData,
|
|
1836
|
-
activeDescriptor,
|
|
1837
|
-
servedJunctions
|
|
1838
|
-
]);
|
|
1839
|
-
/** The category of the currently selected table. */
|
|
1840
|
-
const activeTableCategory = useMemo(() => {
|
|
1841
|
-
if (!activeTableData) return null;
|
|
1842
|
-
const isJunction = Boolean(activeJunction) || junctionTableNames.has(activeTableData.tableName);
|
|
1843
|
-
return classifyTableClient(activeTableData.tableName, activeTableData.schemaName, isJunction, Boolean(activeDescriptor));
|
|
1844
|
-
}, [
|
|
1845
|
-
activeTableData,
|
|
1846
|
-
activeDescriptor,
|
|
1847
|
-
activeJunction,
|
|
1848
|
-
junctionTableNames
|
|
1849
|
-
]);
|
|
1850
|
-
/**
|
|
1851
|
-
* Whether the server re-asserts this table's RLS on every start: it switches
|
|
1852
|
-
* RLS back on and re-creates every policy the project declares for it.
|
|
1853
|
-
*/
|
|
1854
|
-
const activeTableManaged = Boolean(activeDescriptor || activeJunction);
|
|
1855
|
-
/**
|
|
1856
|
-
* What the server says the selected table's policies are — `undefined`
|
|
1857
|
-
* when it declares none, or withheld them from this caller.
|
|
1858
|
-
*/
|
|
1859
|
-
const activeDeclared = useMemo(() => {
|
|
1860
|
-
if (activeDescriptor) return declaredPoliciesOf(activeDescriptor.rls);
|
|
1861
|
-
if (activeJunction && activeJunction.policies.length > 0) return {
|
|
1862
|
-
rules: [],
|
|
1863
|
-
policies: activeJunction.policies
|
|
1864
|
-
};
|
|
1865
|
-
}, [activeDescriptor, activeJunction]);
|
|
1866
|
-
/**
|
|
1867
|
-
* The table is declared, but this caller is not shown what it compiles to
|
|
1868
|
-
* (no `schema:read`): the list is what the database holds, and nothing is
|
|
1869
|
-
* written to the declaration — its raw rules may be redacted.
|
|
1870
|
-
*/
|
|
1871
|
-
const declaredWithheld = activeDescriptor !== null && activeDeclared === void 0;
|
|
1872
|
-
/** A save to the declaration needs the declaration, and a codebase to write it into. */
|
|
1873
|
-
const savesToCodebase = activeDescriptor !== null && hasCodebase;
|
|
1874
|
-
/**
|
|
1875
|
-
* What Postgres enforces on the selected table, and what the code declares
|
|
1876
|
-
* that it does not have yet.
|
|
1877
|
-
*
|
|
1878
|
-
* A policy in both is listed with the *database's* fields, and the
|
|
1879
|
-
* declaration rides beside it with where the two differ (`listPolicies`).
|
|
1880
|
-
* The declaration's fields in their place would make a policy changed in
|
|
1881
|
-
* SQL look exactly like its declaration, and would show every rule written
|
|
1882
|
-
* as a structured condition — all of Rebase's own policies — with no USING.
|
|
1883
|
-
*/
|
|
1884
|
-
const mergedPolicies = useMemo(() => {
|
|
1885
|
-
if (!activeTableData) return [];
|
|
1886
|
-
return listPolicies(activeTableData.policies || [], activeDeclared, activeTableData.tableName).sort((a, b) => a.policyname.localeCompare(b.policyname));
|
|
1887
|
-
}, [activeTableData, activeDeclared]);
|
|
1888
|
-
const rlsStats = useMemo(() => {
|
|
1889
|
-
return {
|
|
1890
|
-
total: tables.length,
|
|
1891
|
-
enabled: tables.filter((t) => t.rlsEnabled).length,
|
|
1892
|
-
withPolicies: tables.filter((t) => t.policies.length > 0).length,
|
|
1893
|
-
totalPolicies: tables.reduce((sum, t) => sum + t.policies.length, 0)
|
|
1894
|
-
};
|
|
1895
|
-
}, [tables]);
|
|
1896
|
-
const renderPolicyTag = (label, value) => {
|
|
1897
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1898
|
-
className: "flex items-center gap-1.5 px-2 py-1 rounded-md bg-surface-well border border-hairline",
|
|
1899
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
1900
|
-
className: "text-[10px] uppercase text-text-secondary dark:text-text-secondary-dark font-medium tracking-wider",
|
|
1901
|
-
children: [label, ":"]
|
|
1902
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
1903
|
-
className: "font-mono text-xs text-text-primary dark:text-text-primary-dark break-all",
|
|
1904
|
-
children: value
|
|
1905
|
-
})]
|
|
1906
|
-
});
|
|
1907
|
-
};
|
|
1908
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1909
|
-
className: "flex h-full w-full bg-surface-card overflow-hidden text-text-primary dark:text-text-primary-dark",
|
|
1910
|
-
children: [
|
|
1911
|
-
/* @__PURE__ */ jsx(ResizablePanels, {
|
|
1912
|
-
dividerAriaLabel: t("resize_sidebar"),
|
|
1913
|
-
orientation: "horizontal",
|
|
1914
|
-
panelSizePercent: sidebarSize,
|
|
1915
|
-
onPanelSizeChange: setSidebarSize,
|
|
1916
|
-
minPanelSizePx: 220,
|
|
1917
|
-
firstPanel: /* @__PURE__ */ jsxs("div", {
|
|
1918
|
-
className: cls("flex flex-col h-full w-full bg-surface-card border-r", defaultBorderMixin),
|
|
1919
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
1920
|
-
className: cls("flex items-center justify-between pl-2 pr-2 border-b bg-surface-sheet shrink-0", defaultBorderMixin),
|
|
1921
|
-
children: [/* @__PURE__ */ jsxs(Tabs, {
|
|
1922
|
-
value: sidebarTab,
|
|
1923
|
-
onValueChange: (v) => setSidebarTab(v),
|
|
1924
|
-
variant: "boxy",
|
|
1925
|
-
className: "w-[unset] flex-shrink-0",
|
|
1926
|
-
children: [/* @__PURE__ */ jsx(Tab, {
|
|
1927
|
-
value: "tables",
|
|
1928
|
-
children: "Tables"
|
|
1929
|
-
}), /* @__PURE__ */ jsx(Tab, {
|
|
1930
|
-
value: "info",
|
|
1931
|
-
children: "Info"
|
|
1932
|
-
})]
|
|
1933
|
-
}), /* @__PURE__ */ jsx(IconButton, {
|
|
1934
|
-
"aria-label": t("refresh"),
|
|
1935
|
-
size: "small",
|
|
1936
|
-
onClick: fetchRLSData,
|
|
1937
|
-
title: t("refresh"),
|
|
1938
|
-
children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
|
|
1939
|
-
})]
|
|
1940
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
1941
|
-
className: "flex-grow overflow-hidden relative",
|
|
1942
|
-
children: [sidebarTab === "tables" && /* @__PURE__ */ jsx("div", {
|
|
1943
|
-
className: "flex flex-col h-full",
|
|
1944
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
1945
|
-
className: "flex-grow overflow-y-auto no-scrollbar p-1",
|
|
1946
|
-
children: isLoading && tables.length === 0 ? /* @__PURE__ */ jsx("div", {
|
|
1947
|
-
className: "flex justify-center p-4",
|
|
1948
|
-
children: /* @__PURE__ */ jsx(CircularProgress, { size: "small" })
|
|
1949
|
-
}) : tables.length === 0 ? /* @__PURE__ */ jsx("div", {
|
|
1950
|
-
className: "p-4 text-center",
|
|
1951
|
-
children: /* @__PURE__ */ jsx(Typography, {
|
|
1952
|
-
variant: "caption",
|
|
1953
|
-
className: "text-text-disabled dark:text-text-disabled-dark italic",
|
|
1954
|
-
children: t("studio_rls_no_tables")
|
|
1955
|
-
})
|
|
1956
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1957
|
-
(categorizedTables.collection.length > 0 || categorizedTables.junction.length > 0) && /* @__PURE__ */ jsxs(SidebarSection, {
|
|
1958
|
-
title: t("studio_rls_served_tables"),
|
|
1959
|
-
icon: /* @__PURE__ */ jsx(DatabaseIcon, {
|
|
1960
|
-
size: 12,
|
|
1961
|
-
className: "text-primary dark:text-primary-light"
|
|
1962
|
-
}),
|
|
1963
|
-
expanded: expandedSections.collection ?? true,
|
|
1964
|
-
onToggle: () => setExpandedSections((prev) => ({
|
|
1965
|
-
...prev,
|
|
1966
|
-
collection: !(prev.collection ?? true)
|
|
1967
|
-
})),
|
|
1968
|
-
children: [categorizedTables.collection.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
1969
|
-
table,
|
|
1970
|
-
isSelected: selectedTable === `${table.schemaName}.${table.tableName}`,
|
|
1971
|
-
onSelect: () => setSelectedTable(`${table.schemaName}.${table.tableName}`),
|
|
1972
|
-
t
|
|
1973
|
-
}, `${table.schemaName}.${table.tableName}`)), categorizedTables.junction.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
1974
|
-
table,
|
|
1975
|
-
isSelected: selectedTable === `${table.schemaName}.${table.tableName}`,
|
|
1976
|
-
onSelect: () => setSelectedTable(`${table.schemaName}.${table.tableName}`),
|
|
1977
|
-
badge: "Junction",
|
|
1978
|
-
dimmed: true,
|
|
1979
|
-
t
|
|
1980
|
-
}, `${table.schemaName}.${table.tableName}`))]
|
|
1981
|
-
}),
|
|
1982
|
-
categorizedTables.other.length > 0 && /* @__PURE__ */ jsx(SidebarSection, {
|
|
1983
|
-
title: "Not served",
|
|
1984
|
-
icon: /* @__PURE__ */ jsx(AlertTriangleIcon, {
|
|
1985
|
-
size: 12,
|
|
1986
|
-
className: "text-yellow-500 dark:text-yellow-400"
|
|
1987
|
-
}),
|
|
1988
|
-
expanded: expandedSections.other ?? true,
|
|
1989
|
-
onToggle: () => setExpandedSections((prev) => ({
|
|
1990
|
-
...prev,
|
|
1991
|
-
other: !(prev.other ?? true)
|
|
1992
|
-
})),
|
|
1993
|
-
children: categorizedTables.other.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
1994
|
-
table,
|
|
1995
|
-
isSelected: selectedTable === `${table.schemaName}.${table.tableName}`,
|
|
1996
|
-
onSelect: () => setSelectedTable(`${table.schemaName}.${table.tableName}`),
|
|
1997
|
-
t
|
|
1998
|
-
}, `${table.schemaName}.${table.tableName}`))
|
|
1999
|
-
}),
|
|
2000
|
-
categorizedTables.internal.length > 0 && /* @__PURE__ */ jsx(SidebarSection, {
|
|
2001
|
-
title: "Rebase Internal",
|
|
2002
|
-
icon: /* @__PURE__ */ jsx(LockIcon, {
|
|
2003
|
-
size: 12,
|
|
2004
|
-
className: "text-text-disabled dark:text-text-disabled-dark"
|
|
2005
|
-
}),
|
|
2006
|
-
expanded: expandedSections.internal ?? false,
|
|
2007
|
-
onToggle: () => setExpandedSections((prev) => ({
|
|
2008
|
-
...prev,
|
|
2009
|
-
internal: !(prev.internal ?? false)
|
|
2010
|
-
})),
|
|
2011
|
-
count: categorizedTables.internal.length,
|
|
2012
|
-
children: categorizedTables.internal.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
2013
|
-
table,
|
|
2014
|
-
isSelected: selectedTable === `${table.schemaName}.${table.tableName}`,
|
|
2015
|
-
onSelect: () => setSelectedTable(`${table.schemaName}.${table.tableName}`),
|
|
2016
|
-
dimmed: true,
|
|
2017
|
-
t
|
|
2018
|
-
}, `${table.schemaName}.${table.tableName}`))
|
|
2019
|
-
})
|
|
2020
|
-
] })
|
|
2021
|
-
})
|
|
2022
|
-
}), sidebarTab === "info" && /* @__PURE__ */ jsx("div", {
|
|
2023
|
-
className: "flex flex-col h-full",
|
|
2024
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
2025
|
-
className: "flex-grow overflow-y-auto p-3 space-y-3 no-scrollbar",
|
|
2026
|
-
children: [
|
|
2027
|
-
/* @__PURE__ */ jsxs("div", {
|
|
2028
|
-
className: cls("p-3 rounded-lg border bg-surface-card", defaultBorderMixin),
|
|
2029
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
2030
|
-
className: "flex items-center gap-2 mb-2",
|
|
2031
|
-
children: [/* @__PURE__ */ jsx(ShieldIcon, {
|
|
2032
|
-
size: iconSize.smallest,
|
|
2033
|
-
className: "text-primary"
|
|
2034
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
2035
|
-
variant: "body2",
|
|
2036
|
-
className: "font-semibold text-[13px]",
|
|
2037
|
-
children: "RLS Studio"
|
|
2038
|
-
})]
|
|
2039
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
2040
|
-
variant: "caption",
|
|
2041
|
-
className: "text-text-secondary dark:text-text-secondary-dark text-xs leading-relaxed block",
|
|
2042
|
-
children: "Manage Row Level Security policies for your PostgreSQL tables. Enable RLS and create fine-grained access policies."
|
|
2043
|
-
})]
|
|
2044
|
-
}),
|
|
2045
|
-
/* @__PURE__ */ jsxs("div", {
|
|
2046
|
-
className: "space-y-2",
|
|
2047
|
-
children: [
|
|
2048
|
-
/* @__PURE__ */ jsxs("div", {
|
|
2049
|
-
className: cls("p-2.5 rounded border bg-surface-card flex items-center justify-between", defaultBorderMixin),
|
|
2050
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
2051
|
-
variant: "caption",
|
|
2052
|
-
className: "text-text-secondary dark:text-text-secondary-dark text-xs",
|
|
2053
|
-
children: "Total tables"
|
|
2054
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
2055
|
-
variant: "body2",
|
|
2056
|
-
className: "font-mono text-[13px] font-medium",
|
|
2057
|
-
children: rlsStats.total
|
|
2058
|
-
})]
|
|
2059
|
-
}),
|
|
2060
|
-
/* @__PURE__ */ jsxs("div", {
|
|
2061
|
-
className: cls("p-2.5 rounded border bg-surface-card flex items-center justify-between", defaultBorderMixin),
|
|
2062
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
2063
|
-
variant: "caption",
|
|
2064
|
-
className: "text-text-secondary dark:text-text-secondary-dark text-xs",
|
|
2065
|
-
children: t("studio_rls_enabled")
|
|
2066
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
2067
|
-
className: "flex items-center gap-1.5",
|
|
2068
|
-
children: [/* @__PURE__ */ jsx("div", { className: "w-1.5 h-1.5 rounded-full bg-green-500" }), /* @__PURE__ */ jsx(Typography, {
|
|
2069
|
-
variant: "body2",
|
|
2070
|
-
className: "font-mono text-[13px] font-medium",
|
|
2071
|
-
children: rlsStats.enabled
|
|
2072
|
-
})]
|
|
2073
|
-
})]
|
|
2074
|
-
}),
|
|
2075
|
-
/* @__PURE__ */ jsxs("div", {
|
|
2076
|
-
className: cls("p-2.5 rounded border bg-surface-card flex items-center justify-between", defaultBorderMixin),
|
|
2077
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
2078
|
-
variant: "caption",
|
|
2079
|
-
className: "text-text-secondary dark:text-text-secondary-dark text-xs",
|
|
2080
|
-
children: "Tables with policies"
|
|
2081
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
2082
|
-
variant: "body2",
|
|
2083
|
-
className: "font-mono text-[13px] font-medium",
|
|
2084
|
-
children: rlsStats.withPolicies
|
|
2085
|
-
})]
|
|
2086
|
-
}),
|
|
2087
|
-
/* @__PURE__ */ jsxs("div", {
|
|
2088
|
-
className: cls("p-2.5 rounded border bg-surface-card flex items-center justify-between", defaultBorderMixin),
|
|
2089
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
2090
|
-
variant: "caption",
|
|
2091
|
-
className: "text-text-secondary dark:text-text-secondary-dark text-xs",
|
|
2092
|
-
children: "Total policies"
|
|
2093
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
2094
|
-
variant: "body2",
|
|
2095
|
-
className: "font-mono text-[13px] font-medium",
|
|
2096
|
-
children: rlsStats.totalPolicies
|
|
2097
|
-
})]
|
|
2098
|
-
})
|
|
2099
|
-
]
|
|
2100
|
-
}),
|
|
2101
|
-
rlsStats.total - rlsStats.enabled > 0 && /* @__PURE__ */ jsxs("div", {
|
|
2102
|
-
className: cls("p-2.5 rounded border border-yellow-200 dark:border-yellow-900/50 bg-yellow-50 dark:bg-yellow-900/20 flex items-start gap-2", defaultBorderMixin),
|
|
2103
|
-
children: [/* @__PURE__ */ jsx(AlertTriangleIcon, {
|
|
2104
|
-
size: 14,
|
|
2105
|
-
className: "text-yellow-600 dark:text-yellow-500 mt-0.5 shrink-0"
|
|
2106
|
-
}), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs(Typography, {
|
|
2107
|
-
variant: "caption",
|
|
2108
|
-
className: "text-yellow-800 dark:text-yellow-400 text-xs font-semibold block",
|
|
2109
|
-
children: [
|
|
2110
|
-
rlsStats.total - rlsStats.enabled,
|
|
2111
|
-
" table",
|
|
2112
|
-
rlsStats.total - rlsStats.enabled > 1 ? "s" : "",
|
|
2113
|
-
" without RLS"
|
|
2114
|
-
]
|
|
2115
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
2116
|
-
variant: "caption",
|
|
2117
|
-
className: "text-yellow-700 dark:text-yellow-600 text-xs block mt-0.5",
|
|
2118
|
-
children: "These tables have no row-level access control. If auth enforcement is disabled, data may be publicly accessible."
|
|
2119
|
-
})] })]
|
|
2120
|
-
}),
|
|
2121
|
-
rlsStats.enabled > 0 && rlsStats.enabled - rlsStats.withPolicies > 0 && /* @__PURE__ */ jsxs("div", {
|
|
2122
|
-
className: cls("p-2.5 rounded border border-blue-200 dark:border-blue-900/50 bg-blue-50 dark:bg-blue-900/20 flex items-start gap-2", defaultBorderMixin),
|
|
2123
|
-
children: [/* @__PURE__ */ jsx(ShieldIcon, {
|
|
2124
|
-
size: 14,
|
|
2125
|
-
className: "text-blue-600 dark:text-blue-400 mt-0.5 shrink-0"
|
|
2126
|
-
}), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs(Typography, {
|
|
2127
|
-
variant: "caption",
|
|
2128
|
-
className: "text-blue-800 dark:text-blue-300 text-xs font-semibold block",
|
|
2129
|
-
children: [
|
|
2130
|
-
rlsStats.enabled - rlsStats.withPolicies,
|
|
2131
|
-
" table",
|
|
2132
|
-
rlsStats.enabled - rlsStats.withPolicies > 1 ? "s" : "",
|
|
2133
|
-
" with RLS but no policies"
|
|
2134
|
-
]
|
|
2135
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
2136
|
-
variant: "caption",
|
|
2137
|
-
className: "text-blue-700 dark:text-blue-500 text-xs block mt-0.5",
|
|
2138
|
-
children: "RLS is enabled but no permissive policies exist. All access is denied by default (Postgres deny-all)."
|
|
2139
|
-
})] })]
|
|
2140
|
-
})
|
|
2141
|
-
]
|
|
2142
|
-
})
|
|
2143
|
-
})]
|
|
2144
|
-
})]
|
|
2145
|
-
}),
|
|
2146
|
-
secondPanel: /* @__PURE__ */ jsxs("div", {
|
|
2147
|
-
className: "flex-grow flex flex-col min-w-0 h-full w-full bg-surface-card",
|
|
2148
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
2149
|
-
className: cls("flex items-center justify-between pr-2 border-b bg-surface-sheet h-[42px] shrink-0", defaultBorderMixin),
|
|
2150
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
2151
|
-
className: "flex items-center flex-grow overflow-hidden px-4",
|
|
2152
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
2153
|
-
variant: "subtitle2",
|
|
2154
|
-
className: "font-mono text-text-secondary dark:text-text-secondary-dark truncate",
|
|
2155
|
-
children: activeTableData ? `${activeTableData.schemaName}.${activeTableData.tableName}` : t("studio_rls_select_table")
|
|
2156
|
-
}), activeTableData && /* @__PURE__ */ jsx("div", {
|
|
2157
|
-
className: "ml-3",
|
|
2158
|
-
children: activeTableData.rlsEnabled ? /* @__PURE__ */ jsx(Chip, {
|
|
2159
|
-
size: "smallest",
|
|
2160
|
-
className: "bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400 border-green-200 dark:border-green-800",
|
|
2161
|
-
children: t("studio_rls_enabled")
|
|
2162
|
-
}) : /* @__PURE__ */ jsx(Chip, {
|
|
2163
|
-
size: "smallest",
|
|
2164
|
-
className: "bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400 border-yellow-200 dark:border-yellow-800",
|
|
2165
|
-
children: t("studio_rls_disabled")
|
|
2166
|
-
})
|
|
2167
|
-
})]
|
|
2168
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
2169
|
-
className: "flex shrink-0 items-center justify-end gap-1.5",
|
|
2170
|
-
children: activeTableData && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2171
|
-
/* @__PURE__ */ jsx(Button, {
|
|
2172
|
-
variant: "text",
|
|
2173
|
-
size: "small",
|
|
2174
|
-
onClick: () => setConfirmToggleRls({
|
|
2175
|
-
table: activeTableData.tableName,
|
|
2176
|
-
schema: activeTableData.schemaName,
|
|
2177
|
-
enabled: activeTableData.rlsEnabled,
|
|
2178
|
-
managed: activeTableManaged
|
|
2179
|
-
}),
|
|
2180
|
-
children: activeTableData.rlsEnabled ? t("studio_rls_disable_rls") : t("studio_rls_enable_rls")
|
|
2181
|
-
}),
|
|
2182
|
-
/* @__PURE__ */ jsx("div", { className: "h-4 w-px bg-hairline mx-1" }),
|
|
2183
|
-
/* @__PURE__ */ jsx(Button, {
|
|
2184
|
-
variant: "text",
|
|
2185
|
-
size: "small",
|
|
2186
|
-
onClick: fetchRLSData,
|
|
2187
|
-
startIcon: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest }),
|
|
2188
|
-
children: "Refresh"
|
|
2189
|
-
}),
|
|
2190
|
-
/* @__PURE__ */ jsx("div", { className: "h-4 w-px bg-hairline mx-1" }),
|
|
2191
|
-
/* @__PURE__ */ jsx(Button, {
|
|
2192
|
-
size: "small",
|
|
2193
|
-
color: "primary",
|
|
2194
|
-
onClick: () => setEditingPolicy("new"),
|
|
2195
|
-
children: t("studio_rls_create_policy")
|
|
2196
|
-
})
|
|
2197
|
-
] })
|
|
2198
|
-
})]
|
|
2199
|
-
}), isLoading && !activeTableData ? /* @__PURE__ */ jsx("div", {
|
|
2200
|
-
className: "flex-grow flex items-center justify-center h-full",
|
|
2201
|
-
children: /* @__PURE__ */ jsx(CircularProgress, { size: "small" })
|
|
2202
|
-
}) : error ? /* @__PURE__ */ jsx("div", {
|
|
2203
|
-
className: "p-6 h-full flex items-center justify-center",
|
|
2204
|
-
children: /* @__PURE__ */ jsx(ErrorView, {
|
|
2205
|
-
title: t("studio_rls_error"),
|
|
2206
|
-
error,
|
|
2207
|
-
onRetry: fetchRLSData
|
|
2208
|
-
})
|
|
2209
|
-
}) : !activeTableData ? /* @__PURE__ */ jsx("div", {
|
|
2210
|
-
className: "flex-grow flex items-center justify-center text-text-disabled h-full",
|
|
2211
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
2212
|
-
className: "text-center",
|
|
2213
|
-
children: [/* @__PURE__ */ jsx("svg", {
|
|
2214
|
-
className: "w-12 h-12 mx-auto mb-4 opacity-50",
|
|
2215
|
-
fill: "none",
|
|
2216
|
-
stroke: "currentColor",
|
|
2217
|
-
viewBox: "0 0 24 24",
|
|
2218
|
-
children: /* @__PURE__ */ jsx("path", {
|
|
2219
|
-
strokeLinecap: "round",
|
|
2220
|
-
strokeLinejoin: "round",
|
|
2221
|
-
strokeWidth: 1,
|
|
2222
|
-
d: "M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"
|
|
2223
|
-
})
|
|
2224
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
2225
|
-
variant: "body2",
|
|
2226
|
-
children: t("studio_rls_select_table")
|
|
2227
|
-
})]
|
|
2228
|
-
})
|
|
2229
|
-
}) : editingPolicy ? /* @__PURE__ */ jsx(PolicyEditor, {
|
|
2230
|
-
policy: editingPolicy === "new" ? void 0 : editingPolicy,
|
|
2231
|
-
schema: activeTableData.schemaName,
|
|
2232
|
-
table: activeTableData.tableName,
|
|
2233
|
-
roleOptions: pgRoleOptions,
|
|
2234
|
-
onSave: async (newPolicy) => {
|
|
2235
|
-
if (savesToCodebase && activeDescriptor) {
|
|
2236
|
-
if (declaredWithheld) {
|
|
2237
|
-
snackbarController.open({
|
|
2238
|
-
type: "error",
|
|
2239
|
-
message: t("studio_rls_save_needs_schema_read", { table: activeTableData.tableName })
|
|
2240
|
-
});
|
|
2241
|
-
return;
|
|
2242
|
-
}
|
|
2243
|
-
const existingRules = activeDescriptor.rls.rules;
|
|
2244
|
-
let newRules;
|
|
2245
|
-
if (editingPolicy === "new") newRules = [...existingRules, policyToSecurityRule(newPolicy)];
|
|
2246
|
-
else {
|
|
2247
|
-
const edit = applyPolicyEdit(existingRules, editingPolicy, newPolicy);
|
|
2248
|
-
if (!edit.ok) {
|
|
2249
|
-
snackbarController.open({
|
|
2250
|
-
type: "error",
|
|
2251
|
-
message: t(POLICY_EDIT_REFUSALS[edit.reason], { policy: editingPolicy.policyname })
|
|
2252
|
-
});
|
|
2253
|
-
return;
|
|
2254
|
-
}
|
|
2255
|
-
newRules = edit.rules;
|
|
2256
|
-
if (JSON.stringify(newRules) === JSON.stringify(existingRules)) {
|
|
2257
|
-
snackbarController.open({
|
|
2258
|
-
type: "info",
|
|
2259
|
-
message: t("studio_rls_nothing_changed")
|
|
2260
|
-
});
|
|
2261
|
-
return;
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
try {
|
|
2265
|
-
await saveSecurityRules(activeDescriptor, newRules);
|
|
2266
|
-
snackbarController.open({
|
|
2267
|
-
type: "success",
|
|
2268
|
-
message: "Policy saved successfully"
|
|
2269
|
-
});
|
|
2270
|
-
setEditingPolicy(null);
|
|
2271
|
-
fetchRLSData();
|
|
2272
|
-
} catch (e) {
|
|
2273
|
-
reportSaveFailure(e);
|
|
2274
|
-
}
|
|
2275
|
-
} else {
|
|
2276
|
-
if (editingPolicy !== "new" && editingPolicy.generated) {
|
|
2277
|
-
snackbarController.open({
|
|
2278
|
-
type: "error",
|
|
2279
|
-
message: t(POLICY_EDIT_REFUSALS.generated, { policy: editingPolicy.policyname })
|
|
2280
|
-
});
|
|
2281
|
-
return;
|
|
2282
|
-
}
|
|
2283
|
-
try {
|
|
2284
|
-
const qualifiedTable = `${quoteIdentifier(activeTableData.schemaName)}.${quoteIdentifier(activeTableData.tableName)}`;
|
|
2285
|
-
const policyName = quoteIdentifier(newPolicy.policyname || "unnamed_policy");
|
|
2286
|
-
const cmd = newPolicy.cmd || "ALL";
|
|
2287
|
-
const permissive = (newPolicy.permissive || "PERMISSIVE") === "PERMISSIVE" ? "PERMISSIVE" : "RESTRICTIVE";
|
|
2288
|
-
const roles = newPolicy.roles && newPolicy.roles.length > 0 ? newPolicy.roles.map((r) => quoteIdentifier(r)).join(", ") : "public";
|
|
2289
|
-
let sql = `CREATE POLICY ${policyName} ON ${qualifiedTable}`;
|
|
2290
|
-
sql += ` AS ${permissive}`;
|
|
2291
|
-
sql += ` FOR ${cmd}`;
|
|
2292
|
-
sql += ` TO ${roles}`;
|
|
2293
|
-
if (newPolicy.qual) sql += ` USING (${newPolicy.qual})`;
|
|
2294
|
-
if (newPolicy.with_check) sql += ` WITH CHECK (${newPolicy.with_check})`;
|
|
2295
|
-
if (editingPolicy !== "new") sql = `DROP POLICY IF EXISTS ${quoteIdentifier(editingPolicy.policyname)} ON ${qualifiedTable}; DROP POLICY IF EXISTS ${quoteIdentifier(adminRequestPolicyName(editingPolicy.policyname))} ON ${qualifiedTable}; ${sql}`;
|
|
2296
|
-
await databaseAdmin.executeSql(sql);
|
|
2297
|
-
snackbarController.open({
|
|
2298
|
-
type: "success",
|
|
2299
|
-
message: `Policy "${newPolicy.policyname}" applied to the database`
|
|
2300
|
-
});
|
|
2301
|
-
setEditingPolicy(null);
|
|
2302
|
-
fetchRLSData();
|
|
2303
|
-
} catch (e) {
|
|
2304
|
-
snackbarController.open({
|
|
2305
|
-
type: "error",
|
|
2306
|
-
message: e instanceof Error ? e.message : String(e)
|
|
2307
|
-
});
|
|
2308
|
-
}
|
|
2309
|
-
}
|
|
2310
|
-
},
|
|
2311
|
-
onCancel: () => setEditingPolicy(null)
|
|
2312
|
-
}) : /* @__PURE__ */ jsx("div", {
|
|
2313
|
-
className: "flex-grow flex flex-col overflow-hidden",
|
|
2314
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
2315
|
-
className: "p-6 pt-4 flex-grow overflow-auto bg-surface-sheet",
|
|
2316
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
2317
|
-
className: "max-w-4xl mx-auto flex flex-col gap-6",
|
|
2318
|
-
children: [
|
|
2319
|
-
schemaProblem && /* @__PURE__ */ jsx(SchemaSourceProblemAlert, { problem: schemaProblem }),
|
|
2320
|
-
activeTableData && declaredWithheld && /* @__PURE__ */ jsx(Alert, {
|
|
2321
|
-
color: "info",
|
|
2322
|
-
children: /* @__PURE__ */ jsx(Typography, {
|
|
2323
|
-
variant: "caption",
|
|
2324
|
-
children: t("studio_rls_declared_withheld", { table: activeTableData.tableName })
|
|
2325
|
-
})
|
|
2326
|
-
}),
|
|
2327
|
-
activeTableData && activeTableManaged && !savesToCodebase && /* @__PURE__ */ jsx(Alert, {
|
|
2328
|
-
color: "info",
|
|
2329
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
2330
|
-
className: "flex items-start gap-2",
|
|
2331
|
-
children: /* @__PURE__ */ jsx(Typography, {
|
|
2332
|
-
variant: "caption",
|
|
2333
|
-
children: t("studio_rls_reapplied_on_start", { table: activeTableData.tableName })
|
|
2334
|
-
})
|
|
2335
|
-
})
|
|
2336
|
-
}),
|
|
2337
|
-
activeTableData && activeTableCategory === "internal" && /* @__PURE__ */ jsx(Alert, {
|
|
2338
|
-
color: "info",
|
|
2339
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
2340
|
-
className: "flex items-start gap-2",
|
|
2341
|
-
children: /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Typography, {
|
|
2342
|
-
variant: "body2",
|
|
2343
|
-
className: "mb-1 font-semibold",
|
|
2344
|
-
children: "Rebase System Table"
|
|
2345
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
2346
|
-
variant: "caption",
|
|
2347
|
-
className: "opacity-80",
|
|
2348
|
-
children: "This table is managed internally by Rebase. Its security policies are configured automatically. Editing policies on system tables is an advanced operation."
|
|
2349
|
-
})] })
|
|
2350
|
-
})
|
|
2351
|
-
}),
|
|
2352
|
-
activeTableData && activeTableCategory === "junction" && /* @__PURE__ */ jsx(Alert, {
|
|
2353
|
-
color: "info",
|
|
2354
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
2355
|
-
className: "flex items-start gap-2",
|
|
2356
|
-
children: /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Typography, {
|
|
2357
|
-
variant: "body2",
|
|
2358
|
-
className: "mb-1 font-semibold",
|
|
2359
|
-
children: "Junction Table"
|
|
2360
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
2361
|
-
variant: "caption",
|
|
2362
|
-
className: "opacity-80",
|
|
2363
|
-
children: "This is an auto-generated junction table for a many-to-many relation. Rebase derives its policies: rows are readable when both related rows are, and writable following the declaring table's update rules (plus the server/admin baseline). You can still add RLS policies directly to broaden access."
|
|
2364
|
-
})] })
|
|
2365
|
-
})
|
|
2366
|
-
}),
|
|
2367
|
-
activeTableData && !activeTableData.rlsEnabled && /* @__PURE__ */ jsxs("div", {
|
|
2368
|
-
className: cls("p-4 sm:p-5 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-900/50 rounded-lg flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between", defaultBorderMixin),
|
|
2369
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
2370
|
-
className: "flex gap-3 items-start",
|
|
2371
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
2372
|
-
className: "mt-1 bg-yellow-100 dark:bg-yellow-900/50 p-1.5 rounded-md shrink-0 flex items-center justify-center",
|
|
2373
|
-
children: /* @__PURE__ */ jsx(AlertTriangleIcon, { size: iconSize.smallest })
|
|
2374
|
-
}), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Typography, {
|
|
2375
|
-
variant: "subtitle2",
|
|
2376
|
-
className: "text-yellow-800 dark:text-yellow-500",
|
|
2377
|
-
children: "Row Level Security (RLS) is disabled"
|
|
2378
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
2379
|
-
variant: "body2",
|
|
2380
|
-
className: "text-yellow-700 dark:text-yellow-600/90 mt-1 max-w-2xl",
|
|
2381
|
-
children: "Your table is completely readable and writable by anyone with access privileges. Enable RLS to create policies that restrict access to specific rows."
|
|
2382
|
-
})] })]
|
|
2383
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
2384
|
-
size: "medium",
|
|
2385
|
-
variant: "filled",
|
|
2386
|
-
color: "neutral",
|
|
2387
|
-
onClick: () => setEditingPolicy("new"),
|
|
2388
|
-
className: "shrink-0 whitespace-nowrap",
|
|
2389
|
-
disabled: !activeDescriptor,
|
|
2390
|
-
children: t("studio_rls_create_policy")
|
|
2391
|
-
})]
|
|
2392
|
-
}),
|
|
2393
|
-
activeTableData && mergedPolicies && mergedPolicies.length > 0 && /* @__PURE__ */ jsxs("div", {
|
|
2394
|
-
className: "flex flex-col gap-3",
|
|
2395
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
2396
|
-
variant: "subtitle2",
|
|
2397
|
-
className: "text-text-secondary dark:text-text-secondary-dark uppercase tracking-wider mb-1",
|
|
2398
|
-
children: t("studio_rls_policies")
|
|
2399
|
-
}), mergedPolicies.map((policy) => /* @__PURE__ */ jsxs(Paper, {
|
|
2400
|
-
className: cls("p-3 sm:px-4 sm:py-3 flex flex-col sm:flex-row sm:items-center justify-between gap-4 border rounded-lg", defaultBorderMixin),
|
|
2401
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
2402
|
-
className: "flex flex-col gap-2 min-w-0",
|
|
2403
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
2404
|
-
className: "flex items-center gap-2",
|
|
2405
|
-
children: [
|
|
2406
|
-
/* @__PURE__ */ jsx(KeyIcon, {
|
|
2407
|
-
size: iconSize.smallest,
|
|
2408
|
-
className: "text-text-secondary dark:text-text-secondary-dark shrink-0"
|
|
2409
|
-
}),
|
|
2410
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
2411
|
-
variant: "body2",
|
|
2412
|
-
className: "truncate",
|
|
2413
|
-
children: policy.policyname
|
|
2414
|
-
}),
|
|
2415
|
-
policy.status === "code_only" && /* @__PURE__ */ jsx(Tooltip, {
|
|
2416
|
-
title: t("studio_rls_unapplied_tooltip"),
|
|
2417
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
2418
|
-
className: "px-1.5 py-0.5 rounded text-[10px] uppercase bg-primary/10 text-primary border border-primary/20 shrink-0",
|
|
2419
|
-
children: t("studio_rls_unapplied")
|
|
2420
|
-
})
|
|
2421
|
-
}),
|
|
2422
|
-
policy.drift && policy.drift.length > 0 && /* @__PURE__ */ jsx(Tooltip, {
|
|
2423
|
-
title: t("studio_rls_drift_tooltip", { fields: policy.drift.join(", ") }),
|
|
2424
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
2425
|
-
className: "px-1.5 py-0.5 rounded text-xs bg-orange-500/10 text-orange-600 border border-orange-500/20 shrink-0",
|
|
2426
|
-
children: `${t("studio_rls_drift")}: ${policy.drift.join(", ")}`
|
|
2427
|
-
})
|
|
2428
|
-
}),
|
|
2429
|
-
policy.status === "live" && hasCodebase && /* @__PURE__ */ jsx(Tooltip, {
|
|
2430
|
-
title: "This policy is live in the database but missing from your codebase schema.",
|
|
2431
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
2432
|
-
className: "px-1.5 py-0.5 rounded text-[10px] uppercase bg-orange-500/10 text-orange-600 border border-orange-500/20 shrink-0",
|
|
2433
|
-
children: "DB Only"
|
|
2434
|
-
})
|
|
2435
|
-
})
|
|
2436
|
-
]
|
|
2437
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
2438
|
-
className: "flex flex-wrap gap-1.5 text-sm",
|
|
2439
|
-
children: [renderPolicyTag("Action", policy.cmd), renderPolicyTag("Roles", Array.isArray(policy.roles) ? policy.roles.join(", ") : policy.roles)]
|
|
2440
|
-
})]
|
|
2441
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
2442
|
-
className: "flex gap-2 shrink-0 items-center",
|
|
2443
|
-
children: [
|
|
2444
|
-
policy.status === "live" && savesToCodebase && activeDescriptor && !declaredWithheld && /* @__PURE__ */ jsx(Button, {
|
|
2445
|
-
size: "small",
|
|
2446
|
-
variant: "outlined",
|
|
2447
|
-
color: "primary",
|
|
2448
|
-
onClick: async () => {
|
|
2449
|
-
const rule = policyToSecurityRule(policy);
|
|
2450
|
-
const newRules = [...activeDescriptor.rls.rules, rule];
|
|
2451
|
-
try {
|
|
2452
|
-
await saveSecurityRules(activeDescriptor, newRules);
|
|
2453
|
-
snackbarController.open({
|
|
2454
|
-
type: "success",
|
|
2455
|
-
message: "Policy imported successfully"
|
|
2456
|
-
});
|
|
2457
|
-
fetchRLSData();
|
|
2458
|
-
} catch (e) {
|
|
2459
|
-
reportSaveFailure(e);
|
|
2460
|
-
}
|
|
2461
|
-
},
|
|
2462
|
-
children: "Import to codebase"
|
|
2463
|
-
}),
|
|
2464
|
-
/* @__PURE__ */ jsx(Button, {
|
|
2465
|
-
size: "small",
|
|
2466
|
-
variant: "text",
|
|
2467
|
-
color: "primary",
|
|
2468
|
-
onClick: () => setEditingPolicy(policy),
|
|
2469
|
-
children: t("studio_rls_edit")
|
|
2470
|
-
}),
|
|
2471
|
-
policy.status !== "code_only" && /* @__PURE__ */ jsx(Tooltip, {
|
|
2472
|
-
title: t("studio_rls_delete"),
|
|
2473
|
-
asChild: true,
|
|
2474
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
2475
|
-
"aria-label": t("studio_rls_delete"),
|
|
2476
|
-
size: "small",
|
|
2477
|
-
onClick: () => setConfirmDropPolicy({
|
|
2478
|
-
policyName: policy.policyname,
|
|
2479
|
-
table: activeTableData.tableName,
|
|
2480
|
-
schema: activeTableData.schemaName
|
|
2481
|
-
}),
|
|
2482
|
-
children: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest })
|
|
2483
|
-
})
|
|
2484
|
-
})
|
|
2485
|
-
]
|
|
2486
|
-
})]
|
|
2487
|
-
}, policy.policyname))]
|
|
2488
|
-
}),
|
|
2489
|
-
activeTableData && mergedPolicies.length === 0 && activeTableData.rlsEnabled && /* @__PURE__ */ jsxs("div", {
|
|
2490
|
-
className: "flex flex-col items-center justify-center py-12 text-center",
|
|
2491
|
-
children: [
|
|
2492
|
-
/* @__PURE__ */ jsx(ShieldIcon, {
|
|
2493
|
-
size: 40,
|
|
2494
|
-
className: "text-surface-300 dark:text-surface-600 mb-4"
|
|
2495
|
-
}),
|
|
2496
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
2497
|
-
variant: "subtitle2",
|
|
2498
|
-
className: "text-text-secondary dark:text-text-secondary-dark mb-2",
|
|
2499
|
-
children: "No policies defined"
|
|
2500
|
-
}),
|
|
2501
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
2502
|
-
variant: "caption",
|
|
2503
|
-
className: "text-text-disabled dark:text-text-disabled-dark max-w-sm mb-4",
|
|
2504
|
-
children: "RLS is enabled on this table but no policies exist. All access is denied by default (Postgres deny-all). Create a policy to allow specific access."
|
|
2505
|
-
}),
|
|
2506
|
-
/* @__PURE__ */ jsx(Button, {
|
|
2507
|
-
size: "small",
|
|
2508
|
-
variant: "filled",
|
|
2509
|
-
color: "primary",
|
|
2510
|
-
onClick: () => setEditingPolicy("new"),
|
|
2511
|
-
children: t("studio_rls_create_policy")
|
|
2512
|
-
})
|
|
2513
|
-
]
|
|
2514
|
-
}),
|
|
2515
|
-
activeTableData && mergedPolicies.length === 0 && !activeTableData.rlsEnabled && activeDescriptor && /* @__PURE__ */ jsxs("div", {
|
|
2516
|
-
className: "flex flex-col items-center justify-center py-12 text-center",
|
|
2517
|
-
children: [
|
|
2518
|
-
/* @__PURE__ */ jsx(AlertTriangleIcon, {
|
|
2519
|
-
size: 40,
|
|
2520
|
-
className: "text-yellow-400 dark:text-yellow-600 mb-4"
|
|
2521
|
-
}),
|
|
2522
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
2523
|
-
variant: "subtitle2",
|
|
2524
|
-
className: "text-text-secondary dark:text-text-secondary-dark mb-2",
|
|
2525
|
-
children: "No access control"
|
|
2526
|
-
}),
|
|
2527
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
2528
|
-
variant: "caption",
|
|
2529
|
-
className: "text-text-disabled dark:text-text-disabled-dark max-w-sm",
|
|
2530
|
-
children: "This table has neither RLS nor policies. Enable RLS and create policies to restrict row-level access."
|
|
2531
|
-
})
|
|
2532
|
-
]
|
|
2533
|
-
})
|
|
2534
|
-
]
|
|
2535
|
-
})
|
|
2536
|
-
})
|
|
2537
|
-
})]
|
|
2538
|
-
})
|
|
2539
|
-
}),
|
|
2540
|
-
/* @__PURE__ */ jsx(ConfirmationDialog, {
|
|
2541
|
-
open: confirmToggleRls !== null,
|
|
2542
|
-
loading: confirming,
|
|
2543
|
-
onAccept: applyToggleRls,
|
|
2544
|
-
onCancel: () => setConfirmToggleRls(null),
|
|
2545
|
-
title: confirmToggleRls?.enabled ? t("studio_rls_disable_confirm_title") : t("studio_rls_enable_confirm_title"),
|
|
2546
|
-
body: confirmToggleRls?.enabled ? [t("studio_rls_disable_confirm_body", { table: confirmToggleRls.table }), confirmToggleRls.managed ? t("studio_rls_disable_reapplied", { table: confirmToggleRls.table }) : ""].filter(Boolean).join(" ") : t("studio_rls_enable_confirm_body", { table: confirmToggleRls?.table ?? "" })
|
|
2547
|
-
}),
|
|
2548
|
-
/* @__PURE__ */ jsx(ConfirmationDialog, {
|
|
2549
|
-
open: detaching !== null,
|
|
2550
|
-
onAccept: () => answerDetach(true),
|
|
2551
|
-
onCancel: () => answerDetach(false),
|
|
2552
|
-
title: t("schema_rules_detach_title"),
|
|
2553
|
-
body: t("schema_rules_detach_body", { table: detaching ?? "" })
|
|
2554
|
-
}),
|
|
2555
|
-
/* @__PURE__ */ jsx(ConfirmationDialog, {
|
|
2556
|
-
open: confirmDropPolicy !== null,
|
|
2557
|
-
loading: confirming,
|
|
2558
|
-
onAccept: applyDropPolicy,
|
|
2559
|
-
onCancel: () => setConfirmDropPolicy(null),
|
|
2560
|
-
title: t("studio_rls_drop_policy_title"),
|
|
2561
|
-
body: t("studio_rls_drop_policy_body", {
|
|
2562
|
-
policy: confirmDropPolicy?.policyName ?? "",
|
|
2563
|
-
table: confirmDropPolicy?.table ?? ""
|
|
2564
|
-
})
|
|
2565
|
-
})
|
|
2566
|
-
]
|
|
2567
|
-
});
|
|
2568
|
-
};
|
|
2569
|
-
//#endregion
|
|
2570
|
-
export { RLSEditor };
|
|
2571
|
-
|
|
2572
|
-
//# sourceMappingURL=RLSEditor-CTG3jLE7.js.map
|