fix: add isCreator role by default when creating new role

This commit is contained in:
kasia.oczkowska
2024-10-11 15:18:24 +01:00
parent fac4339207
commit 7885de36a9
5 changed files with 79 additions and 21 deletions

View File

@@ -45,3 +45,36 @@ export function getPermissions(computedPermissions) {
[],
);
}
export const getComputedPermissionsDefaultValues = (
data,
conditionsInitialValues,
) => {
if (!data) return {};
const conditions = {};
data.conditions.forEach((condition) => {
conditions[condition.key] =
conditionsInitialValues?.[condition.key] || false;
});
const result = {};
data.subjects.forEach((subject) => {
const subjectKey = subject.key;
result[subjectKey] = {};
data.actions.forEach((action) => {
const actionKey = action.key;
if (action.subjects.includes(subjectKey)) {
result[subjectKey][actionKey] = {
value: false,
conditions: { ...conditions },
};
}
});
});
return result;
};