add permissions and fix issues

This commit is contained in:
Marshal
2026-07-23 20:24:20 +00:00
parent 40f16f3cec
commit 668b5e1c9d
40 changed files with 18634 additions and 342 deletions

View File

@@ -150,9 +150,20 @@ const RuleEngineResourcePage = () => {
const canView = Boolean(
config && canAccessRuleEngineResource(user, config.slug, "view"),
);
const canManage = Boolean(
config && canAccessRuleEngineResource(user, config.slug, "manage"),
// Per-action gates replace the retired coarse "manage": Add shows only with
// create, row Edit with update, row Delete with delete.
const canCreate = Boolean(
config && canAccessRuleEngineResource(user, config.slug, "create"),
);
const canUpdate = Boolean(
config && canAccessRuleEngineResource(user, config.slug, "update"),
);
const canDelete = Boolean(
config && canAccessRuleEngineResource(user, config.slug, "delete"),
);
// Update-class controls (reorder, rate submit/approve, approval-rule decide)
// all map to the update permission — the matching endpoints now require it.
const canUpdateControls = canUpdate;
const listParams = useMemo(
() => ({
@@ -480,7 +491,7 @@ const RuleEngineResourcePage = () => {
cell: ({ row }) => (
<div onClick={(e) => e.stopPropagation()} data-stop-row-click>
<Group gap="xs" wrap="nowrap" justify="flex-end">
{config.orderConfig && canManage ? (
{config.orderConfig && canUpdateControls ? (
<RuleEngineOrderControls
record={row.original}
orderConfig={config.orderConfig}
@@ -493,7 +504,7 @@ const RuleEngineResourcePage = () => {
record={row.original}
config={config}
layout="row"
readOnly={!canManage}
readOnly={!canUpdateControls}
onEdit={(record) => {
setEditing(record);
setFormOpen(true);
@@ -504,8 +515,8 @@ const RuleEngineResourcePage = () => {
? () => setChainOpen(true)
: undefined
}
onSubmitRate={canManage ? (id) => submit.mutate(id) : undefined}
onApproveRate={canManage ? handleApproveRate : undefined}
onSubmitRate={canUpdateControls ? (id) => submit.mutate(id) : undefined}
onApproveRate={canUpdateControls ? handleApproveRate : undefined}
/>
</Group>
</div>
@@ -514,7 +525,7 @@ const RuleEngineResourcePage = () => {
return base;
}, [
canManage,
canUpdateControls,
config,
isRates,
pendingByRateId,
@@ -642,7 +653,7 @@ const RuleEngineResourcePage = () => {
title={config.label}
subtitle={config.subtitle}
action={
canManage && config.slug !== "container-types" ? (
canCreate && config.slug !== "container-types" ? (
<Button leftSection={<Plus size={18} />} onClick={openCreate}>
{addLabel}
</Button>
@@ -653,7 +664,7 @@ const RuleEngineResourcePage = () => {
{isPriorityRules ? (
<PriorityRuleApprovalsSection
requests={priorityWorkflow.pending.data ?? []}
canDecide={canManage}
canDecide={canUpdateControls}
approve={priorityWorkflow.approve}
reject={priorityWorkflow.reject}
/>
@@ -742,7 +753,7 @@ const RuleEngineResourcePage = () => {
showSearch={Boolean(config.supportsSearch)}
searchPlaceholder={config.searchPlaceholder}
onManageOrder={
canManage && config.orderConfig
canUpdateControls && config.orderConfig
? () => setOrderDialogOpen(true)
: undefined
}
@@ -806,16 +817,16 @@ const RuleEngineResourcePage = () => {
pageCount={pageCount}
totalCount={totalCount}
onPaginationChange={setPagination}
readOnly={!canManage}
onEdit={canManage ? openEdit : undefined}
onDelete={canManage ? setDeleteTarget : undefined}
readOnly={!canUpdate && !canDelete}
onEdit={canUpdate ? openEdit : undefined}
onDelete={canDelete ? setDeleteTarget : undefined}
onViewChain={
config.slug === "approval-rules"
? () => setChainOpen(true)
: undefined
}
onSubmitRate={canManage ? (id) => submit.mutate(id) : undefined}
onApproveRate={canManage ? handleApproveRate : undefined}
onSubmitRate={canUpdateControls ? (id) => submit.mutate(id) : undefined}
onApproveRate={canUpdateControls ? handleApproveRate : undefined}
/>
)}
</Stack>