Skip to content

Members, roles and data scopes ​

Membership controls project access, role permissions control operations, and data scopes control the records those operations can access. Run the examples from the entry repository, substituting your project code for order-center.

bash
./kaiwu whoami
./kaiwu access permissions order-center
./kaiwu access roles order-center
./kaiwu access members order-center

Grant a read-only role ​

In Project Management, open the project’s permission center, create a role, grant its menu permissions and assign it to an existing user. This example assumes alice exists and manifest sync has registered order:order:list.

bash
./kaiwu access role-create order-center auditor --name "Auditor"
./kaiwu access role-grant order-center auditor --permissions order:order:list
./kaiwu access member-set order-center alice --roles auditor

role-grant replaces the role’s permission set. member-set replaces the member’s roles and enables the membership by default. Read current assignments before modifying an existing object. Read them back, sign in as the member, and verify both UI hiding (via useCan / <Can> from @/kaiwu) and backend enforcement.

In product-led projects, demo personas (mock-support/personas.ts) map to roles defined in frontend kaiwu/roles.yml. The first ./kaiwu project adopt <frontend-dir> --apply imports those initial roles automatically; subsequent runs and regular project sync preserve manual platform edits unless --with-access is explicitly passed.

Permission center with menu and button codes

Filter order rows ​

When coding agents generate CRUD endpoints, the most common security gap is checking menu permissions while forgetting row-level isolation. Kaiwu enforces row scopes across Gateway and Starter without adding runtime callbacks:

  • Five fixed scope types with role union: Supports ALL, DEPT_AND_CHILD, DEPT, SELF, and CUSTOM_DEPT (with optional child departments). Multiple roles resolve to their union, and unconfigured roles default to SELF.
  • Zero-callback signed propagation: System resolves the scope snapshot and Gateway embeds the ds claim into the 60s signed Context. Business services never call back to System on normal requests.
  • Table-level SQL enforcement & build gates: Add com.kaiwuzaidao:kaiwu-data-scope:0.2.0 to domain, register its interceptor before pagination, and declare protected tables (or explicit exempt reasons) in kaiwu/data-scopes.yml under META-INF/kaiwu/. Indexed owner_user_id and owner_dept_id columns are auto-filled on insert; ownership transfers use DataScopes.reassign, background jobs use audited DataScopes.unrestricted("reason", ...), and DataScopeConventionTest checks ownership fields and indexes, rejects references to protected tables in JdbcTemplate source, and warns about potentially undeclared list, page, or export endpoints.

Sync the resources, configure per-role scopes in the permission center, and verify two owners across list results, paginated totals, and out-of-scope updates. Integration code · Platform scope rules

Apache License 2.0