Skip to content

feat(roles): add Presidente and Segretario built-in roles - #82

Merged
lorenzocorallo merged 3 commits into
mainfrom
feat/presidente-segretario-roles
Nov 2, 2026
Merged

lorenzocorallo merged 3 commits into
mainfrom
feat/presidente-segretario-roles

Conversation

@lorenzocorallo

@lorenzocorallo lorenzocorallo commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Adds two built-in roles for the board offices: presidente (Presidente) and segretario (Segretario). Both always inherit from direttivo.

Who assigns them

Only a Master Admin, by hand. Holding idp:roles:assign is not enough, even if you hold everything the office grants. This matters because Direttivo holds idp:roles:assign today.

They are still built in: the key is fixed and they can't be deleted. They are the only built-in roles that take hand assignments. The others still come from evidence or config.

What changed to allow this:

  • Server: assigning or revoking one of these roles returns 403 unless the caller is a Master Admin. Other built-in roles still get 400.
  • Database: migration 0024 updates the guard_managed_role_links trigger so user_role accepts these two keys and still rejects the other built-in roles.
  • Reads: hand assignments of these roles now count in identity/tokens, the backend access snapshot, People, the user directory role filter and search, the account page, and MCP get_role members.
  • UI: a Master Admin sees the People list on the role page and can pick the roles on a user's page. Everyone else doesn't see them as options.

Inheriting Direttivo

  • 0024 adds the parent link from each office to direttivo.
  • Role validation won't let anyone remove that parent, so a holder always gets everything Direttivo grants. Extra parents and permissions can still be added.
  • Holders get direttivo in their roles and all its permissions. They don't get the direttivo state, which still comes only from the Entra group.

Migration

0024 adds the two roles (static-role-presidente, static-role-segretario, no source_state), the parent links, and the updated trigger. If a hand-made role already uses one of these keys, it stops with an error instead of quietly treating it as the office. Production has no such role (checked read-only).

Not in this PR

  • Permissions (regulations:manage, regulations:read, regulations:write): the code only defines idp:* permissions. Everything else, and which role gets what, is set at runtime by admins. Create these and grant them in the admin UI when the regulations editor ships.

Checks

  • vp check and vp test pass.
  • On a throwaway Postgres: all migrations applied, the seed and parent links are correct, the trigger accepts presidente and rejects direttivo, and the full PostgreSQL suite passes.
  • A new PostgreSQL test checks that a non-Master-Admin with idp:roles:assign gets 403, a Master Admin can assign and revoke, and the holder gets direttivo.
  • One existing test, denies bootstrapping new authority with both writer permissions, failed once in a full parallel run and passed in every other run, including 4 runs on its own. It looks flaky when it shares the DB with other test files.

Both are managed roles proven by direct membership of an Entra group
(PN_ENTRA_PRESIDENTE_GROUP_ID, PN_ENTRA_SEGRETARIO_GROUP_ID), like
Direttivo, and always inherit from Direttivo. Migration 0024 seeds them
and the inheritance edge.
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between ce5dd3e and 1a84447.

Files selected for processing: 17
  • README.md
  • drizzle/0024_presidente_segretario_roles.sql
  • src/auth/access-snapshot.ts
  • src/auth/account-overview.ts
  • src/auth/mcp-server.ts
  • src/auth/people-roles.ts
  • src/auth/people-search.ts
  • src/auth/rbac-security.integration.test.mjs
  • src/auth/rbac-store.ts
  • src/auth/rbac.test.ts
  • src/auth/rbac.ts
  • src/auth/user-directory.ts
  • src/components/rbac/delegation.test.ts
  • src/components/rbac/delegation.ts
  • src/components/users/user-roles.tsx
  • src/routes/access/roles/$roleId.tsx
  • src/routes/users/index.tsx

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 2c366c9 and ce5dd3e.

Files ignored due to path filters: 1
  • drizzle/meta/0024_snapshot.json is excluded by !drizzle/meta/*_snapshot.json
Files selected for processing: 14
  • .env.example
  • README.md
  • drizzle/0024_presidente_segretario_roles.sql
  • drizzle/meta/_journal.json
  • scripts/security-config.mjs
  • src/auth/access-snapshot.ts
  • src/auth/account-overview.ts
  • src/auth/identity-subject.ts
  • src/auth/membership.ts
  • src/auth/policy.ts
  • src/auth/rbac.test.ts
  • src/auth/rbac.ts
  • src/db/rbac.ts
  • src/env.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The change adds Presidente and Segretario as managed roles that inherit from Direttivo. Optional Entra group settings provide membership evidence for each role. Role validation preserves the intrinsic parent relationship, and the README and environment example document the settings.

Changes

Board-office roles

Layer / File(s) Summary
Role catalog and inheritance
src/auth/rbac.ts, drizzle/0024_presidente_segretario_roles.sql, drizzle/meta/_journal.json, src/db/rbac.ts, src/auth/rbac.test.ts, README.md
The catalog and migration add Presidente and Segretario with Direttivo as their parent. Validation requires intrinsic parents that remain in the catalog. Tests cover role inheritance and parent validation.
Entra group configuration and evidence
src/env.ts, scripts/security-config.mjs, src/auth/access-snapshot.ts, src/auth/membership.ts, src/auth/identity-subject.ts, src/auth/policy.ts, src/auth/account-overview.ts, .env.example, README.md
Optional group IDs configure the office-role mappings and require complete Entra credentials when set. Successful membership checks add the corresponding states. The policy trusts those states as Entra evidence, and account overview treats them as groups.

Possibly related PRs

  • PoliNetworkOrg/auth#73: Adds People role bindings and excludes managed roles from People binding. This change adds Presidente and Segretario to the managed role catalog.

Change: Feature

Merge Risk: Minimal · previous review ce5dd

The new offices use direct Entra membership and inherit Direttivo access. No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title "feat(roles): add Presidente and Segretario built-in roles" matches the main change in the changeset. The raw summary and PR objectives both show that the PR adds the two built-in roles, the…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(roles): add Presidente and Segretario built-in roles" matches the main change in the changeset. The raw summary and PR objectives both show that the PR adds the two built-in roles, their Entra group mappings, the migration 0024 that seeds them, and their inheritance from Direttivo. The title is short, specific, and uses a conventional commit prefix. It does not cover the inheritance or the optional group configuration, which is acceptable for a title.

Full details: Docstring Coverage

Explanation

Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 10 files. (4 skipped: 4 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…n only

Drop the Entra group wiring. The two board offices stay built-in
(fixed key, cannot be deleted, always inherit from Direttivo), but are
given and taken back by hand, and only by a Master Admin. Migration
0024 lets user_role hold these two managed roles.
@lorenzocorallo
lorenzocorallo enabled auto-merge (squash) November 2, 2026 19:12
@lorenzocorallo
lorenzocorallo merged commit d7cf703 into main Nov 2, 2026
2 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