Skip to content

feat: advocate users can invite new organisations and copy maps to them#415

Merged
joaquimds merged 9 commits intomainfrom
feat/advocate-invite-org
Apr 14, 2026
Merged

feat: advocate users can invite new organisations and copy maps to them#415
joaquimds merged 9 commits intomainfrom
feat/advocate-invite-org

Conversation

@joaquimds
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 UserRole and role-gated tRPC procedures (superadminProcedure, new advocateProcedure) 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.role and 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.

Comment thread src/app/(private)/(dashboards)/invite-organisation/page.tsx Outdated
Comment thread src/server/commands/copyMapsToOrganisation.ts
Comment thread src/server/commands/copyMapsToOrganisation.ts
Comment thread migrations/1774658921004_data_source_config_org_unique.ts
Comment thread src/server/trpc/routers/map.ts
Comment thread tests/unit/server/trpc/routers/invitation.test.ts
Comment thread src/server/trpc/index.ts
joaquimds and others added 3 commits April 14, 2026 11:35
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/server/trpc/routers/invitation.ts
Comment thread src/server/commands/copyMapsToOrganisation.ts
Comment thread src/server/commands/copyMapsToOrganisation.ts
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/server/trpc/routers/map.ts
Comment thread src/server/services/database/schema.ts
Comment thread src/server/commands/copyMapsToOrganisation.ts Outdated
Comment thread src/server/commands/copyMapsToOrganisation.ts
Comment thread src/server/trpc/routers/invitation.ts
Comment thread src/server/trpc/routers/invitation.ts
joaquimds and others added 3 commits April 14, 2026 15:48
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/server/commands/copyMapsToOrganisation.ts
@joaquimds joaquimds merged commit e461b2d into main Apr 14, 2026
1 check passed
@joaquimds joaquimds deleted the feat/advocate-invite-org branch April 14, 2026 14:02
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.

2 participants