infrastructure.persistence.models.casbin_rule¶
src.infrastructure.persistence.models.casbin_rule
¶
Casbin rule database model for RBAC policy storage.
This module defines the CasbinRule model that stores Casbin RBAC policies. The table structure matches what casbin-async-sqlalchemy-adapter expects.
Policy Types (ptype): - 'p': Permission rules (role, resource, action) - 'g': Role grouping rules (user/role, parent_role)
Reference
- docs/architecture/authorization-architecture.md
- docs/guides/database-seeding.md
Classes¶
CasbinRule
¶
Bases: BaseModel
Casbin rule model for RBAC policy storage.
This table stores all Casbin RBAC policies including: - Permission rules: Which roles can access which resources - Role groupings: Role inheritance hierarchy
Note
Uses Integer ID (not UUID) to match Casbin adapter expectations. The id column overrides the UUID from BaseModel.
Policy Examples
Permission rule (ptype='p'): ptype='p', v0='admin', v1='users', v2='write' Means: admin role can write to users resource
Role grouping (ptype='g'): ptype='g', v0='admin', v1='user' Means: admin inherits from user role
Fields
id: Auto-incrementing integer primary key ptype: Policy type ('p' for permission, 'g' for grouping) v0-v2: Policy values (meaning depends on ptype)
Seeding
Initial policies are seeded via rbac_seeder.py after migrations. Subsequent changes are managed through admin APIs.
Source code in src/infrastructure/persistence/models/casbin_rule.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |