feat: add organization.passwordReset PBAC permission (#27377)

* feat: add organization.passwordReset PBAC permission

Allow org admins/owners to reset passwords for members of their
organization via a new PBAC permission. Previously this was only
available to system-level admins.

- Add PasswordReset to CustomAction enum and PERMISSION_REGISTRY
- Create migration to grant permission to admin_role (owner has wildcard)
- Add org-scoped tRPC endpoint using createOrgPbacProcedure
- Handler validates org membership, prevents self-targeting, and blocks
  resetting owner passwords
- Wire permission through MemberPermissions, getOrgMembersPageData, and
  the org members table UI dropdown

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* fix: use targeted select in org password reset to avoid over-fetching

Replace findById with findForPasswordReset repository method that only
selects email, name, and locale instead of the full userSelect which
includes sensitive fields like twoFactorSecret and backupCodes.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* test: add unit tests for sendPasswordReset handler

Co-Authored-By: Claude Opus 4.5 <[email protected]>

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
This commit is contained in:
sean-brydonandClaude Opus 4.5 authored and GitHub committed 2026-01-29 11:18:02 +00:00
1 parent 1f8f134854
commit 08a2b0bfb5
12 files changed
+410 -132

No files matched your search

@@ -1,17 +1,15 @@
import { unstable_cache } from "next/cache";
import { redirect } from "next/navigation";
import { PrismaAttributeRepository } from "@calcom/features/attributes/repositories/PrismaAttributeRepository";
import type { Session } from "next-auth";
import { CrudAction, CustomAction, Resource } from "@calcom/features/pbac/domain/types/permission-registry";
import type { MemberPermissions } from "@calcom/features/pbac/lib/team-member-permissions";
import { getSpecificPermissions } from "@calcom/features/pbac/lib/resource-permissions";
import type { MemberPermissions } from "@calcom/features/pbac/lib/team-member-permissions";
import { RoleManagementFactory } from "@calcom/features/pbac/services/role-management.factory";
import { prisma } from "@calcom/prisma";
import { MembershipRole } from "@calcom/prisma/enums";
import { viewerOrganizationsRouter } from "@calcom/trpc/server/routers/viewer/organizations/_router";
import { createRouterCaller } from "app/_trpc/context";
import { unstable_cache } from "next/cache";
import { redirect } from "next/navigation";
import type { Session } from "next-auth";
const getCachedAttributes = unstable_cache(
async (orgId: number) => {
@@ -60,6 +58,7 @@ export async function getOrgMembersPageData(session: Session) {
CustomAction.ChangeMemberRole,
CustomAction.Remove,
CustomAction.Impersonate,
CustomAction.PasswordReset,
],
fallbackRoles: {
[CustomAction.ListMembers]: {
@@ -80,6 +79,9 @@ export async function getOrgMembersPageData(session: Session) {
[CustomAction.Impersonate]: {
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
},
[CustomAction.PasswordReset]: {
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
},
},
}),
getSpecificPermissions({
@@ -107,6 +109,7 @@ export async function getOrgMembersPageData(session: Session) {
canChangeMemberRole: orgPermissions[CustomAction.ChangeMemberRole],
canRemove: orgPermissions[CustomAction.Remove],
canImpersonate: orgPermissions[CustomAction.Impersonate],
canResetPassword: orgPermissions[CustomAction.PasswordReset],
canViewAttributes: attributesPermissions[CrudAction.Read],
canEditAttributesForUser: attributesPermissions[CustomAction.EditUsers],
};