fix(acl): keep empty draft rules and clarify OR/AND hint

Empty rules were stripped on re-parse so Add rule looked broken; editor now keeps drafts until filled.
This commit is contained in:
2026-10-22 12:18:05 +03:30
parent 09a60b3b5a
commit 73c87b8be4
2 changed files with 30 additions and 9 deletions
@@ -10,7 +10,6 @@ import {
DATA_ACCESS_SECTION_LABELS,
DATA_ACCESS_SECTIONS,
emptySectionDataAccess,
parseDataAccessPolicy,
} from '@mento/shared';
import { api } from '@/lib/api';
import { useCustomerGroups } from '@/lib/customer-groups';
@@ -57,15 +56,21 @@ watch(
{ immediate: true },
);
const policy = computed(() => parseDataAccessPolicy(props.modelValue));
/** بدون parse سخت‌گیرانه تا قانون خالیِ در حال ویرایش پاک نشود */
function sectionValue(key: DataAccessSection): SectionDataAccess {
return policy.value[key] ?? emptySectionDataAccess();
const raw = props.modelValue?.[key];
if (raw && typeof raw === 'object') {
return {
mode: raw.mode === 'rules' ? 'rules' : 'all',
rules: Array.isArray(raw.rules) ? raw.rules.map((r) => ({ ...r })) : [],
};
}
return emptySectionDataAccess();
}
function setSection(key: DataAccessSection, next: SectionDataAccess) {
emit('update:modelValue', {
...policy.value,
...props.modelValue,
[key]: next,
});
}