Refactor isReadOnly + introduce restrictedFields (#13533)

Closes https://github.com/twentyhq/core-team-issues/issues/1276 

We now need to take fields permissions into account when determining if
a cell is editable or not.

a record field (= a cell) is read only if one of the condition is met:
- the object of the record is read-only (can be determined at table
level) by permission setting
- the field of the object is read-only (can be determined at column
level) - either by permission settings or by system (some workflows
fields for intance)
- the record is deleted (can be determined at row level) 

we reorganized the code to avoid re-computing known information as much
as possible.

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Marie
2025-08-04 18:42:27 +02:00
committed by GitHub
parent 42045667a4
commit 932910e71e
74 changed files with 576 additions and 346 deletions
@@ -92,6 +92,8 @@ const InternalTableContextProviders = ({
recordTableId: objectMetadataItem.namePlural,
viewBarId: 'view-bar',
visibleTableColumns: visibleTableColumns,
objectPermissions:
objectPermissionsByObjectMetadataId[objectMetadataItem.id],
}}
>
<RecordTableBodyContextProvider
@@ -136,7 +136,7 @@ export const getFieldDecorator =
position: 0,
objectMetadataItem,
}),
isReadOnly: false,
isRecordFieldReadOnly: false,
}}
>
<RecordMockSetterEffect
@@ -51,7 +51,7 @@ export const useMockFieldContext = ({
}),
useUpdateRecord: useUpdateOneObjectMutation,
clearable,
isReadOnly: false,
isRecordFieldReadOnly: false,
}}
>
{children}
@@ -136,6 +136,7 @@ export const mockedUserData: MockedUser = {
canUpdateObjectRecords: true,
canSoftDeleteObjectRecords: true,
canDestroyObjectRecords: true,
restrictedFields: {},
})),
},
locale: 'en',
@@ -165,6 +166,7 @@ export const mockedLimitedPermissionsUserData: MockedUser = {
canUpdateObjectRecords: true,
canSoftDeleteObjectRecords: true,
canDestroyObjectRecords: true,
restrictedFields: {},
})),
},
};