Skip to content

Commit 0afbe94

Browse files
authored
Enhance password reset logic in MemberActionsService (#20504)
* Update allowResetPassword method to permit password resets for users with an Accepted status when AdminResetTwoFactor is enabled. * Add unit tests to verify behavior for password reset permissions based on user status and AdminResetTwoFactor settings.
1 parent c966e74 commit 0afbe94

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

apps/web/src/app/admin-console/organizations/members/services/member-actions/member-actions.service.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,33 @@ describe("MemberActionsService", () => {
791791
expect(result).toBe(false);
792792
});
793793

794+
it("should allow reset password when user status is accepted and AdminResetTwoFactor is enabled", () => {
795+
const user = {
796+
...mockOrgUser,
797+
status: OrganizationUserStatusType.Accepted,
798+
} as OrganizationUserView;
799+
800+
const result = service.allowResetPassword(user, mockOrganization, resetPasswordEnabled, true);
801+
802+
expect(result).toBe(true);
803+
});
804+
805+
it("should not allow reset password when user status is accepted and AdminResetTwoFactor is disabled", () => {
806+
const user = {
807+
...mockOrgUser,
808+
status: OrganizationUserStatusType.Accepted,
809+
} as OrganizationUserView;
810+
811+
const result = service.allowResetPassword(
812+
user,
813+
mockOrganization,
814+
resetPasswordEnabled,
815+
false,
816+
);
817+
818+
expect(result).toBe(false);
819+
});
820+
794821
it("should not allow reset password when user status is invited", () => {
795822
const user = {
796823
...mockOrgUser,

apps/web/src/app/admin-console/organizations/members/services/member-actions/member-actions.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ export class MemberActionsService {
235235

236236
const statusAllowed =
237237
orgUser.status === OrganizationUserStatusType.Confirmed ||
238-
(adminResetTwoFactorEnabled && orgUser.status === OrganizationUserStatusType.Revoked);
238+
(adminResetTwoFactorEnabled && orgUser.status === OrganizationUserStatusType.Revoked) ||
239+
(adminResetTwoFactorEnabled && orgUser.status === OrganizationUserStatusType.Accepted);
239240

240241
return (
241242
organization.canManageUsersPassword &&

0 commit comments

Comments
 (0)