Skip to content

Commit 5ca7717

Browse files
fix: editRecord would not correctly check non editable fields (#815)
--------- Co-authored-by: Antoine Hurard <[email protected]>
1 parent 2a5866e commit 5ca7717

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/schema/mutation/editRecord.mutation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ export const hasInaccessibleFields = (
3636
ability: AppAbility
3737
) => {
3838
const oldData = record.data || {};
39-
const k = union(keys(oldData), keys(newData));
40-
const updatedKeys = filter(k, (key) => {
41-
let oldD = get(oldData, key);
42-
let newD = get(newData, key);
39+
const allKeys = union(keys(oldData), keys(newData));
40+
const updatedKeys = filter(allKeys, (key) => {
41+
let previous = get(oldData, key);
42+
let next = get(newData, key);
4343

4444
// check for date objects and convert them to strings
45-
if (oldD instanceof Date) oldD = oldD.toISOString();
46-
if (newD instanceof Date) newD = newD.toISOString();
45+
if (previous instanceof Date) previous = previous.toISOString();
46+
if (next instanceof Date) next = next.toISOString();
4747

48-
return !isEqual(get(oldD, key), get(newD, key));
48+
return !isEqual(previous, next);
4949
});
5050

5151
return updatedKeys.some(

src/security/extendAbilityForRecords.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ function userCanAccessField(
3434
if (field === undefined) return false;
3535
const arrayToCheck = type === 'read' ? 'canSee' : 'canUpdate';
3636

37+
// If the readOnly property of the field is true, ignore the permission check to update the records
38+
if (arrayToCheck === 'canUpdate') {
39+
if (field.readOnly) {
40+
return false;
41+
}
42+
}
43+
3744
// if the user has a role in the array, they should have the permission, return true
3845
// otherwise, return false
3946
return user.roles?.some((role: Role) =>

0 commit comments

Comments
 (0)