Skip to content

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

feat: rls

mertmit6413db712dc4
diff --git a/packages/nc-gui/components/dashboard/TreeView/Table/Node.vue b/packages/nc-gui/components/dashboard/TreeView/Table/Node.vue
index 62691fb4b7..a8ad4bd620 100644
--- a/packages/nc-gui/components/dashboard/TreeView/Table/Node.vue
+++ b/packages/nc-gui/components/dashboard/TreeView/Table/Node.vue
@@ -63,6 +63,7 @@ const source = computed(() => {
const isTableDeleteDialogVisible = ref(false)
const isTablePermissionsDialogVisible = ref(false)
+const isTableRlsDialogVisible = ref(false)
const isOptionsOpen = ref(false)
@@ -282,6 +283,11 @@ async function onPermissions(_table: SidebarTableNode) {
isTablePermissionsDialogVisible.value = true
}
+function onRowLevelSecurity() {
+ isOptionsOpen.value = false
+ isTableRlsDialogVisible.value = true
+}
+
/** Cancel renaming view */
function onCancel() {
if (!isEditing.value) return
@@ -388,6 +394,8 @@ const enabledOptions = computed(() => {
(source.value?.is_meta || source.value?.is_local),
tablePermission:
isEeUI && table.value?.type === 'table' && isUIAllowed('tablePermission', { roles: baseRole?.value, source: source.value }),
+ tableRowLevelSecurity:
+ isEeUI && table.value?.type === 'table' && isUIAllowed('tablePermission', { roles: baseRole?.value, source: source.value }),
tableDelete: isUIAllowed('tableDelete', { roles: baseRole?.value, source: source.value }),
}
})
@@ -608,6 +616,17 @@ const enabledOptions = computed(() => {
</NcMenuItem>
</template>
</PaymentUpgradeBadgeProvider>
+ <NcMenuItem
+ v-if="enabledOptions.tableRowLevelSecurity"
+ :data-testid="`sidebar-table-rls-${table.title}`"
+ class="nc-table-rls"
+ @click="onRowLevelSecurity"
+ >
+ <div v-e="['c:table:rls']" class="flex gap-2 items-center w-full">
+ <GeneralIcon icon="ncShield" class="opacity-80" />
+ <div class="flex-1">Row-Level Security</div>
+ </div>
+ </NcMenuItem>
</template>
<template v-if="enabledOptions.tableDelete">
<NcDivider />
@@ -659,6 +678,12 @@ const enabledOptions = computed(() => {
:table-id="table.id"
:title="table.title"
/>
+ <DlgTableRowLevelSecurity
+ v-if="table.id && isEeUI"
+ v-model:visible="isTableRlsDialogVisible"
+ :table-id="table.id"
+ :title="table.title"
+ />
<DashboardTreeViewViewsList v-if="isExpanded" :table-id="table.id" :base-id="base.id" />
</div>
</template>
diff --git a/packages/nocodb-sdk/src/lib/enums.ts b/packages/nocodb-sdk/src/lib/enums.ts
index 5c05be4169..27652103f4 100644
--- a/packages/nocodb-sdk/src/lib/enums.ts
+++ b/packages/nocodb-sdk/src/lib/enums.ts
@@ -271,6 +271,10 @@ export enum AppEvents {
RECORD_TEMPLATE_UPDATE = 'record.template.update',
RECORD_TEMPLATE_DELETE = 'record.template.delete',
RECORD_TEMPLATE_USE = 'record.template.use',
+
+ RLS_POLICY_CREATE = 'rls_policy.create',
+ RLS_POLICY_UPDATE = 'rls_policy.update',
+ RLS_POLICY_DELETE = 'rls_policy.delete',
}
export enum ClickhouseTables {
diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts
index aea4595a88..5761705f24 100644
--- a/packages/nocodb/src/db/BaseModelSqlv2.ts
+++ b/packages/nocodb/src/db/BaseModelSqlv2.ts
@@ -294,6 +294,17 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
});
qb.where(_wherePk(this.model.primaryKeys, id));
+
+ // Apply RLS conditions to readByPk
+ const rlsConditionsReadByPk = await this.getRlsConditions();
+ if (rlsConditionsReadByPk.length) {
+ await conditionV2(
+ this,
+ [new Filter({ children: rlsConditionsReadByPk, is_group: true })],
+ qb,
+ );
+ }
+
let data;
try {
@@ -395,6 +406,17 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
return false;
}
qb.where(_wherePk(pks, id)).first();
+
+ // Apply RLS conditions to exist check
+ const rlsConditionsExist = await this.getRlsConditions();
+ if (rlsConditionsExist.length) {
+ await conditionV2(
+ this,
+ [new Filter({ children: rlsConditionsExist, is_group: true })],
+ qb,
+ );
+ }
+
return !!(await this.execAndParse(qb, null, { raw: true, first: true }));
}
@@ -423,9 +445,16 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
aliasColObjMap,
);
+ // Resolve RLS conditions for findOne
+ const rlsConditionsFindOne = await this.getRlsConditions();
+ const rlsFilterGroupFindOne = rlsConditionsFindOne.length
+ ? [new Filter({ children: rlsConditionsFindOne, is_group: true })]
+ : [];
+
await conditionV2(
this,
[
+ ...rlsFilterGroupFindOne,
new Filter({
children: args.filterArr || [],
is_group: true,
@@ -543,11 +572,19 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
aliasColObjMap,
throwErrorIfInvalidParams,
);
+ // Resolve RLS (Row-Level Security) conditions
+ const rlsConditions = await this.getRlsConditions();
+ const rlsFilterGroup = rlsConditions.length
+ ? [new Filter({ children: rlsConditions, is_group: true })]
+ : [];
+
// todo: replace with view id
if (!ignoreViewFilterAndSort && this.viewId) {
await conditionV2(
this,
[
+ // RLS filters β€” always first, always applied
+ ...rlsFilterGroup,
...(args.customConditions
? [
new Filter({
@@ -589,6 +626,8 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
await conditionV2(
this,
[
+ // RLS filters β€” always first, always applied
+ ...rlsFilterGroup,
...(args.customConditions
? [
new Filter({
@@ -714,10 +753,17 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
throwErrorIfInvalidParams,
);
+ // Resolve RLS conditions for count
+ const rlsConditionsCount = await this.getRlsConditions();
+ const rlsFilterGroupCount = rlsConditionsCount.length
+ ? [new Filter({ children: rlsConditionsCount, is_group: true })]
+ : [];
+
if (!ignoreViewFilterAndSort && this.viewId) {
await conditionV2(
this,
[
+ ...rlsFilterGroupCount,
...(args.customConditions
? [
new Filter({
@@ -753,6 +799,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
await conditionV2(
this,
[
+ ...rlsFilterGroupCount,
...(args.customConditions
? [
new Filter({
@@ -830,9 +877,16 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
where,
aliasColObjMap,
);
+ // Resolve RLS conditions for groupByAndAggregate
+ const rlsConditionsGBA = await this.getRlsConditions();
+ const rlsFilterGroupGBA = rlsConditionsGBA.length
+ ? [new Filter({ children: rlsConditionsGBA, is_group: true })]
+ : [];
+
await conditionV2(
this,
[
+ ...rlsFilterGroupGBA,
new Filter({
children: filterObj,
is_group: true,
@@ -864,6 +918,17 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
}[],
_view: View,
) {
+ // Prepend RLS conditions to filterArr for bulkGroupByCount
+ const rlsConditionsBGBC = await this.getRlsConditions();
+ if (rlsConditionsBGBC.length) {
+ args = {
+ ...args,
+ filterArr: [
+ new Filter({ children: rlsConditionsBGBC, is_group: true }),
+ ...(args.filterArr || []),
+ ],
+ };
+ }
return await baseModelGroupBy(this, logger).bulkCount(
args,
bulkFilterList,
@@ -887,6 +952,17 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
}[],
_view: View,
) {
+ // Prepend RLS conditions to filterArr for bulkGroupBy
+ const rlsConditionsBGB = await this.getRlsConditions();
+ if (rlsConditionsBGB.length) {
+ args = {
+ ...args,
+ filterArr: [
+ new Filter({ children: rlsConditionsBGB, is_group: true }),
+ ...(args.filterArr || []),
+ ],
+ };
+ }
return await baseModelGroupBy(this, logger).bulkList(
args,
bulkFilterList,
@@ -999,6 +1075,12 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
});
}
+ // Resolve RLS conditions for bulkAggregate
+ const rlsConditionsBulkAgg = await this.getRlsConditions();
+ const rlsFilterGroupBulkAgg = rlsConditionsBulkAgg.length
+ ? [new Filter({ children: rlsConditionsBulkAgg, is_group: true })]
+ : [];
+
const selectors = [] as Array<Knex.Raw>;
// Generate a knex raw query for each filter in the bulkFilterList
for (const f of bulkFilterList) {
@@ -1016,6 +1098,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
await conditionV2(
this,
[
+ ...rlsFilterGroupBulkAgg,
...(this.viewId
? [
new Filter({
@@ -1176,9 +1259,16 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
where,
aliasColObjMap,
);
+ // Resolve RLS conditions for aggregate
+ const rlsConditionsAgg = await this.getRlsConditions();
+ const rlsFilterGroupAgg = rlsConditionsAgg.length
+ ? [new Filter({ children: rlsConditionsAgg, is_group: true })]
+ : [];
+
await conditionV2(
this,
[
+ ...rlsFilterGroupAgg,
...(this.viewId
? [
new Filter({
@@ -1262,6 +1352,17 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
sortArr?: Sort[];
minCount?: number; // Minimum count for groups (e.g., 2 to get only duplicates)
}) {
+ // Prepend RLS conditions to filterArr for groupBy
+ const rlsConditionsGB = await this.getRlsConditions();
+ if (rlsConditionsGB.length) {
+ args = {
+ ...args,
+ filterArr: [
+ new Filter({ children: rlsConditionsGB, is_group: true }),
+ ...(args.filterArr || []),
+ ],
+ };
+ }
return await baseModelGroupBy(this, logger).list(args);
}
@@ -1273,6 +1374,17 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
filterArr?: Filter[];
minCount?: number; // Minimum count for groups (e.g., 2 to get only duplicates)
}) {
+ // Prepend RLS conditions to filterArr for groupByCount
+ const rlsConditionsGBC = await this.getRlsConditions();
+ if (rlsConditionsGBC.length) {
+ args = {
+ ...args,
+ filterArr: [
+ new Filter({ children: rlsConditionsGBC, is_group: true }),
+ ...(args.filterArr || []),
+ ],
+ };
+ }
return await baseModelGroupBy(this, logger).count(args);
}
@@ -3358,7 +3470,14 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
true,
);
+ // Resolve RLS conditions for bulkUpdateAll
+ const rlsConditionsBUA = await this.getRlsConditions();
+ const rlsFilterGroupBUA = rlsConditionsBUA.length
+ ? [new Filter({ children: rlsConditionsBUA, is_group: true })]
+ : [];
+
const conditionObj = [
+ ...rlsFilterGroupBUA,
new Filter({
children: args.filterArr || [],
is_group: true,
@@ -4889,11 +5008,18 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
where,
aliasColObjMap,
);
+ // Resolve RLS conditions for groupedList
+ const rlsConditionsGL = await this.getRlsConditions();
+ const rlsFilterGroupGL = rlsConditionsGL.length
+ ? [new Filter({ children: rlsConditionsGL, is_group: true })]
+ : [];
+
// todo: replace with view id
if (!args.ignoreViewFilterAndSort && this.viewId) {
await conditionV2(
this,
[
+ ...rlsFilterGroupGL,
new Filter({
children:
(await Filter.rootFilterList(this.context, {
@@ -4925,6 +5051,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
await conditionV2(
this,
[
+ ...rlsFilterGroupGL,
new Filter({
children: args.filterArr || [],
is_group: true,
@@ -5051,12 +5178,19 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
args.where,
aliasColObjMap,
);
+ // Resolve RLS conditions for groupedListCount
+ const rlsConditionsGLC = await this.getRlsConditions();
+ const rlsFilterGroupGLC = rlsConditionsGLC.length
+ ? [new Filter({ children: rlsConditionsGLC, is_group: true })]
+ : [];
+
// todo: replace with view id
if (!args.ignoreViewFilterAndSort && this.viewId) {
await conditionV2(
this,
[
+ ...rlsFilterGroupGLC,
new Filter({
children:
(await Filter.rootFilterList(this.context, {
@@ -5081,6 +5215,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
await conditionV2(
this,
[
+ ...rlsFilterGroupGLC,
new Filter({
children: args.filterArr || [],
is_group: true,
@@ -7293,6 +7428,15 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
user: any;
req: any;
}) {}
+
+ /**
+ * Returns RLS (Row-Level Security) filter conditions for the current user.
+ * CE version: no-op, returns empty array (no RLS).
+ * EE version: resolves applicable policies and returns filter conditions.
+ */
+ public async getRlsConditions(): Promise<Filter[]> {
+ return [];
+ }
}
export { BaseModelSqlv2 };
diff --git a/packages/nocodb/src/db/BaseModelSqlv2/delete.ts b/packages/nocodb/src/db/BaseModelSqlv2/delete.ts
index d39336ba06..2491bd8ac9 100644
--- a/packages/nocodb/src/db/BaseModelSqlv2/delete.ts
+++ b/packages/nocodb/src/db/BaseModelSqlv2/delete.ts
@@ -75,9 +75,16 @@ export class BaseModelDelete {
true,
);
+ // Resolve RLS conditions for bulkDeleteAll
+ const rlsConditionsBDA = await this.baseModel.getRlsConditions();
+ const rlsFilterGroupBDA = rlsConditionsBDA.length
+ ? [new Filter({ children: rlsConditionsBDA, is_group: true })]
+ : [];
+
await conditionV2(
this.baseModel,
[
+ ...rlsFilterGroupBDA,
new Filter({
children: args.filterArr || [],
is_group: true,
diff --git a/packages/nocodb/src/meta/migrations/XcMigrationSourcev0.ts b/packages/nocodb/src/meta/migrations/XcMigrationSourcev0.ts
index 7543176fd7..fbb25ef767 100644
--- a/packages/nocodb/src/meta/migrations/XcMigrationSourcev0.ts
+++ b/packages/nocodb/src/meta/migrations/XcMigrationSourcev0.ts
@@ -20,6 +20,7 @@ import * as nc_019_sandboxes from './v0/nc_019_sandboxes';
import * as nc_020_add_cell_coloring_fields_to_row_color_conditions from './v0/nc_020_add_cell_coloring_fields_to_row_color_conditions';
import * as nc_021_scim_support from './v0/nc_021_scim_support';
import * as nc_022_record_templates from './v0/nc_022_record_templates';
+import * as nc_023_rls_policies from './v0/nc_023_rls_policies';
// Create a custom migration source class
export default class XcMigrationSourcev0 {
@@ -51,6 +52,7 @@ export default class XcMigrationSourcev0 {
'nc_020_add_cell_coloring_fields_to_row_color_conditions',
'nc_021_scim_support',
'nc_022_record_templates',
+ 'nc_023_rls_policies',
]);
}
@@ -104,6 +106,8 @@ export default class XcMigrationSourcev0 {
return nc_021_scim_support;
case 'nc_022_record_templates':
return nc_022_record_templates;
+ case 'nc_023_rls_policies':
+ return nc_023_rls_policies;
}
}
}
diff --git a/packages/nocodb/src/meta/migrations/v0/nc_023_rls_policies.ts b/packages/nocodb/src/meta/migrations/v0/nc_023_rls_policies.ts
new file mode 100644
index 0000000000..7c57d03d99
--- /dev/null
+++ b/packages/nocodb/src/meta/migrations/v0/nc_023_rls_policies.ts
@@ -0,0 +1,69 @@
+import type { Knex } from 'knex';
+import { MetaTable } from '~/utils/globals';
+
+const up = async (knex: Knex) => {
+ // Create nc_rls_policies table
+ await knex.schema.createTable(MetaTable.RLS_POLICIES, (table) => {
+ table.string('id', 20).notNullable();
+ table.string('base_id', 20).notNullable();
+ table.string('source_id', 20);
+ table.string('fk_model_id', 20).notNullable();
+ table.string('title', 255);
+ table.boolean('enabled').defaultTo(true);
+ table.boolean('is_default').defaultTo(false);
+ table.string('default_behavior', 20); // 'show_all', 'deny_all', 'condition'
+ table.float('order');
+ table.text('meta');
+ table.string('created_by', 20);
+ table.timestamps(true, true);
+
+ // Primary key
+ table.primary(['base_id', 'id'], 'nc_rls_policies_pk');
+
+ // Indexes
+ table.index(['fk_model_id', 'enabled'], 'nc_rls_policies_model_enabled_idx');
+ table.index(['fk_model_id', 'is_default'], 'nc_rls_policies_model_default_idx');
+ });
+
+ // Create nc_rls_policy_subjects table (mirrors nc_permission_subjects pattern)
+ await knex.schema.createTable(MetaTable.RLS_POLICY_SUBJECTS, (table) => {
+ table.string('fk_rls_policy_id', 20).notNullable();
+ table.string('subject_type', 255).notNullable(); // 'user', 'team', 'role'
+ table.string('subject_id', 255).notNullable(); // User ID, team ID, or role string
+ table.string('fk_workspace_id', 20);
+ table.string('base_id', 20);
+ table.timestamps(true, true);
+
+ // Primary key (composite β€” prevents duplicate assignments)
+ table.primary(
+ ['fk_rls_policy_id', 'subject_type', 'subject_id'],
+ 'nc_rls_policy_subjects_pk',
+ );
+
+ // Index for context-based lookups
+ table.index(
+ ['fk_workspace_id', 'base_id'],
+ 'nc_rls_policy_subjects_context_idx',
+ );
+ });
+
+ // Extend existing filter table with fk_rls_policy_id
+ await knex.schema.alterTable(MetaTable.FILTER_EXP, (table) => {
+ table.string('fk_rls_policy_id', 20);
+ table.index(['fk_rls_policy_id'], 'nc_filter_exp_rls_policy_idx');
+ });
+};
+
+const down = async (knex: Knex) => {
+ // Remove fk_rls_policy_id from filter table
+ await knex.schema.alterTable(MetaTable.FILTER_EXP, (table) => {
+ table.dropIndex(['fk_rls_policy_id'], 'nc_filter_exp_rls_policy_idx');
+ table.dropColumn('fk_rls_policy_id');
+ });
+
+ // Drop tables in reverse order
+ await knex.schema.dropTableIfExists(MetaTable.RLS_POLICY_SUBJECTS);
+ await knex.schema.dropTableIfExists(MetaTable.RLS_POLICIES);
+};
+
+export { up, down };
diff --git a/packages/nocodb/src/models/Filter.ts b/packages/nocodb/src/models/Filter.ts
index 34ddba9d78..b9279fb402 100644
--- a/packages/nocodb/src/models/Filter.ts
+++ b/packages/nocodb/src/models/Filter.ts
@@ -35,6 +35,7 @@ export default class Filter implements FilterType {
fk_row_color_condition_id: string;
fk_link_col_id?: string;
fk_value_col_id?: string;
+ fk_rls_policy_id?: string;
comparison_op?: (typeof COMPARISON_OPS)[number];
comparison_sub_op?: (typeof COMPARISON_SUB_OPS)[number];
@@ -99,6 +100,7 @@ export default class Filter implements FilterType {
'fk_value_col_id',
'fk_parent_column_id',
'fk_row_color_condition_id',
+ 'fk_rls_policy_id',
'fk_column_id',
'comparison_op',
'comparison_sub_op',
@@ -119,6 +121,7 @@ export default class Filter implements FilterType {
'fk_hook_id',
'fk_row_color_condition_id',
'fk_link_col_id',
+ 'fk_rls_policy_id',
].find((k) => filter[k]);
insertObj.order = await ncMeta.metaGetNextOrder(MetaTable.FILTER_EXP, {
[referencedModelColName]: filter[referencedModelColName],
@@ -281,6 +284,20 @@ export default class Filter implements FilterType {
),
);
}
+ if (filter.fk_rls_policy_id) {
+ p.push(
+ NocoCache.appendToList(
+ context,
+ CacheScope.FILTER_EXP,
+ [
+ FilterCacheScope.RLS_POLICY,
+ filter.fk_rls_policy_id,
+ filter.fk_parent_id,
+ ],
+ key,
+ ),
+ );
+ }
p.push(
NocoCache.appendToList(
context,
@@ -300,6 +317,16 @@ export default class Filter implements FilterType {
),
);
}
+ if (filter.fk_rls_policy_id) {
+ p.push(
+ NocoCache.appendToList(
+ context,
+ CacheScope.FILTER_EXP,
+ [FilterCacheScope.RLS_POLICY, filter.fk_rls_policy_id],
+ key,
+ ),
+ );
+ }
await Promise.all(p);
});
}
@@ -546,19 +573,21 @@ export default class Filter implements FilterType {
linkColId,
parentColId,
widgetId,
+ rlsPolicyId,
}: {
viewId?: string;
hookId?: string;
linkColId?: string;
parentColId?: string;
widgetId?: string;
+ rlsPolicyId?: string;
},
ncMeta = Noco.ncMeta,
): Promise<FilterType> {
const cachedList = await NocoCache.getList(
context,
CacheScope.FILTER_EXP,
- [parentColId || viewId || hookId || linkColId || widgetId],
+ [parentColId || viewId || hookId || linkColId || widgetId || rlsPolicyId],
{
key: 'order',
},
@@ -578,6 +607,8 @@ export default class Filter implements FilterType {
condition.fk_parent_column_id = parentColId;
} else if (widgetId) {
condition.fk_widget_id = widgetId;
+ } else if (rlsPolicyId) {
+ condition.fk_rls_policy_id = rlsPolicyId;
}
filters = await ncMeta.metaList2(
@@ -604,6 +635,8 @@ export default class Filter implements FilterType {
filterCacheScope = FilterCacheScope.LINK_COL;
} else if (widgetId) {
filterCacheScope = FilterCacheScope.WIDGET;
+ } else if (rlsPolicyId) {
+ filterCacheScope = FilterCacheScope.RLS_POLICY;
}
await NocoCache.setList(
@@ -741,6 +774,37 @@ export default class Filter implements FilterType {
await deleteRecursively(filter);
}
+ static async deleteAllByRlsPolicy(
+ context: NcContext,
+ rlsPolicyId: string,
+ ncMeta = Noco.ncMeta,
+ ) {
+ const filter = await this.getFilterObject(
+ context,
+ { rlsPolicyId },
+ ncMeta,
+ );
+
+ const deleteRecursively = async (filter) => {
+ if (!filter) return;
+ for (const f of filter?.children || []) await deleteRecursively(f);
+ if (filter.id) {
+ await ncMeta.metaDelete(
+ context.workspace_id,
+ context.base_id,
+ MetaTable.FILTER_EXP,
+ filter.id,
+ );
+ await NocoCache.deepDel(
+ context,
+ `${CacheScope.FILTER_EXP}:${filter.id}`,
+ CacheDelDirection.CHILD_TO_PARENT,
+ );
+ }
+ };
+ await deleteRecursively(filter);
+ }
+
static async deleteAllByParentColumn(
context: NcContext,
parentColId: string,
@@ -936,6 +1000,43 @@ export default class Filter implements FilterType {
?.map((f) => this.castType(f));
}
+ static async rootFilterListByRlsPolicy(
+ context: NcContext,
+ { rlsPolicyId }: { rlsPolicyId: string },
+ ncMeta = Noco.ncMeta,
+ ) {
+ const cachedList = await NocoCache.getList(
+ context,
+ CacheScope.FILTER_EXP,
+ [FilterCacheScope.RLS_POLICY, rlsPolicyId],
+ { key: 'order' },
+ );
+ let { list: filterObjs } = cachedList;
+ const { isNoneList } = cachedList;
+ if (!isNoneList && !filterObjs.length) {
+ filterObjs = await ncMeta.metaList2(
+ context.workspace_id,
+ context.base_id,
+ MetaTable.FILTER_EXP,
+ {
+ condition: { fk_rls_policy_id: rlsPolicyId },
+ orderBy: {
+ order: 'asc',
+ },
+ },
+ );
+ await NocoCache.setList(
+ context,
+ CacheScope.FILTER_EXP,
+ [FilterCacheScope.RLS_POLICY, rlsPolicyId],
+ filterObjs,
+ );
+ }
+ return filterObjs
+ ?.filter((f) => !f.fk_parent_id)
+ ?.map((f) => this.castType(f));
+ }
+
static async rootFilterListByParentColumn(
context: NcContext,
{ parentColId }: { parentColId: string },
diff --git a/packages/nocodb/src/utils/globals.ts b/packages/nocodb/src/utils/globals.ts
index 17bc070045..a62b80c22a 100644
--- a/packages/nocodb/src/utils/globals.ts
+++ b/packages/nocodb/src/utils/globals.ts
@@ -112,6 +112,8 @@ export enum MetaTable {
SANDBOXES = 'nc_sandboxes_v2',
SCIM_CONFIG = 'nc_scim_config',
RECORD_TEMPLATES = 'nc_record_templates',
+ RLS_POLICIES = 'nc_rls_policies',
+ RLS_POLICY_SUBJECTS = 'nc_rls_policy_subjects',
}
export const BaseRelatedMetaTables = [
@@ -151,6 +153,8 @@ export const BaseRelatedMetaTables = [
MetaTable.MODELS,
MetaTable.PERMISSIONS,
MetaTable.PERMISSION_SUBJECTS,
+ MetaTable.RLS_POLICIES,
+ MetaTable.RLS_POLICY_SUBJECTS,
MetaTable.ROW_COLOR_CONDITIONS,
MetaTable.SORT,
MetaTable.SOURCES,
@@ -342,6 +346,7 @@ export enum CacheScope {
SANDBOX = 'sandbox',
SCIM_CONFIG = 'scimConfig',
RECORD_TEMPLATE = 'recordTemplate',
+ RLS_POLICY = 'rlsPolicy',
}
export enum CacheGetType {
@@ -434,6 +439,7 @@ export enum FilterCacheScope {
LINK_COL = 'linkCol',
WIDGET = 'widget',
PARENT = 'parent',
+ RLS_POLICY = 'rlsPolicy',
}
export const NC_STORE_DEFAULT_WORKSPACE_ID_KEY = 'NC_DEFAULT_WORKSPACE_ID';