Implement three-layer permission system with URY roles and capabilities#96
Draft
Implement three-layer permission system with URY roles and capabilities#96
Conversation
Adds a three-layer permission system for URY: 1. Capability layer — 24 fine-grained capabilities across orders, payments, kitchen, dispatch, reports, settings, users, and roles 2. URY Role layer — 13 named roles (Admin, Ops Admin, Manager, Director, Purchase/Sales Manager, Accountant, Analyst, Captain, Servicer, Cashier, Chef, Store Manager/Admin/Accountant) each owning a set of capabilities 3. Frappe Role layer — backing Frappe roles for DocType-level permission enforcement with desk/non-desk access control Backend: - URY Role, URY User Role, URY Role Permission doctypes - Capability engine with caching (ury/ury/permissions.py) - Whitelisted API endpoints for user/role CRUD (permissions_api.py) - App permission check via URY User Role - Install/migrate hooks for idempotent role seeding - Migration patch for existing URY Manager/Captain/Cashier users - Frappe role fixtures for all 14 backing roles Frontend: - React PermissionsContext for capability-based UI gating - TypeScript API client for all permissions endpoints - User management page with invite, role change, enable/disable https://claude.ai/code/session_01TZ1yuzhjsj7276Qm3nZESS
- Add /settings route with sidebar navigation - Add ProtectedRoute component for capability-based access control - Add SettingsLayout component with Users and Roles navigation - Add RolesPage for read-only role viewing with capability grouping - Update Header with Settings link in user dropdown (gated by capability) - Wrap App with PermissionsProvider - Add URY Role and URY User Role to fixtures export
- Add optional chaining to prevent crash when capabilities is undefined - This can happen when the API returns without capabilities field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces a comprehensive three-layer permission system for URY consisting of:
users.create,orders.view_all) checked throughout the applicationKey Changes
Backend (Python/Frappe)
ury/ury/permissions.py— Core permission engine with:has_capability()andget_user_capabilities()functions for runtime checksury/ury/api/permissions_api.py— Whitelisted REST endpoints:get_users(),invite_user(),update_user_role(),set_user_enabled()get_ury_roles(),create_ury_role(),update_ury_role()_require(capability)checksNew DocTypes:
URY Role— Stores role definitions with capability assignmentsURY User Role— Links users to URY roles with enable/disable toggleURY Role Permission— Child table for capability assignmentsury/install.py— Idempotent role seeding:after_installandafter_migratehooksFrontend (React/TypeScript)
pos/src/lib/permissions-api.ts— TypeScript API client:MeResponse,URYUser,URYRole,URYRoleCapabilitypos/src/contexts/PermissionsContext.tsx— React context provider:usePermissions()hook for capability checkshasCapability(capability)method for conditional rendering/logicpos/src/pages/admin/UsersPage.tsx— User management UI:users.manageorusers.create)Notable Implementation Details
desk_access=1get Frappe desk access; others are frontend-onlyURYUserRole.on_update()automatically syncs Frappe roles when URY role changeshttps://claude.ai/code/session_01TZ1yuzhjsj7276Qm3nZESS