From c5bc5410901c91ebcc36a42089242487fa986e9e Mon Sep 17 00:00:00 2001 From: Hai Cao Date: Thu, 8 Jun 2023 09:52:10 -0700 Subject: [PATCH] Fix must_change option for login management (#23350) --- .../src/objectManagement/ui/loginDialog.ts | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/extensions/mssql/src/objectManagement/ui/loginDialog.ts b/extensions/mssql/src/objectManagement/ui/loginDialog.ts index f396b93eb3..c8a5277684 100644 --- a/extensions/mssql/src/objectManagement/ui/loginDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/loginDialog.ts @@ -64,7 +64,7 @@ export class LoginDialog extends PrincipalDialogBase { this.objectInfo.password = newValue; + this.mustChangePasswordCheckbox.enabled = this.objectInfo.enforcePasswordPolicy && this.isPasswordChanged(); + // this handles the case where the mustChangePasswordCheckbox is disabled when a user changes the password input and reverts the change. In that case we want to reset the check state of this checkbox to its original value instead of using the potentially dirty state set during password input changes. + if (!this.mustChangePasswordCheckbox.enabled) { + this.mustChangePasswordCheckbox.checked = this.objectInfo.mustChangePassword; + } }, this.objectInfo.password ?? ''); const passwordRow = this.createLabelInputContainer(objectManagementLoc.PasswordText, this.passwordInput); this.confirmPasswordInput = this.createPasswordInputBox(objectManagementLoc.ConfirmPasswordText, async () => { }, this.objectInfo.password ?? ''); @@ -158,21 +163,26 @@ export class LoginDialog extends PrincipalDialogBase { const enforceExpiration = checked; this.objectInfo.enforcePasswordExpiration = enforceExpiration; - this.mustChangePasswordCheckbox.enabled = enforceExpiration; - this.mustChangePasswordCheckbox.checked = enforceExpiration; + if (this.options.isNewObject || this.isPasswordChanged()) { + this.mustChangePasswordCheckbox.enabled = enforceExpiration; + this.mustChangePasswordCheckbox.checked = enforceExpiration; + } }, this.objectInfo.enforcePasswordPolicy); this.mustChangePasswordCheckbox = this.createCheckbox(objectManagementLoc.MustChangePasswordText, async (checked) => { this.objectInfo.mustChangePassword = checked; - }, this.objectInfo.mustChangePassword); + }, this.objectInfo.mustChangePassword, this.options.isNewObject); items.push(this.enforcePasswordPolicyCheckbox, this.enforcePasswordExpirationCheckbox, this.mustChangePasswordCheckbox); @@ -187,6 +197,10 @@ export class LoginDialog extends PrincipalDialogBase