fix: field permissions include inherited fields
This commit is contained in:
parent
49709458bb
commit
e94074c3f3
@ -36,8 +36,9 @@ export const RolesResourcesActions = connect((props) => {
|
|||||||
const form = useForm();
|
const form = useForm();
|
||||||
const roleCollection = useRecord();
|
const roleCollection = useRecord();
|
||||||
const availableActions = useAvailableActions();
|
const availableActions = useAvailableActions();
|
||||||
const { getCollection } = useCollectionManager();
|
const { getCollection, getCollectionFields } = useCollectionManager();
|
||||||
const collection = getCollection(roleCollection.name);
|
const collection = getCollection(roleCollection.name);
|
||||||
|
const collectionFields = getCollectionFields(roleCollection.name);
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const field = useField<ArrayField>();
|
const field = useField<ArrayField>();
|
||||||
@ -50,20 +51,22 @@ export const RolesResourcesActions = connect((props) => {
|
|||||||
return action?.fields?.includes(fieldName);
|
return action?.fields?.includes(fieldName);
|
||||||
};
|
};
|
||||||
const availableActionsWithFields = availableActions.filter((action) => action.allowConfigureFields);
|
const availableActionsWithFields = availableActions.filter((action) => action.allowConfigureFields);
|
||||||
const fieldPermissions = collection?.fields?.filter(field => field.interface)?.map((field) => {
|
const fieldPermissions = collectionFields
|
||||||
const permission = { ...field };
|
?.filter((field) => field.interface)
|
||||||
for (const action of availableActionsWithFields) {
|
?.map((field) => {
|
||||||
permission[action.name] = inAction(action.name, field.name);
|
const permission = { ...field };
|
||||||
}
|
for (const action of availableActionsWithFields) {
|
||||||
return permission;
|
permission[action.name] = inAction(action.name, field.name);
|
||||||
});
|
}
|
||||||
|
return permission;
|
||||||
|
});
|
||||||
const toggleAction = (actionName: string) => {
|
const toggleAction = (actionName: string) => {
|
||||||
if (actionMap[actionName]) {
|
if (actionMap[actionName]) {
|
||||||
delete actionMap[actionName];
|
delete actionMap[actionName];
|
||||||
} else {
|
} else {
|
||||||
actionMap[actionName] = {
|
actionMap[actionName] = {
|
||||||
name: actionName,
|
name: actionName,
|
||||||
fields: collection?.fields?.filter(field => field.interface)?.map?.((item) => item.name),
|
fields: collectionFields?.filter((field) => field.interface)?.map?.((item) => item.name),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
onChange(Object.values(actionMap));
|
onChange(Object.values(actionMap));
|
||||||
@ -79,7 +82,8 @@ export const RolesResourcesActions = connect((props) => {
|
|||||||
};
|
};
|
||||||
const allChecked = {};
|
const allChecked = {};
|
||||||
for (const action of availableActionsWithFields) {
|
for (const action of availableActionsWithFields) {
|
||||||
allChecked[action.name] = collection?.fields?.filter(field => field.interface)?.length === actionMap?.[action.name]?.fields?.length;
|
allChecked[action.name] =
|
||||||
|
collectionFields?.filter((field) => field.interface)?.length === actionMap?.[action.name]?.fields?.length;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -107,7 +111,7 @@ export const RolesResourcesActions = connect((props) => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
dataIndex: 'enabled',
|
dataIndex: 'enabled',
|
||||||
title: t("Allow"),
|
title: t('Allow'),
|
||||||
render: (enabled, action) => (
|
render: (enabled, action) => (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={enabled}
|
checked={enabled}
|
||||||
@ -119,7 +123,7 @@ export const RolesResourcesActions = connect((props) => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
dataIndex: 'scope',
|
dataIndex: 'scope',
|
||||||
title: t("Data scope"),
|
title: t('Data scope'),
|
||||||
render: (value, action) =>
|
render: (value, action) =>
|
||||||
!action.onNewRecord && (
|
!action.onNewRecord && (
|
||||||
<ScopeSelect
|
<ScopeSelect
|
||||||
@ -173,7 +177,7 @@ export const RolesResourcesActions = connect((props) => {
|
|||||||
if (checked) {
|
if (checked) {
|
||||||
item.fields = [];
|
item.fields = [];
|
||||||
} else {
|
} else {
|
||||||
item.fields = collection?.fields?.map?.((item) => item.name);
|
item.fields = collectionFields?.map?.((item) => item.name);
|
||||||
}
|
}
|
||||||
actionMap[action.name] = item;
|
actionMap[action.name] = item;
|
||||||
onChange(Object.values(actionMap));
|
onChange(Object.values(actionMap));
|
||||||
|
Loading…
Reference in New Issue
Block a user