mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-16 19:11:39 -04:00
User Management - Support new object types: Server Role, Application Role and Database Role (#22889)
* server role dialogs * dialogs for other types * refactor * find object dialog * script button * refactoring * fix issues * fix title * vbump sts * remove language from links
This commit is contained in:
@@ -4,11 +4,12 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import { DefaultInputWidth, ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
|
||||
import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
|
||||
import { IObjectManagementService, ObjectManagement } from 'mssql';
|
||||
import * as localizedConstants from '../localizedConstants';
|
||||
import { AlterLoginDocUrl, CreateLoginDocUrl, PublicServerRoleName } from '../constants';
|
||||
import { getAuthenticationTypeByDisplayName, getAuthenticationTypeDisplayName, isValidSQLPassword } from '../utils';
|
||||
import { DefaultMaxTableHeight } from './dialogBase';
|
||||
|
||||
export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Login, ObjectManagement.LoginViewInfo> {
|
||||
private generalSection: azdata.GroupContainer;
|
||||
@@ -52,11 +53,8 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
return true;
|
||||
}
|
||||
|
||||
protected async validateInput(): Promise<string[]> {
|
||||
const errors: string[] = [];
|
||||
if (!this.objectInfo.name) {
|
||||
errors.push(localizedConstants.NameCannotBeEmptyError);
|
||||
}
|
||||
protected override async validateInput(): Promise<string[]> {
|
||||
const errors = await super.validateInput();
|
||||
if (this.objectInfo.authenticationType === ObjectManagement.AuthenticationType.Sql) {
|
||||
if (!this.objectInfo.password && !(this.viewInfo.supportAdvancedPasswordOptions && !this.objectInfo.enforcePasswordPolicy)) {
|
||||
errors.push(localizedConstants.PasswordCannotBeEmptyError);
|
||||
@@ -104,17 +102,9 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
}
|
||||
|
||||
private initializeGeneralSection(): void {
|
||||
this.nameInput = this.modelView.modelBuilder.inputBox().withProps({
|
||||
ariaLabel: localizedConstants.NameText,
|
||||
enabled: this.options.isNewObject,
|
||||
value: this.objectInfo.name,
|
||||
width: DefaultInputWidth
|
||||
}).component();
|
||||
this.disposables.push(this.nameInput.onTextChanged(async () => {
|
||||
this.objectInfo.name = this.nameInput.value!;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.nameInput = this.createInputBox(localizedConstants.NameText, async (newValue) => {
|
||||
this.objectInfo.name = newValue;
|
||||
}, this.objectInfo.name, this.options.isNewObject);
|
||||
|
||||
const nameContainer = this.createLabelInputContainer(localizedConstants.NameText, this.nameInput);
|
||||
const authTypes = [];
|
||||
@@ -127,93 +117,72 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
if (this.viewInfo.supportAADAuthentication) {
|
||||
authTypes.push(localizedConstants.AADAuthenticationTypeDisplayText);
|
||||
}
|
||||
this.authTypeDropdown = this.createDropdown(localizedConstants.AuthTypeText, authTypes, getAuthenticationTypeDisplayName(this.objectInfo.authenticationType), this.options.isNewObject);
|
||||
this.disposables.push(this.authTypeDropdown.onValueChanged(async () => {
|
||||
this.objectInfo.authenticationType = getAuthenticationTypeByDisplayName(<string>this.authTypeDropdown.value);
|
||||
this.authTypeDropdown = this.createDropdown(localizedConstants.AuthTypeText, async (newValue) => {
|
||||
this.objectInfo.authenticationType = getAuthenticationTypeByDisplayName(newValue);
|
||||
this.setViewByAuthenticationType();
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
}, authTypes, getAuthenticationTypeDisplayName(this.objectInfo.authenticationType), this.options.isNewObject);
|
||||
|
||||
const authTypeContainer = this.createLabelInputContainer(localizedConstants.AuthTypeText, this.authTypeDropdown);
|
||||
|
||||
this.enabledCheckbox = this.createCheckbox(localizedConstants.EnabledText, this.objectInfo.isEnabled);
|
||||
this.disposables.push(this.enabledCheckbox.onChanged(() => {
|
||||
this.objectInfo.isEnabled = this.enabledCheckbox.checked!;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
this.enabledCheckbox = this.createCheckbox(localizedConstants.EnabledText, async (checked) => {
|
||||
this.objectInfo.isEnabled = checked;
|
||||
}, this.objectInfo.isEnabled);
|
||||
this.generalSection = this.createGroup(localizedConstants.GeneralSectionHeader, [nameContainer, authTypeContainer, this.enabledCheckbox], false);
|
||||
}
|
||||
|
||||
private initializeSqlAuthSection(): void {
|
||||
const items: azdata.Component[] = [];
|
||||
this.passwordInput = this.createPasswordInputBox(localizedConstants.PasswordText, this.objectInfo.password ?? '');
|
||||
this.passwordInput = this.createPasswordInputBox(localizedConstants.PasswordText, async (newValue) => {
|
||||
this.objectInfo.password = newValue;
|
||||
}, this.objectInfo.password ?? '');
|
||||
const passwordRow = this.createLabelInputContainer(localizedConstants.PasswordText, this.passwordInput);
|
||||
this.confirmPasswordInput = this.createPasswordInputBox(localizedConstants.ConfirmPasswordText, this.objectInfo.password ?? '');
|
||||
this.disposables.push(this.passwordInput.onTextChanged(async () => {
|
||||
this.objectInfo.password = this.passwordInput.value;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.disposables.push(this.confirmPasswordInput.onTextChanged(async () => {
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.confirmPasswordInput = this.createPasswordInputBox(localizedConstants.ConfirmPasswordText, async () => { }, this.objectInfo.password ?? '');
|
||||
const confirmPasswordRow = this.createLabelInputContainer(localizedConstants.ConfirmPasswordText, this.confirmPasswordInput);
|
||||
items.push(passwordRow, confirmPasswordRow);
|
||||
|
||||
if (!this.options.isNewObject) {
|
||||
this.specifyOldPasswordCheckbox = this.createCheckbox(localizedConstants.SpecifyOldPasswordText);
|
||||
this.oldPasswordInput = this.createPasswordInputBox(localizedConstants.OldPasswordText, '', false);
|
||||
const oldPasswordRow = this.createLabelInputContainer(localizedConstants.OldPasswordText, this.oldPasswordInput);
|
||||
this.disposables.push(this.specifyOldPasswordCheckbox.onChanged(async () => {
|
||||
this.specifyOldPasswordCheckbox = this.createCheckbox(localizedConstants.SpecifyOldPasswordText, async (checked) => {
|
||||
this.oldPasswordInput.enabled = this.specifyOldPasswordCheckbox.checked;
|
||||
this.objectInfo.oldPassword = '';
|
||||
if (!this.specifyOldPasswordCheckbox.checked) {
|
||||
this.oldPasswordInput.value = '';
|
||||
}
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.disposables.push(this.oldPasswordInput.onTextChanged(async () => {
|
||||
this.objectInfo.oldPassword = this.oldPasswordInput.value;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
});
|
||||
this.oldPasswordInput = this.createPasswordInputBox(localizedConstants.OldPasswordText, async (newValue) => {
|
||||
this.objectInfo.oldPassword = newValue;
|
||||
}, '', false);
|
||||
const oldPasswordRow = this.createLabelInputContainer(localizedConstants.OldPasswordText, this.oldPasswordInput);
|
||||
items.push(this.specifyOldPasswordCheckbox, oldPasswordRow);
|
||||
}
|
||||
|
||||
if (this.viewInfo.supportAdvancedPasswordOptions) {
|
||||
this.enforcePasswordPolicyCheckbox = this.createCheckbox(localizedConstants.EnforcePasswordPolicyText, this.objectInfo.enforcePasswordPolicy);
|
||||
this.enforcePasswordExpirationCheckbox = this.createCheckbox(localizedConstants.EnforcePasswordExpirationText, this.objectInfo.enforcePasswordPolicy);
|
||||
this.mustChangePasswordCheckbox = this.createCheckbox(localizedConstants.MustChangePasswordText, this.objectInfo.mustChangePassword);
|
||||
this.disposables.push(this.enforcePasswordPolicyCheckbox.onChanged(async () => {
|
||||
const enforcePolicy = this.enforcePasswordPolicyCheckbox.checked;
|
||||
this.enforcePasswordPolicyCheckbox = this.createCheckbox(localizedConstants.EnforcePasswordPolicyText, async (checked) => {
|
||||
const enforcePolicy = checked;
|
||||
this.objectInfo.enforcePasswordPolicy = enforcePolicy;
|
||||
this.enforcePasswordExpirationCheckbox.enabled = enforcePolicy;
|
||||
this.mustChangePasswordCheckbox.enabled = enforcePolicy;
|
||||
this.enforcePasswordExpirationCheckbox.checked = enforcePolicy;
|
||||
this.mustChangePasswordCheckbox.checked = enforcePolicy;
|
||||
this.onObjectValueChange();
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.disposables.push(this.enforcePasswordExpirationCheckbox.onChanged(() => {
|
||||
const enforceExpiration = this.enforcePasswordExpirationCheckbox.checked;
|
||||
}, this.objectInfo.enforcePasswordPolicy);
|
||||
|
||||
this.enforcePasswordExpirationCheckbox = this.createCheckbox(localizedConstants.EnforcePasswordExpirationText, async (checked) => {
|
||||
const enforceExpiration = checked;
|
||||
this.objectInfo.enforcePasswordExpiration = enforceExpiration;
|
||||
this.mustChangePasswordCheckbox.enabled = enforceExpiration;
|
||||
this.mustChangePasswordCheckbox.checked = enforceExpiration;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
this.disposables.push(this.mustChangePasswordCheckbox.onChanged(() => {
|
||||
this.objectInfo.mustChangePassword = this.mustChangePasswordCheckbox.checked;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
}, this.objectInfo.enforcePasswordPolicy);
|
||||
|
||||
this.mustChangePasswordCheckbox = this.createCheckbox(localizedConstants.MustChangePasswordText, async (checked) => {
|
||||
this.objectInfo.mustChangePassword = checked;
|
||||
}, this.objectInfo.mustChangePassword);
|
||||
|
||||
items.push(this.enforcePasswordPolicyCheckbox, this.enforcePasswordExpirationCheckbox, this.mustChangePasswordCheckbox);
|
||||
|
||||
if (!this.options.isNewObject) {
|
||||
this.lockedOutCheckbox = this.createCheckbox(localizedConstants.LoginLockedOutText, this.objectInfo.isLockedOut, this.viewInfo.canEditLockedOutState);
|
||||
this.lockedOutCheckbox = this.createCheckbox(localizedConstants.LoginLockedOutText, async (checked) => {
|
||||
this.objectInfo.isLockedOut = checked;
|
||||
}, this.objectInfo.isLockedOut, this.viewInfo.canEditLockedOutState);
|
||||
items.push(this.lockedOutCheckbox);
|
||||
this.disposables.push(this.lockedOutCheckbox.onChanged(() => {
|
||||
this.objectInfo.isLockedOut = this.lockedOutCheckbox.checked!;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,25 +192,19 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
private initializeAdvancedSection(): void {
|
||||
const items: azdata.Component[] = [];
|
||||
if (this.viewInfo.supportAdvancedOptions) {
|
||||
this.defaultDatabaseDropdown = this.createDropdown(localizedConstants.DefaultDatabaseText, this.viewInfo.databases, this.objectInfo.defaultDatabase);
|
||||
this.defaultDatabaseDropdown = this.createDropdown(localizedConstants.DefaultDatabaseText, async (newValue) => {
|
||||
this.objectInfo.defaultDatabase = newValue;
|
||||
}, this.viewInfo.databases, this.objectInfo.defaultDatabase);
|
||||
const defaultDatabaseContainer = this.createLabelInputContainer(localizedConstants.DefaultDatabaseText, this.defaultDatabaseDropdown);
|
||||
this.disposables.push(this.defaultDatabaseDropdown.onValueChanged(() => {
|
||||
this.objectInfo.defaultDatabase = <string>this.defaultDatabaseDropdown.value;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
|
||||
this.defaultLanguageDropdown = this.createDropdown(localizedConstants.DefaultLanguageText, this.viewInfo.languages, this.objectInfo.defaultLanguage);
|
||||
this.defaultLanguageDropdown = this.createDropdown(localizedConstants.DefaultLanguageText, async (newValue) => {
|
||||
this.objectInfo.defaultLanguage = newValue;
|
||||
}, this.viewInfo.languages, this.objectInfo.defaultLanguage);
|
||||
const defaultLanguageContainer = this.createLabelInputContainer(localizedConstants.DefaultLanguageText, this.defaultLanguageDropdown);
|
||||
this.disposables.push(this.defaultLanguageDropdown.onValueChanged(() => {
|
||||
this.objectInfo.defaultLanguage = <string>this.defaultLanguageDropdown.value;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
|
||||
this.connectPermissionCheckbox = this.createCheckbox(localizedConstants.PermissionToConnectText, this.objectInfo.connectPermission);
|
||||
this.disposables.push(this.connectPermissionCheckbox.onChanged(() => {
|
||||
this.objectInfo.connectPermission = this.connectPermissionCheckbox.checked!;
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
this.connectPermissionCheckbox = this.createCheckbox(localizedConstants.PermissionToConnectText, async (checked) => {
|
||||
this.objectInfo.connectPermission = checked;
|
||||
}, this.objectInfo.connectPermission);
|
||||
items.push(defaultDatabaseContainer, defaultLanguageContainer, this.connectPermissionCheckbox);
|
||||
}
|
||||
|
||||
@@ -249,12 +212,14 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
}
|
||||
|
||||
private initializeServerRolesSection(): void {
|
||||
const serverRolesData = this.viewInfo.serverRoles.map(name => {
|
||||
const isRoleSelected = this.objectInfo.serverRoles.indexOf(name) !== -1;
|
||||
const isRoleSelectionEnabled = name !== PublicServerRoleName;
|
||||
return [{ enabled: isRoleSelectionEnabled, checked: isRoleSelected }, name];
|
||||
});
|
||||
this.serverRoleTable = this.createTableList(localizedConstants.ServerRoleSectionHeader, this.viewInfo.serverRoles, this.objectInfo.serverRoles, serverRolesData);
|
||||
this.serverRoleTable = this.createTableList(localizedConstants.ServerRoleSectionHeader,
|
||||
[localizedConstants.ServerRoleTypeDisplayNameInTitle],
|
||||
this.viewInfo.serverRoles,
|
||||
this.objectInfo.serverRoles,
|
||||
DefaultMaxTableHeight,
|
||||
(item) => {
|
||||
return item !== PublicServerRoleName
|
||||
});
|
||||
this.serverRoleSection = this.createGroup(localizedConstants.ServerRoleSectionHeader, [this.serverRoleTable]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user