Skip to content

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

feat: insert flows

mertmitcc210ed13a3b
diff --git a/packages/nc-gui/components/smartsheet/expanded-form/index.vue b/packages/nc-gui/components/smartsheet/expanded-form/index.vue
index 137e0997dd..9ab89def20 100644
--- a/packages/nc-gui/components/smartsheet/expanded-form/index.vue
+++ b/packages/nc-gui/components/smartsheet/expanded-form/index.vue
@@ -401,7 +401,11 @@ const save = async () => {
isUnsavedFormExist.value = false
- if (props.closeAfterSave) {
+ // Close expanded form if row is hidden by RLS policy
+ if (_row.value?.row?.__nc_rls_hidden) {
+ message.info('Record saved successfully but is hidden due to your access permissions.')
+ isExpanded.value = false
+ } else if (props.closeAfterSave) {
isExpanded.value = false
} else {
if (isUnsavedDuplicatedRecordExist.value) {
diff --git a/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue b/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue
index d2038ef068..b1690b0a14 100644
--- a/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue
+++ b/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue
@@ -2569,6 +2569,28 @@ const headerFilteredOrSortedClass = (colId: string) => {
</NcTooltip>
</div>
</div>
+ <div
+ v-if="row.rowMeta?.isRlsHidden"
+ :style="{
+ top: `${(index + 1 + placeholderStartRows.length) * rowHeight - 6}px`,
+ zIndex: 100000,
+ }"
+ class="absolute transform z-30 left-0 w-full flex"
+ >
+ <div
+ class="sticky left-0 flex items-center gap-2 transform bg-nc-yellow-500 px-2 py-1 rounded-br-md font-semibold text-xs text-nc-content-gray"
+ >
+ Row hidden
+
+ <NcTooltip>
+ <template #title>
+ This record will be hidden as it does not match your access permissions.
+ </template>
+
+ <GeneralIcon icon="info" class="w-4 h-4 text-nc-content-gray" />
+ </NcTooltip>
+ </div>
+ </div>
<tr
class="nc-grid-row transition-all duration-500 opacity-100 !xs:h-10"
:style="{
@@ -2586,7 +2608,7 @@ const headerFilteredOrSortedClass = (colId: string) => {
activeCell.row === row.rowMeta.rowIndex || selectedRange._start?.row === row.rowMeta.rowIndex,
'mouse-down': isGridCellMouseDown || isFillMode,
'selected-row': row.rowMeta.selected || vSelectedAllRecords,
- 'invalid-row': row.rowMeta?.isValidationFailed || row.rowMeta?.isRowOrderUpdated,
+ 'invalid-row': row.rowMeta?.isValidationFailed || row.rowMeta?.isRowOrderUpdated || row.rowMeta?.isRlsHidden,
'is-dragging': row.rowMeta?.rowIndex === draggingRecord?.rowMeta?.rowIndex,
}"
>
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasRender.ts b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasRender.ts
index 02b81af2d1..0760e1469d 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasRender.ts
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasRender.ts
@@ -1832,7 +1832,7 @@ export function useCanvasRender({
ctx.fill()
}
- if (row?.rowMeta.isValidationFailed || row?.rowMeta.isRowOrderUpdated) {
+ if (row?.rowMeta.isValidationFailed || row?.rowMeta.isRowOrderUpdated || row?.rowMeta.isRlsHidden) {
warningRow = { row, yOffset }
}
@@ -2589,7 +2589,12 @@ export function useCanvasRender({
ctx.lineTo(adjustedWidth + indent, yOffset + rowHeight.value)
ctx.stroke()
- if (row?.rowMeta.isValidationFailed || row?.rowMeta.isRowOrderUpdated || row?.rowMeta.isGroupChanged) {
+ if (
+ row?.rowMeta.isValidationFailed ||
+ row?.rowMeta.isRowOrderUpdated ||
+ row?.rowMeta.isGroupChanged ||
+ row?.rowMeta.isRlsHidden
+ ) {
warningRow = { row, yOffset }
}
diff --git a/packages/nc-gui/composables/useExpandedFormStore.ts b/packages/nc-gui/composables/useExpandedFormStore.ts
index d8498ff156..a7666ab872 100644
--- a/packages/nc-gui/composables/useExpandedFormStore.ts
+++ b/packages/nc-gui/composables/useExpandedFormStore.ts
@@ -497,6 +497,9 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState(
const loadRow = async (rowId?: string, onlyVirtual = false, onlyNewColumns = false) => {
if (row?.value?.rowMeta?.new || isPublic.value || !meta.value?.id) return
+ // Row is hidden by RLS policy β€” skip read to avoid 404
+ if (row?.value?.row?.__nc_rls_hidden) return
+
const recordId = rowId ?? extractPkFromRow(row.value.row, meta.value.columns as ColumnType[])
if (!recordId) return
diff --git a/packages/nc-gui/composables/useInfiniteData.ts b/packages/nc-gui/composables/useInfiniteData.ts
index 1f40dedd40..80fb9dc1e9 100644
--- a/packages/nc-gui/composables/useInfiniteData.ts
+++ b/packages/nc-gui/composables/useInfiniteData.ts
@@ -880,7 +880,7 @@ export function useInfiniteData(args: {
const sortedEntries = Array.from(dataCache.cachedRows.value.entries()).sort(([indexA], [indexB]) => indexA - indexB)
const invalidIndexes = sortedEntries
- .filter(([_, row]) => row.rowMeta.isValidationFailed || row.rowMeta.isGroupChanged)
+ .filter(([_, row]) => row.rowMeta.isValidationFailed || row.rowMeta.isGroupChanged || row.rowMeta.isRlsHidden)
.map(([index]) => index)
if (invalidIndexes.length === 0) return
@@ -1535,6 +1535,7 @@ export function useInfiniteData(args: {
rowIndex: insertIndex,
new: false,
saving: false,
+ isRlsHidden: !!insertedData?.__nc_rls_hidden,
...getEvaluatedRowMetaRowColorInfo({ ...insertedData, ...currentRow.row }),
},
})
diff --git a/packages/nc-gui/lib/types.ts b/packages/nc-gui/lib/types.ts
index e226f0650d..4afd0a4a1c 100644
--- a/packages/nc-gui/lib/types.ts
+++ b/packages/nc-gui/lib/types.ts
@@ -131,6 +131,8 @@ interface Row {
saving?: boolean
ltarState?: Record<string, Record<string, any> | Record<string, any>[] | null>
fromExpandedForm?: boolean
+ // Row is hidden by RLS policy after insert
+ isRlsHidden?: boolean
// use in datetime picker component
isUpdatedFromCopyNPaste?: Record<string, boolean>
// Used in Calendar view
diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts
index 5761705f24..d09a959781 100644
--- a/packages/nocodb/src/db/BaseModelSqlv2.ts
+++ b/packages/nocodb/src/db/BaseModelSqlv2.ts
@@ -256,6 +256,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
extractOnlyPrimaries = false,
apiVersion,
extractOrderColumn = false,
+ ignoreRls = false,
}: {
ignoreView?: boolean;
getHiddenColumn?: boolean;
@@ -263,6 +264,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
extractOnlyPrimaries?: boolean;
apiVersion?: NcApiVersion;
extractOrderColumn?: boolean;
+ ignoreRls?: boolean;
} = {},
): Promise<any> {
const qb = this.dbDriver(this.tnPath);
@@ -296,7 +298,9 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
qb.where(_wherePk(this.model.primaryKeys, id));
// Apply RLS conditions to readByPk
- const rlsConditionsReadByPk = await this.getRlsConditions();
+ const rlsConditionsReadByPk = ignoreRls
+ ? []
+ : await this.getRlsConditions();
if (rlsConditionsReadByPk.length) {
await conditionV2(
this,
@@ -523,6 +527,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
limitOverride?: number;
skipSubstitutingColumnIds?: boolean;
skipSortBasedOnOrderCol?: boolean;
+ ignoreRls?: boolean;
} = {},
): Promise<any> {
const {
@@ -532,6 +537,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
throwErrorIfInvalidParams = false,
limitOverride,
skipSortBasedOnOrderCol = false,
+ ignoreRls: ignoreRlsOpt = false,
} = options;
const columns = await this.model.getColumns(this.context);
@@ -573,7 +579,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
throwErrorIfInvalidParams,
);
// Resolve RLS (Row-Level Security) conditions
- const rlsConditions = await this.getRlsConditions();
+ const rlsConditions = ignoreRlsOpt ? [] : await this.getRlsConditions();
const rlsFilterGroup = rlsConditions.length
? [new Filter({ children: rlsConditions, is_group: true })]
: [];
@@ -2483,6 +2489,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
source: Source;
disableOptimization?: boolean;
view?: View;
+ ignoreRls?: boolean;
}): Promise<any> {
return this.readByPk(
params.idOrRecord,
@@ -2491,6 +2498,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
{
ignoreView: params.ignoreView,
getHiddenColumn: params.getHiddenColumn,
+ ignoreRls: params.ignoreRls,
},
);
}
@@ -2576,6 +2584,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
getHiddenColumn: true,
validateFormula: false,
source,
+ ignoreRls: true,
});
} else if (
!response ||
@@ -2662,9 +2671,19 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
ignoreView: true,
getHiddenColumn: true,
source,
+ ignoreRls: true,
});
}
+ // Check if the inserted row is visible under the user's RLS policy
+ const rlsConditions = await this.getRlsConditions();
+ if (rlsConditions.length && response) {
+ const isVisible = await this.exist(
+ this.extractPksValues(response, true),
+ );
+ if (!isVisible) response.__nc_rls_hidden = true;
+ }
+
await this.afterInsert({
data: response,
trx: this.dbDriver,