Skip to content

feat(data): consolidate granular table permissions and capability gating - #478

Merged
esafwan merged 4 commits into
developfrom
feat/data-permissions-capability-gating
Jul 26, 2026
Merged

feat(data): consolidate granular table permissions and capability gating#478
esafwan merged 4 commits into
developfrom
feat/data-permissions-capability-gating

Conversation

@esafwan

@esafwan esafwan commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Consolidates the Data permissions work from #346 and #413 onto current origin/develop.

Source PRs:

What changed

  • Adds dedicated Data capabilities:
    • data.tables.manage
    • data.records.create
    • data.records.view_own
    • data.records.view_all
    • data.records.edit_own
    • data.records.edit_all
  • Replaces old Data Table route/API gating that reused flows.* with dedicated data.* capability checks.
  • Adds generated DocType permission sync for Huf Data Tables from Huf Role capability assignments.
  • Syncs Data Table DocPerms on Huf Role update and via migration patch for existing generated tables.
  • Updates Huf Role Permission options and Roles UI grouping for Data capabilities.
  • Updates sidebar and Data Table builder access states to use Data capabilities.
  • Preserves current Data Table bulk import and agent-access functionality from develop while tightening import DocPerms so data.records.create enables import/create without broad read/write/delete access.

Conflict resolution notes

Checks

Passed:

  • git diff --check
  • python3 -m py_compile huf/huf/doctype/huf_data_table/api.py huf/huf/doctype/huf_data_table/permissions.py huf/huf/doctype/huf_role/huf_role.py huf/permissions.py huf/patches/v1/sync_data_table_permissions.py
  • frontend/node_modules/.bin/eslint src/components/app-sidebar.tsx src/pages/DataTableBuilderPage.tsx src/pages/RolesPage.tsx

Attempted but blocked by existing environment/baseline issues:

  • python3 -m pytest huf/huf/doctype/huf_data_table/test_agent_access.py huf/huf/doctype/huf_role/test_huf_role.py huf/huf/doctype/huf_role_permission/test_huf_role_permission.py failed during collection because local Python environment does not have frappe installed.
  • yarn typecheck and yarn build fail on existing unrelated src/components/chat/chatMessageList.mappers.ts(507,31): Property 'injectedMemories' does not exist on type 'ChatMessage'.
  • yarn lint fails on existing unrelated baseline errors in bulk import, memory, tools, and apps files; the touched frontend files pass targeted ESLint.

esafwan added 4 commits July 27, 2026 01:21
The Data feature had zero capability enforcement server-side, and every
dynamically-generated data-table DocType hardcoded its Frappe permission
row to System Manager only - meaning non-admins got a hard
PermissionError on any record, in any table, despite the sidebar
implying broader access via a misused agent.view_all capability.

Adds 6 new capabilities (data.tables.manage, data.records.create,
data.records.view_own/view_all, data.records.edit_own/edit_all),
configurable per Huf Role via the existing Roles system.

Enforcement:
- Schema management (create/update/delete table) now requires
  data.tables.manage, checked server-side in huf_data_table/api.py.
- Record-level access uses Frappe's native if_owner permission
  mechanism instead of hand-rolled filtering: sync_data_table_permissions()
  rebuilds each generated DocType's permission rows from every Huf
  Role's current data.* grants, merging view/edit/create into the
  correct (role, if_owner) row pairs while always preserving System
  Manager's full-access row. This runs on table creation and whenever
  a Huf Role is saved, so permission changes take effect immediately.
- A migration patch backfills permissions onto tables created before
  this change; it's a no-op on fresh installs with no data tables yet.

Frontend: sidebar Data nav item now checks any of the 3 view/manage
capabilities instead of the mismatched agent.view_all; DataTableBuilderPage
shows an access-denied state for users without data.tables.manage;
RolesPage groups the new capabilities under a "Data" category.

Also fixes the Huf Role Permission doctype's capability Select field,
which had a static options list that rejected the new values before
custom Python validation even ran (caught by running a real bench
migrate against the site, not just static analysis).
…ame, add view checks

Found in a final cross-branch security/UX review:
- apply_data_permissions() was whitelisted with no capability check,
  letting any authenticated user trigger a full permission rebuild
  across every data table.
- table_name was only trimmed before being interpolated into the
  generated DocType name (f"HF {table_name}"), with no character
  restriction.
- get_table_record_counts/get_table_schema had no capability check at
  all, letting any user enumerate table schemas and record counts.

Adds a _require_data_manage()/_require_data_view() guard to each,
and a conservative identifier regex on table_name.
… options, migration patch, RolesPage

Restores the pieces dropped by the over-narrow task scope: HufRole.on_update
syncs data-table permissions, huf_role_permission options gain the data.*
capabilities, patches.txt registers sync_data_table_permissions (last line,
per intake dossier), and the RolesPage frontend change.
@esafwan
esafwan force-pushed the feat/data-permissions-capability-gating branch from 31ba617 to 5906c84 Compare July 26, 2026 21:22
@esafwan
esafwan merged commit 73b5ad0 into develop Jul 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant