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:
1 parent
1f8f134854
commit
08a2b0bfb5
12 files changed
+410
-132
No files matched your search
@@ -36,6 +36,7 @@ export enum CustomAction {
|
||||
ReadRecordings = "readRecordings",
|
||||
Impersonate = "impersonate",
|
||||
EditUsers = "editUsers",
|
||||
PasswordReset = "passwordReset",
|
||||
ReadTeamAuditLogs = "readTeamAuditLogs",
|
||||
ReadOrgAuditLogs = "readOrgAuditLogs",
|
||||
}
|
||||
@@ -436,6 +437,14 @@ export const PERMISSION_REGISTRY: PermissionRegistry = {
|
||||
descriptionI18nKey: "pbac_desc_impersonate_organization_members",
|
||||
scope: [Scope.Organization],
|
||||
},
|
||||
[CustomAction.PasswordReset]: {
|
||||
description: "Reset passwords for organization members",
|
||||
category: "org",
|
||||
i18nKey: "pbac_action_password_reset",
|
||||
descriptionI18nKey: "pbac_desc_reset_password_organization_members",
|
||||
scope: [Scope.Organization],
|
||||
dependsOn: ["organization.listMembers"],
|
||||
},
|
||||
[CrudAction.Update]: {
|
||||
description: "Edit organization settings",
|
||||
category: "org",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import { Resource, CustomAction } from "../domain/types/permission-registry";
|
||||
import { CustomAction, Resource } from "../domain/types/permission-registry";
|
||||
import { getSpecificPermissions } from "./resource-permissions";
|
||||
|
||||
export interface MemberPermissions {
|
||||
@@ -9,10 +8,11 @@ export interface MemberPermissions {
|
||||
canChangeMemberRole: boolean;
|
||||
canRemove: boolean;
|
||||
canImpersonate: boolean;
|
||||
canResetPassword?: boolean;
|
||||
canEditAttributesForUser?: boolean;
|
||||
canViewAttributes?: boolean;
|
||||
}
|
||||
|
||||
|
||||
interface TeamWithMembership {
|
||||
id: number;
|
||||
isPrivate: boolean;
|
||||
|
||||
@@ -1339,6 +1339,17 @@ export class UserRepository {
|
||||
});
|
||||
}
|
||||
|
||||
async findForPasswordReset({ id }: { id: number }) {
|
||||
return this.prismaClient.user.findUnique({
|
||||
where: { id },
|
||||
select: {
|
||||
email: true,
|
||||
name: true,
|
||||
locale: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a user by ID returning only their username
|
||||
* @param userId - The user ID
|
||||
|
||||
Reference in new issue
Block a user