Skip to content

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

feat: rls mvp

mertmit35918d0df571
diff --git a/packages/nc-gui/components/dashboard/TreeView/Table/Node.vue b/packages/nc-gui/components/dashboard/TreeView/Table/Node.vue
index a8ad4bd620..42155c7fb9 100644
--- a/packages/nc-gui/components/dashboard/TreeView/Table/Node.vue
+++ b/packages/nc-gui/components/dashboard/TreeView/Table/Node.vue
@@ -395,7 +395,7 @@ const enabledOptions = computed(() => {
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 }),
+ isEeUI && table.value?.type === 'table' && isUIAllowed('rlsManage', { roles: baseRole?.value, source: source.value }),
tableDelete: isUIAllowed('tableDelete', { roles: baseRole?.value, source: source.value }),
}
})
diff --git a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue
index 2b4bd0a7b7..0e4a4e548c 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue
@@ -15,6 +15,7 @@ interface Props {
parentId?: string
autoSave: boolean
hookId?: string
+ rlsPolicyId?: string
widgetId?: string
showLoading?: boolean
modelValue?: FilterType[] | null
@@ -47,6 +48,7 @@ const props = withDefaults(defineProps<Props>(), {
showLoading: true,
parentId: undefined,
hookId: undefined,
+ rlsPolicyId: undefined,
widgetId: undefined,
widget: false,
webHook: false,
@@ -91,6 +93,7 @@ const {
parentId,
autoSave,
hookId,
+ rlsPolicyId,
widgetId,
showLoading,
webHook,
@@ -326,6 +329,7 @@ watch(
)
loadFilters({
hookId: hookId.value,
+ rlsPolicyId: rlsPolicyId?.value,
isWebhook: webHook.value,
widgetId: widgetId.value,
isWidget: widget.value,
@@ -394,6 +398,8 @@ const applyChanges = async (hookOrColId?: string, nested = false, isConditionSup
if (link.value) {
if (!hookOrColId && !props.nestedLevel) return
await sync({ linkId: hookOrColId, nested })
+ } else if (rlsPolicyId?.value) {
+ await sync({ rlsPolicyId: rlsPolicyId.value, nested })
} else {
await sync({ hookId: hookOrColId, nested })
}
@@ -568,6 +574,7 @@ onMounted(async () => {
if (!props.isTempFilters && !initialModelValue?.length)
await loadFilters({
hookId: hookId?.value,
+ rlsPolicyId: rlsPolicyId?.value,
isWebhook: webHook.value,
isWidget: widget.value,
widgetId: widgetId.value,
diff --git a/packages/nc-gui/composables/useRlsPolicies.ts b/packages/nc-gui/composables/useRlsPolicies.ts
new file mode 100644
index 0000000000..24db8def91
--- /dev/null
+++ b/packages/nc-gui/composables/useRlsPolicies.ts
@@ -0,0 +1,41 @@
+// CE stub β€” no-op for Row-Level Security
+// EE override at ee/composables/useRlsPolicies.ts provides full implementation
+
+import type { BaseType, RlsDefaultBehavior, RlsPolicySubjectType, RlsPolicyType } from 'nocodb-sdk'
+
+export const useRlsPolicies = (_base: Ref<BaseType | null>, _tableId: Ref<string>) => {
+ const policies = ref<RlsPolicyType[]>([])
+ const isLoading = ref(false)
+ const isSaving = ref(false)
+
+ const loadPolicies = async () => {}
+ const createPolicy = async (_body: {
+ fk_model_id: string
+ title?: string
+ is_default?: boolean
+ default_behavior?: RlsDefaultBehavior
+ subjects?: RlsPolicySubjectType[]
+ }) => null
+ const updatePolicy = async (_body: {
+ id: string
+ title?: string
+ enabled?: boolean
+ default_behavior?: RlsDefaultBehavior
+ order?: number
+ }) => null
+ const deletePolicy = async (_policyId: string) => {}
+ const setSubjects = async (_policyId: string, _subjects: RlsPolicySubjectType[]) => null
+ const togglePolicy = async (_policy: RlsPolicyType) => {}
+
+ return {
+ policies,
+ isLoading,
+ isSaving,
+ loadPolicies,
+ createPolicy,
+ updatePolicy,
+ deletePolicy,
+ setSubjects,
+ togglePolicy,
+ }
+}
diff --git a/packages/nc-gui/composables/useViewFilters.ts b/packages/nc-gui/composables/useViewFilters.ts
index e60d13a6a2..1aedc653f6 100644
--- a/packages/nc-gui/composables/useViewFilters.ts
+++ b/packages/nc-gui/composables/useViewFilters.ts
@@ -371,6 +371,7 @@ export function useViewFilters(
const loadFilters = async ({
hookId,
+ rlsPolicyId,
isLink,
widgetId,
isWebhook,
@@ -378,6 +379,7 @@ export function useViewFilters(
loadAllFilters,
}: {
hookId?: string
+ rlsPolicyId?: string
widgetId?: string
isWebhook?: boolean
isWidget?: boolean
@@ -389,14 +391,33 @@ export function useViewFilters(
await until(meta).toBeTruthy({ timeout: 5000 })
}
- if (!view.value?.id || !meta.value) return
- if ((nestedMode.value && (isTemp.value || !canListFilterChildren.value)) || (isForm.value && !isWebhook) || isWorkflow) {
- // ignore restoring if not root filter group
- return
+ // RLS policy filters don't require a view
+ if (!rlsPolicyId) {
+ if (!view.value?.id || !meta.value) return
+ if ((nestedMode.value && (isTemp.value || !canListFilterChildren.value)) || (isForm.value && !isWebhook) || isWorkflow) {
+ // ignore restoring if not root filter group
+ return
+ }
}
try {
- if (isWebhook || hookId) {
+ if (rlsPolicyId) {
+ if (parentId.value) {
+ filters.value = (
+ await $api.internal.getOperation(apiWorkspaceId.value!, apiBaseId.value!, {
+ operation: 'filterChildrenList',
+ filterId: parentId.value,
+ })
+ ).list as ColumnFilterType[]
+ } else if (!isNestedRoot) {
+ filters.value = (
+ await $api.internal.getOperation(apiWorkspaceId.value!, apiBaseId.value!, {
+ operation: 'rlsPolicyFilterList',
+ rlsPolicyId,
+ })
+ ).list as ColumnFilterType[]
+ }
+ } else if (isWebhook || hookId) {
if (parentId.value) {
filters.value = (
await $api.internal.getOperation(apiWorkspaceId.value!, apiBaseId.value!, {
@@ -480,10 +501,12 @@ export function useViewFilters(
const sync = async ({
hookId,
+ rlsPolicyId,
linkId,
widgetId,
}: {
hookId?: string
+ rlsPolicyId?: string
nested?: boolean
linkId?: string
widgetId?: string
@@ -551,6 +574,20 @@ export function useViewFilters(
fk_parent_id: parentId.value,
} as FilterType,
)) as ColumnFilterType
+ } else if (rlsPolicyId) {
+ filters.value[+i] = (await $api.internal.postOperation(
+ apiWorkspaceId.value!,
+ apiBaseId.value!,
+ {
+ operation: 'rlsPolicyFilterCreate',
+ },
+ {
+ ...filter,
+ children: undefined,
+ fk_parent_id: parentId.value,
+ fk_rls_policy_id: rlsPolicyId,
+ } as FilterType,
+ )) as ColumnFilterType
} else if (linkId || linkColId?.value) {
filters.value[+i] = (await $api.internal.postOperation(
apiWorkspaceId.value!,
diff --git a/packages/nocodb/src/meta/meta.service.ts b/packages/nocodb/src/meta/meta.service.ts
index 49999e445d..18e25e394c 100644
--- a/packages/nocodb/src/meta/meta.service.ts
+++ b/packages/nocodb/src/meta/meta.service.ts
@@ -136,6 +136,8 @@ export class MetaService {
[MetaTable.MANAGED_APP_DEPLOYMENT_LOGS]: 'madl',
[MetaTable.SANDBOXES]: 'sb',
[MetaTable.SCIM_CONFIG]: 'scfg',
+ [MetaTable.RLS_POLICIES]: 'rlp',
+ [MetaTable.RLS_POLICY_SUBJECTS]: 'rlps',
};
const prefix = prefixMap[target] || 'nc';
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
index 19be27b278..46d9cb7364 100644
--- a/packages/nocodb/src/meta/migrations/v0/nc_023_rls_policies.ts
+++ b/packages/nocodb/src/meta/migrations/v0/nc_023_rls_policies.ts
@@ -5,6 +5,7 @@ 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('fk_workspace_id', 20);
table.string('base_id', 20).notNullable();
table.string('source_id', 20);
table.string('fk_model_id', 20).notNullable();
diff --git a/packages/nocodb/src/schema/swagger.json b/packages/nocodb/src/schema/swagger.json
index 195335ddf3..bb542e8baa 100644
--- a/packages/nocodb/src/schema/swagger.json
+++ b/packages/nocodb/src/schema/swagger.json
@@ -22790,6 +22790,10 @@
"$ref": "#/components/schemas/StringOrNull",
"description": "Foreign Key to Link Column"
},
+ "fk_rls_policy_id": {
+ "$ref": "#/components/schemas/StringOrNull",
+ "description": "Foreign Key to RLS Policy"
+ },
"id": {
"$ref": "#/components/schemas/Id",
"description": "Unique ID"