feat: advocate users can invite new organisations and copy maps to them#415
feat: advocate users can invite new organisations and copy maps to them#415
Conversation
There was a problem hiding this comment.
Pull request overview
Enables role-based permissions (Superadmin/Advocate) so advocates can invite organisations and optionally copy selected maps/data sources into the invited organisation.
Changes:
- Introduces
UserRoleand role-gated tRPC procedures (superadminProcedure, newadvocateProcedure) plus UI updates to use role checks instead of a hard-coded admin email. - Adds invitation flow support for optionally copying selected maps/data sources into the target organisation (
copyMapsToOrganisation) and new UI for advocates to create/manage organisation invitations. - Adds migrations for
user.roleand adjusts data source uniqueness constraints; adds unit tests around role gating and map-copy behavior.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/server/trpc/routers/user.test.ts | Adds unit tests for superadmin-only user listing and role updates. |
| tests/unit/server/trpc/routers/invitation.test.ts | Adds unit tests for invitation list/create authorization behavior. |
| tests/unit/server/commands/copyMapsToOrganisation.test.ts | Adds unit tests for copying maps/data sources with include/exclude behavior and ID remapping. |
| tests/unit/app/api/login/route.test.ts | Updates login test fixture to include the new role field. |
| src/server/trpc/routers/user.ts | Adds user.updateRole tRPC mutation gated by superadmin. |
| src/server/trpc/routers/organisation.ts | Changes organisation.listAll to be accessible to advocates. |
| src/server/trpc/routers/map.ts | Adds map.listAll for advocates to select maps to copy, including resolving data source names. |
| src/server/trpc/routers/invitation.ts | Allows advocates to create/list invitations; supports optional mapSelections and map-copying. |
| src/server/trpc/routers/auth.ts | Removes ensureOrganisationMap call during invitation acceptance. |
| src/server/trpc/index.ts | Replaces email-based superadmin check with role-based checks; introduces advocateProcedure. |
| src/server/services/database/schema.ts | Adds role column to the DB schema typing for User. |
| src/server/repositories/User.ts | Adds updateUserRole repository method. |
| src/server/repositories/Map.ts | Adds listAllMaps repository method with organisation name ordering. |
| src/server/commands/copyMapsToOrganisation.ts | Implements map/data source copying and config/view ID remapping plus import job enqueueing. |
| src/models/User.ts | Introduces UserRole enum and adds role to userSchema. |
| src/constants/index.ts | Removes ADMIN_USER_EMAIL constant (transition to role-based admin). |
| src/components/Sidebar.tsx | Adds “Invite organisation” nav item for Advocate/Superadmin; updates Superadmin gating to role-based. |
| src/authTypes.ts | Extends CurrentUser to include role. |
| src/auth/index.ts | Includes role in the server session’s currentUser. |
| src/app/(private)/map/[id]/components/controls/VisualisationPanel/VisualisationPanel.tsx | Formatting-only change. |
| src/app/(private)/map/[id]/components/Map.css | Fixes a comment typo (“inout” → “input”). |
| src/app/(private)/(dashboards)/superadmin/page.tsx | Updates Superadmin dashboard to role-based access and adds role editing UI; removes invitation UI from this page. |
| src/app/(private)/(dashboards)/superadmin/data-sources/[id]/page.tsx | Updates Superadmin data source config route gating to role-based. |
| src/app/(private)/(dashboards)/invite-organisation/page.tsx | New advocate-accessible page to view pending org invitations and launch invitation creation. |
| src/app/(private)/(dashboards)/invite-organisation/CreateInvitationModal.tsx | New modal to create invitations and optionally select maps/data sources to copy. |
| migrations/1774658921004_data_source_config_org_unique.ts | Alters unique constraint behavior for data source config uniqueness per organisation. |
| migrations/1774658921003_user_role.ts | Adds role to users and seeds the default superadmin role for an existing account. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…/ts-mapped into feat/advocate-invite-org
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 27 out of 27 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 27 out of 27 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…/ts-mapped into feat/advocate-invite-org
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 29 out of 30 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No description provided.