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:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user