Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: rls update flows

mertmitd168ce3cf8c7
diff --git a/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue b/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue
index 9dc3074f3d..e9448ed0da 100644
--- a/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue
+++ b/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue
@@ -639,6 +639,9 @@ async function clearCell(ctx: { row: number; col: number } | null, skipUpdate =
}
function makeEditable(row: Row, col: ColumnType) {
+ // Row is hidden by RLS policy β€” lock it to prevent edits before it's removed from view
+ if (row.rowMeta?.isRlsHidden) return
+
// If the cell is readonly, return
if (!hasEditPermission.value || editEnabled.value || readOnly.value || isSystemColumn(col) || col.readonly) {
return
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts
index 25228a4ee3..d3a7ebca89 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts
@@ -1338,6 +1338,9 @@ export function useCanvasTable({
if (!row || !column) return null
+ // Row is hidden by RLS policy β€” lock it to prevent edits before it's removed from view
+ if (row.rowMeta?.isRlsHidden) return null
+
if (removeInlineAddRecord.value && row.rowMeta.rowIndex && row.rowMeta.rowIndex >= EXTERNAL_SOURCE_VISIBLE_ROWS) return
const isEditRestricted = column.id && !isAllowed(PermissionEntity.FIELD, column.id, PermissionKey.RECORD_FIELD_EDIT)
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCopyPaste.ts b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCopyPaste.ts
index c4915cb034..bf1a8a92b3 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCopyPaste.ts
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCopyPaste.ts
@@ -398,6 +398,10 @@ export function useCopyPaste({
rowIndex: absoluteRowIndex,
},
}
+
+ // Skip rows hidden by RLS policy β€” they are locked and should not be pasted into
+ if (targetRow.rowMeta?.isRlsHidden) continue
+
updatedRows.push(targetRow)
} else {
targetRow = {
@@ -978,7 +982,7 @@ export function useCopyPaste({
const col = columns.value[ctx.col]
const rowObj = cachedRows.value.get(ctx.row)
- if (!col || !col?.columnObj || !rowObj || !col.isCellEditable || col.isSyncedColumn) return
+ if (!col || !col?.columnObj || !rowObj || !col.isCellEditable || col.isSyncedColumn || rowObj.rowMeta?.isRlsHidden) return
const columnObj = col.columnObj
if (
diff --git a/packages/nc-gui/composables/useExpandedFormStore.ts b/packages/nc-gui/composables/useExpandedFormStore.ts
index a7666ab872..830ff4e4c1 100644
--- a/packages/nc-gui/composables/useExpandedFormStore.ts
+++ b/packages/nc-gui/composables/useExpandedFormStore.ts
@@ -435,7 +435,7 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState(
return message.info(t('msg.info.updateNotAllowedWithoutPK'))
}
- await $api.dbTableRow.update(
+ const updatedData = await $api.dbTableRow.update(
NOCO,
meta.value.base_id ?? (base.value.id as string),
meta.value.id,
@@ -443,6 +443,11 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState(
updateOrInsertObj,
)
+ // If the updated row is now hidden by RLS policy, mark it
+ if (updatedData?.__nc_rls_hidden) {
+ row.value.row.__nc_rls_hidden = true
+ }
+
if (!undo) {
const undoObject = [...changedColumns.value].reduce((obj, col) => {
obj[col] = row.value.oldRow[col]
diff --git a/packages/nc-gui/composables/useGridViewData.ts b/packages/nc-gui/composables/useGridViewData.ts
index ebeb718077..495286118b 100644
--- a/packages/nc-gui/composables/useGridViewData.ts
+++ b/packages/nc-gui/composables/useGridViewData.ts
@@ -529,6 +529,10 @@ export function useGridViewData(
...row.row,
...newRow,
}
+ // Mark row as hidden if it moved out of user's RLS scope after update
+ if (newRow.__nc_rls_hidden) {
+ row.rowMeta.isRlsHidden = true
+ }
dataCache.cachedRows.value.set(rowIndex, row)
}
}
diff --git a/packages/nc-gui/composables/useInfiniteData.ts b/packages/nc-gui/composables/useInfiniteData.ts
index 80fb9dc1e9..89f46d83ba 100644
--- a/packages/nc-gui/composables/useInfiniteData.ts
+++ b/packages/nc-gui/composables/useInfiniteData.ts
@@ -1678,6 +1678,11 @@ export function useInfiniteData(args: {
Object.assign(toUpdate.oldRow, updatedRowData)
Object.assign(toUpdate.rowMeta, getEvaluatedRowMetaRowColorInfo(toUpdate.row))
+ // Mark row as hidden if it moved out of user's RLS scope after update
+ if (updatedRowData?.__nc_rls_hidden) {
+ toUpdate.rowMeta.isRlsHidden = true
+ }
+
// Update the row in cachedRows
if (toUpdate.rowMeta.rowIndex !== undefined) {
dataCache.cachedRows.value.set(toUpdate.rowMeta.rowIndex, toUpdate)
@@ -1725,6 +1730,9 @@ export function useInfiniteData(args: {
throw new Error('Row metadata is missing')
}
+ // Row is hidden by RLS policy β€” skip save to avoid repeated API calls on a row the user can no longer access
+ if (row.rowMeta.isRlsHidden) return
+
const dataCache = getDataCache(path)
row.rowMeta.changed = false