mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 02:48:30 -05:00
simplify object management feature APIs (#22781)
This commit is contained in:
@@ -4,14 +4,13 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import { DefaultInputWidth, ObjectManagementDialogBase } from './objectManagementDialogBase';
|
||||
import { DefaultInputWidth, ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
|
||||
import { IObjectManagementService, ObjectManagement } from 'mssql';
|
||||
import * as localizedConstants from '../localizedConstants';
|
||||
import { AlterLoginDocUrl, AuthenticationType, CreateLoginDocUrl, NodeType, PublicServerRoleName } from '../constants';
|
||||
import { AlterLoginDocUrl, CreateLoginDocUrl, PublicServerRoleName } from '../constants';
|
||||
import { getAuthenticationTypeByDisplayName, getAuthenticationTypeDisplayName, isValidSQLPassword } from '../utils';
|
||||
|
||||
export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Login, ObjectManagement.LoginViewInfo> {
|
||||
|
||||
private generalSection: azdata.GroupContainer;
|
||||
private sqlAuthSection: azdata.GroupContainer;
|
||||
private serverRoleSection: azdata.GroupContainer;
|
||||
@@ -32,15 +31,19 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
private enabledCheckbox: azdata.CheckBoxComponent;
|
||||
private lockedOutCheckbox: azdata.CheckBoxComponent;
|
||||
|
||||
constructor(objectManagementService: IObjectManagementService, connectionUri: string, isNewObject: boolean, name?: string, objectExplorerContext?: azdata.ObjectExplorerContext) {
|
||||
super(NodeType.Login, isNewObject ? CreateLoginDocUrl : AlterLoginDocUrl, objectManagementService, connectionUri, isNewObject, name, objectExplorerContext);
|
||||
constructor(objectManagementService: IObjectManagementService, options: ObjectManagementDialogOptions) {
|
||||
super(objectManagementService, options);
|
||||
}
|
||||
|
||||
protected override get docUrl(): string {
|
||||
return this.options.isNewObject ? CreateLoginDocUrl : AlterLoginDocUrl
|
||||
}
|
||||
|
||||
protected override async onConfirmation(): Promise<boolean> {
|
||||
// Empty password is only allowed when advanced password options are supported and the password policy check is off.
|
||||
// To match the SSMS behavior, a warning is shown to the user.
|
||||
if (this.viewInfo.supportAdvancedPasswordOptions
|
||||
&& this.objectInfo.authenticationType === AuthenticationType.Sql
|
||||
&& this.objectInfo.authenticationType === ObjectManagement.AuthenticationType.Sql
|
||||
&& !this.objectInfo.password
|
||||
&& !this.objectInfo.enforcePasswordPolicy) {
|
||||
const result = await vscode.window.showWarningMessage(localizedConstants.BlankPasswordConfirmationText, { modal: true }, localizedConstants.YesText);
|
||||
@@ -54,14 +57,14 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
if (!this.objectInfo.name) {
|
||||
errors.push(localizedConstants.NameCannotBeEmptyError);
|
||||
}
|
||||
if (this.objectInfo.authenticationType === AuthenticationType.Sql) {
|
||||
if (this.objectInfo.authenticationType === ObjectManagement.AuthenticationType.Sql) {
|
||||
if (!this.objectInfo.password && !(this.viewInfo.supportAdvancedPasswordOptions && !this.objectInfo.enforcePasswordPolicy)) {
|
||||
errors.push(localizedConstants.PasswordCannotBeEmptyError);
|
||||
}
|
||||
|
||||
if (this.objectInfo.password && (this.objectInfo.enforcePasswordPolicy || !this.viewInfo.supportAdvancedPasswordOptions)
|
||||
&& !isValidSQLPassword(this.objectInfo.password, this.objectInfo.name)
|
||||
&& (this.isNewObject || this.objectInfo.password !== this.originalObjectInfo.password)) {
|
||||
&& (this.options.isNewObject || this.objectInfo.password !== this.originalObjectInfo.password)) {
|
||||
errors.push(localizedConstants.InvalidPasswordError);
|
||||
}
|
||||
|
||||
@@ -76,22 +79,8 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
return errors;
|
||||
}
|
||||
|
||||
protected async onComplete(): Promise<void> {
|
||||
if (this.isNewObject) {
|
||||
await this.objectManagementService.createLogin(this.contextId, this.objectInfo);
|
||||
} else {
|
||||
await this.objectManagementService.updateLogin(this.contextId, this.objectInfo);
|
||||
}
|
||||
}
|
||||
|
||||
protected async disposeView(): Promise<void> {
|
||||
await this.objectManagementService.disposeLoginView(this.contextId);
|
||||
}
|
||||
|
||||
protected async initializeData(): Promise<ObjectManagement.LoginViewInfo> {
|
||||
const viewInfo = await this.objectManagementService.initializeLoginView(this.connectionUri, this.contextId, this.isNewObject, this.objectName);
|
||||
viewInfo.objectInfo.password = viewInfo.objectInfo.password ?? '';
|
||||
return viewInfo;
|
||||
protected override postInitializeData(): void {
|
||||
this.objectInfo.password = this.objectInfo.password ?? '';
|
||||
}
|
||||
|
||||
protected async initializeUI(): Promise<void> {
|
||||
@@ -99,7 +88,7 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
this.initializeGeneralSection();
|
||||
sections.push(this.generalSection);
|
||||
|
||||
if (this.isNewObject || this.objectInfo.authenticationType === 'Sql') {
|
||||
if (this.options.isNewObject || this.objectInfo.authenticationType === 'Sql') {
|
||||
this.initializeSqlAuthSection();
|
||||
sections.push(this.sqlAuthSection);
|
||||
}
|
||||
@@ -114,14 +103,10 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
this.formContainer.addItems(sections);
|
||||
}
|
||||
|
||||
protected async generateScript(): Promise<string> {
|
||||
return this.objectManagementService.scriptLogin(this.contextId, this.objectInfo);
|
||||
}
|
||||
|
||||
private initializeGeneralSection(): void {
|
||||
this.nameInput = this.modelView.modelBuilder.inputBox().withProps({
|
||||
ariaLabel: localizedConstants.NameText,
|
||||
enabled: this.isNewObject,
|
||||
enabled: this.options.isNewObject,
|
||||
value: this.objectInfo.name,
|
||||
width: DefaultInputWidth
|
||||
}).component();
|
||||
@@ -142,7 +127,7 @@ 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.isNewObject);
|
||||
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.setViewByAuthenticationType();
|
||||
@@ -175,7 +160,7 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
const confirmPasswordRow = this.createLabelInputContainer(localizedConstants.ConfirmPasswordText, this.confirmPasswordInput);
|
||||
items.push(passwordRow, confirmPasswordRow);
|
||||
|
||||
if (!this.isNewObject) {
|
||||
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);
|
||||
@@ -222,7 +207,7 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
this.onObjectValueChange();
|
||||
}));
|
||||
items.push(this.enforcePasswordPolicyCheckbox, this.enforcePasswordExpirationCheckbox, this.mustChangePasswordCheckbox);
|
||||
if (!this.isNewObject) {
|
||||
if (!this.options.isNewObject) {
|
||||
this.lockedOutCheckbox = this.createCheckbox(localizedConstants.LoginLockedOutText, this.objectInfo.isLockedOut, this.viewInfo.canEditLockedOutState);
|
||||
items.push(this.lockedOutCheckbox);
|
||||
this.disposables.push(this.lockedOutCheckbox.onChanged(() => {
|
||||
|
||||
@@ -12,11 +12,11 @@ import * as vscode from 'vscode';
|
||||
import { EOL } from 'os';
|
||||
import { generateUuid } from 'vscode-languageclient/lib/utils/uuid';
|
||||
import { getErrorMessage } from '../../utils';
|
||||
import { NodeType, TelemetryActions, TelemetryViews } from '../constants';
|
||||
import { TelemetryActions, ObjectManagementViewName } from '../constants';
|
||||
import {
|
||||
CreateObjectOperationDisplayName, HelpText, LoadingDialogText,
|
||||
NameText,
|
||||
NewObjectDialogTitle, ObjectPropertiesDialogTitle, OkText, ScriptError, ScriptGeneratedText, ScriptText, SelectedText, UpdateObjectOperationDisplayName
|
||||
NewObjectDialogTitle, NoActionScriptedMessage, ObjectPropertiesDialogTitle, OkText, ScriptError, ScriptGeneratedText, ScriptText, SelectedText, UpdateObjectOperationDisplayName
|
||||
} from '../localizedConstants';
|
||||
import { deepClone, getNodeTypeDisplayName, refreshNode } from '../utils';
|
||||
import { TelemetryReporter } from '../../telemetry';
|
||||
@@ -34,14 +34,26 @@ export function getTableHeight(rowCount: number, minRowCount: number = DefaultTa
|
||||
return Math.min(Math.max(rowCount, minRowCount) * TableRowHeight + TableColumnHeaderHeight, maxHeight);
|
||||
}
|
||||
|
||||
function getDialogName(type: NodeType, isNewObject: boolean): string {
|
||||
function getDialogName(type: ObjectManagement.NodeType, isNewObject: boolean): string {
|
||||
return isNewObject ? `New${type}` : `${type}Properties`
|
||||
}
|
||||
|
||||
export interface ObjectManagementDialogOptions {
|
||||
connectionUri: string;
|
||||
database?: string;
|
||||
objectType: ObjectManagement.NodeType;
|
||||
isNewObject: boolean;
|
||||
parentUrn: string;
|
||||
objectUrn?: string;
|
||||
objectExplorerContext?: azdata.ObjectExplorerContext;
|
||||
width?: azdata.window.DialogWidth;
|
||||
objectName?: string;
|
||||
}
|
||||
|
||||
export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectManagement.SqlObject, ViewInfoType extends ObjectManagement.ObjectViewInfo<ObjectInfoType>> {
|
||||
protected readonly disposables: vscode.Disposable[] = [];
|
||||
protected readonly dialogObject: azdata.window.Dialog;
|
||||
protected readonly contextId: string;
|
||||
private _contextId: string;
|
||||
private _viewInfo: ViewInfoType;
|
||||
private _originalObjectInfo: ObjectInfoType;
|
||||
private _modelView: azdata.ModelView;
|
||||
@@ -50,28 +62,22 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
private _helpButton: azdata.window.Button;
|
||||
private _scriptButton: azdata.window.Button;
|
||||
|
||||
constructor(private readonly objectType: NodeType,
|
||||
docUrl: string,
|
||||
protected readonly objectManagementService: IObjectManagementService,
|
||||
protected readonly connectionUri: string,
|
||||
protected isNewObject: boolean,
|
||||
protected readonly objectName: string = '',
|
||||
protected readonly objectExplorerContext?: azdata.ObjectExplorerContext,
|
||||
dialogWidth: azdata.window.DialogWidth = 'narrow') {
|
||||
const objectTypeDisplayName = getNodeTypeDisplayName(objectType, true);
|
||||
const dialogTitle = isNewObject ? NewObjectDialogTitle(objectTypeDisplayName) : ObjectPropertiesDialogTitle(objectTypeDisplayName, objectName);
|
||||
this.dialogObject = azdata.window.createModelViewDialog(dialogTitle, getDialogName(objectType, isNewObject), dialogWidth);
|
||||
constructor(protected readonly objectManagementService: IObjectManagementService, protected readonly options: ObjectManagementDialogOptions) {
|
||||
this.options.width = this.options.width || 'narrow';
|
||||
const objectTypeDisplayName = getNodeTypeDisplayName(options.objectType, true);
|
||||
const dialogTitle = options.isNewObject ? NewObjectDialogTitle(objectTypeDisplayName) : ObjectPropertiesDialogTitle(objectTypeDisplayName, options.objectName);
|
||||
this.dialogObject = azdata.window.createModelViewDialog(dialogTitle, getDialogName(options.objectType, options.isNewObject), options.width);
|
||||
this.dialogObject.okButton.label = OkText;
|
||||
this.disposables.push(this.dialogObject.onClosed(async (reason: azdata.window.CloseReason) => { await this.dispose(reason); }));
|
||||
this._helpButton = azdata.window.createButton(HelpText, 'left');
|
||||
this.disposables.push(this._helpButton.onClick(async () => {
|
||||
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(docUrl));
|
||||
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(this.docUrl));
|
||||
}));
|
||||
this._scriptButton = azdata.window.createButton(ScriptText, 'left');
|
||||
this.disposables.push(this._scriptButton.onClick(async () => { await this.onScriptButtonClick(); }));
|
||||
this.dialogObject.customButtons = [this._helpButton, this._scriptButton];
|
||||
this.updateLoadingStatus(true);
|
||||
this.contextId = generateUuid();
|
||||
this._contextId = generateUuid();
|
||||
this.dialogObject.registerCloseValidator(async (): Promise<boolean> => {
|
||||
const confirmed = await this.onConfirmation();
|
||||
if (!confirmed) {
|
||||
@@ -81,18 +87,13 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract initializeData(): Promise<ViewInfoType>;
|
||||
protected abstract initializeUI(): Promise<void>;
|
||||
protected abstract onComplete(): Promise<void>;
|
||||
protected async onDispose(): Promise<void> { }
|
||||
protected abstract validateInput(): Promise<string[]>;
|
||||
protected abstract generateScript(): Promise<string>;
|
||||
protected abstract get docUrl(): string;
|
||||
|
||||
/**
|
||||
* Dispose the information related to this view in the backend service.
|
||||
*/
|
||||
protected abstract disposeView(): Promise<void>;
|
||||
protected postInitializeData(): void {
|
||||
|
||||
}
|
||||
protected onObjectValueChange(): void {
|
||||
this.dialogObject.okButton.enabled = this.isDirty;
|
||||
}
|
||||
@@ -141,28 +142,28 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
});
|
||||
}));
|
||||
azdata.window.openDialog(this.dialogObject);
|
||||
this._viewInfo = await this.initializeData();
|
||||
await this.initializeData();
|
||||
await initializeViewPromise;
|
||||
await this.initializeUI();
|
||||
this._originalObjectInfo = deepClone(this.objectInfo);
|
||||
const typeDisplayName = getNodeTypeDisplayName(this.objectType);
|
||||
const typeDisplayName = getNodeTypeDisplayName(this.options.objectType);
|
||||
this.dialogObject.registerOperation({
|
||||
displayName: this.isNewObject ? CreateObjectOperationDisplayName(typeDisplayName)
|
||||
: UpdateObjectOperationDisplayName(typeDisplayName, this.objectName),
|
||||
displayName: this.options.isNewObject ? CreateObjectOperationDisplayName(typeDisplayName)
|
||||
: UpdateObjectOperationDisplayName(typeDisplayName, this.options.objectName),
|
||||
description: '',
|
||||
isCancelable: false,
|
||||
operation: async (operation: azdata.BackgroundOperation): Promise<void> => {
|
||||
const actionName = this.isNewObject ? TelemetryActions.CreateObject : TelemetryActions.UpdateObject;
|
||||
const actionName = this.options.isNewObject ? TelemetryActions.CreateObject : TelemetryActions.UpdateObject;
|
||||
try {
|
||||
if (JSON.stringify(this.objectInfo) !== JSON.stringify(this._originalObjectInfo)) {
|
||||
const startTime = Date.now();
|
||||
await this.onComplete();
|
||||
if (this.isNewObject && this.objectExplorerContext) {
|
||||
await refreshNode(this.objectExplorerContext);
|
||||
await this.objectManagementService.save(this._contextId, this.objectInfo);
|
||||
if (this.options.isNewObject && this.options.objectExplorerContext) {
|
||||
await refreshNode(this.options.objectExplorerContext);
|
||||
}
|
||||
|
||||
TelemetryReporter.sendTelemetryEvent(actionName, {
|
||||
objectType: this.objectType
|
||||
objectType: this.options.objectType
|
||||
}, {
|
||||
elapsedTimeMs: Date.now() - startTime
|
||||
});
|
||||
@@ -171,8 +172,8 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
}
|
||||
catch (err) {
|
||||
operation.updateStatus(azdata.TaskStatus.Failed, getErrorMessage(err));
|
||||
TelemetryReporter.createErrorEvent2(TelemetryViews.ObjectManagement, actionName, err).withAdditionalProperties({
|
||||
objectType: this.objectType
|
||||
TelemetryReporter.createErrorEvent2(ObjectManagementViewName, actionName, err).withAdditionalProperties({
|
||||
objectType: this.options.objectType
|
||||
}).send();
|
||||
} finally {
|
||||
await this.disposeView();
|
||||
@@ -181,9 +182,9 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
});
|
||||
this.updateLoadingStatus(false);
|
||||
} catch (err) {
|
||||
const actionName = this.isNewObject ? TelemetryActions.OpenNewObjectDialog : TelemetryActions.OpenPropertiesDialog;
|
||||
TelemetryReporter.createErrorEvent2(TelemetryViews.ObjectManagement, actionName, err).withAdditionalProperties({
|
||||
objectType: this.objectType
|
||||
const actionName = this.options.isNewObject ? TelemetryActions.OpenNewObjectDialog : TelemetryActions.OpenPropertiesDialog;
|
||||
TelemetryReporter.createErrorEvent2(ObjectManagementViewName, actionName, err).withAdditionalProperties({
|
||||
objectType: this.options.objectType
|
||||
}).send();
|
||||
void vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
azdata.window.closeDialog(this.dialogObject);
|
||||
@@ -191,13 +192,22 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
}
|
||||
|
||||
private async dispose(reason: azdata.window.CloseReason): Promise<void> {
|
||||
await this.onDispose();
|
||||
this.disposables.forEach(disposable => disposable.dispose());
|
||||
if (reason !== 'ok') {
|
||||
await this.disposeView();
|
||||
}
|
||||
}
|
||||
|
||||
private async disposeView(): Promise<void> {
|
||||
await this.objectManagementService.disposeView(this._contextId);
|
||||
}
|
||||
|
||||
private async initializeData(): Promise<void> {
|
||||
const viewInfo = await this.objectManagementService.initializeView(this._contextId, this.options.objectType, this.options.connectionUri, this.options.database, this.options.isNewObject, this.options.parentUrn, this.options.objectUrn);
|
||||
this._viewInfo = viewInfo as ViewInfoType;
|
||||
this.postInitializeData();
|
||||
}
|
||||
|
||||
protected async runValidation(showErrorMessage: boolean = true): Promise<boolean> {
|
||||
const errors = await this.validateInput();
|
||||
if (errors.length > 0 && (this.dialogObject.message?.text || showErrorMessage)) {
|
||||
@@ -335,10 +345,16 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
const script = await this.generateScript();
|
||||
await azdata.queryeditor.openQueryDocument({ content: script }, providerId);
|
||||
let message: string;
|
||||
const script = await this.objectManagementService.script(this._contextId, this.objectInfo);
|
||||
if (script) {
|
||||
message = ScriptGeneratedText;
|
||||
await azdata.queryeditor.openQueryDocument({ content: script }, providerId);
|
||||
} else {
|
||||
message = NoActionScriptedMessage;
|
||||
}
|
||||
this.dialogObject.message = {
|
||||
text: ScriptGeneratedText,
|
||||
text: message,
|
||||
level: azdata.window.MessageLevel.Information
|
||||
};
|
||||
} catch (err) {
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as azdata from 'azdata';
|
||||
import { DefaultInputWidth, ObjectManagementDialogBase } from './objectManagementDialogBase';
|
||||
import { DefaultInputWidth, ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
|
||||
import { IObjectManagementService, ObjectManagement } from 'mssql';
|
||||
import * as localizedConstants from '../localizedConstants';
|
||||
import { AlterUserDocUrl, AuthenticationType, CreateUserDocUrl, NodeType, UserType } from '../constants';
|
||||
import { AlterUserDocUrl, CreateUserDocUrl } from '../constants';
|
||||
import { getAuthenticationTypeByDisplayName, getAuthenticationTypeDisplayName, getUserTypeByDisplayName, getUserTypeDisplayName, isValidSQLPassword } from '../utils';
|
||||
|
||||
export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User, ObjectManagement.UserViewInfo> {
|
||||
@@ -31,14 +31,16 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
private ownedSchemaTable: azdata.TableComponent;
|
||||
private membershipTable: azdata.TableComponent;
|
||||
|
||||
constructor(objectManagementService: IObjectManagementService, connectionUri: string, private readonly database: string, isNewObject: boolean, name?: string, objectExplorerContext?: azdata.ObjectExplorerContext) {
|
||||
super(NodeType.User, isNewObject ? CreateUserDocUrl : AlterUserDocUrl, objectManagementService, connectionUri, isNewObject, name, objectExplorerContext);
|
||||
constructor(objectManagementService: IObjectManagementService, options: ObjectManagementDialogOptions) {
|
||||
super(objectManagementService, options);
|
||||
}
|
||||
|
||||
protected async initializeData(): Promise<ObjectManagement.UserViewInfo> {
|
||||
const viewInfo = await this.objectManagementService.initializeUserView(this.connectionUri, this.database, this.contextId, this.isNewObject, this.objectName);
|
||||
viewInfo.objectInfo.password = viewInfo.objectInfo.password ?? '';
|
||||
return viewInfo;
|
||||
protected override get docUrl(): string {
|
||||
return this.options.isNewObject ? CreateUserDocUrl : AlterUserDocUrl;
|
||||
}
|
||||
|
||||
protected override postInitializeData(): void {
|
||||
this.objectInfo.password = this.objectInfo.password ?? '';
|
||||
}
|
||||
|
||||
protected async validateInput(): Promise<string[]> {
|
||||
@@ -46,7 +48,7 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
if (!this.objectInfo.name) {
|
||||
errors.push(localizedConstants.NameCannotBeEmptyError);
|
||||
}
|
||||
if (this.objectInfo.type === UserType.Contained && this.objectInfo.authenticationType === AuthenticationType.Sql) {
|
||||
if (this.objectInfo.type === ObjectManagement.UserType.Contained && this.objectInfo.authenticationType === ObjectManagement.AuthenticationType.Sql) {
|
||||
if (!this.objectInfo.password) {
|
||||
errors.push(localizedConstants.PasswordCannotBeEmptyError);
|
||||
}
|
||||
@@ -54,10 +56,10 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
errors.push(localizedConstants.PasswordsNotMatchError);
|
||||
}
|
||||
if (!isValidSQLPassword(this.objectInfo.password!, this.objectInfo.name)
|
||||
&& (this.isNewObject || this.objectInfo.password !== this.originalObjectInfo.password)) {
|
||||
&& (this.options.isNewObject || this.objectInfo.password !== this.originalObjectInfo.password)) {
|
||||
errors.push(localizedConstants.InvalidPasswordError);
|
||||
}
|
||||
} else if (this.objectInfo.type === UserType.WithLogin) {
|
||||
} else if (this.objectInfo.type === ObjectManagement.UserType.WithLogin) {
|
||||
if (!this.objectInfo.loginName) {
|
||||
errors.push(localizedConstants.LoginNotSelectedError);
|
||||
}
|
||||
@@ -65,18 +67,6 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
return errors;
|
||||
}
|
||||
|
||||
protected async onComplete(): Promise<void> {
|
||||
if (this.isNewObject) {
|
||||
await this.objectManagementService.createUser(this.contextId, this.objectInfo);
|
||||
} else {
|
||||
await this.objectManagementService.updateUser(this.contextId, this.objectInfo);
|
||||
}
|
||||
}
|
||||
|
||||
protected async disposeView(): Promise<void> {
|
||||
await this.objectManagementService.disposeUserView(this.contextId);
|
||||
}
|
||||
|
||||
protected async initializeUI(): Promise<void> {
|
||||
this.initializeGeneralSection();
|
||||
this.initializeOwnedSchemaSection();
|
||||
@@ -88,14 +78,10 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
}, 100);
|
||||
}
|
||||
|
||||
protected async generateScript(): Promise<string> {
|
||||
return this.objectManagementService.scriptUser(this.contextId, this.objectInfo);
|
||||
}
|
||||
|
||||
private initializeGeneralSection(): void {
|
||||
this.nameInput = this.modelView.modelBuilder.inputBox().withProps({
|
||||
ariaLabel: localizedConstants.NameText,
|
||||
enabled: this.isNewObject,
|
||||
enabled: this.options.isNewObject,
|
||||
value: this.objectInfo.name,
|
||||
width: DefaultInputWidth
|
||||
}).component();
|
||||
@@ -114,7 +100,7 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
|
||||
// only supporting user with login for initial preview
|
||||
const userTypes = [localizedConstants.UserWithLoginText, localizedConstants.UserWithWindowsGroupLoginText, localizedConstants.ContainedUserText, localizedConstants.UserWithNoConnectAccess];
|
||||
this.typeDropdown = this.createDropdown(localizedConstants.UserTypeText, userTypes, getUserTypeDisplayName(this.objectInfo.type), this.isNewObject);
|
||||
this.typeDropdown = this.createDropdown(localizedConstants.UserTypeText, userTypes, getUserTypeDisplayName(this.objectInfo.type), this.options.isNewObject);
|
||||
this.disposables.push(this.typeDropdown.onValueChanged(async () => {
|
||||
this.objectInfo.type = getUserTypeByDisplayName(<string>this.typeDropdown.value);
|
||||
this.onObjectValueChange();
|
||||
@@ -122,7 +108,7 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
await this.runValidation(false);
|
||||
}));
|
||||
this.typeContainer = this.createLabelInputContainer(localizedConstants.UserTypeText, this.typeDropdown);
|
||||
this.loginDropdown = this.createDropdown(localizedConstants.LoginText, this.viewInfo.logins, this.objectInfo.loginName, this.isNewObject);
|
||||
this.loginDropdown = this.createDropdown(localizedConstants.LoginText, this.viewInfo.logins, this.objectInfo.loginName, this.options.isNewObject);
|
||||
this.disposables.push(this.loginDropdown.onValueChanged(async () => {
|
||||
this.objectInfo.loginName = <string>this.loginDropdown.value;
|
||||
this.onObjectValueChange();
|
||||
@@ -140,7 +126,7 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
if (this.viewInfo.supportAADAuthentication) {
|
||||
authTypes.push(localizedConstants.AADAuthenticationTypeDisplayText);
|
||||
}
|
||||
this.authTypeDropdown = this.createDropdown(localizedConstants.AuthTypeText, authTypes, getAuthenticationTypeDisplayName(this.objectInfo.authenticationType), this.isNewObject);
|
||||
this.authTypeDropdown = this.createDropdown(localizedConstants.AuthTypeText, authTypes, getAuthenticationTypeDisplayName(this.objectInfo.authenticationType), this.options.isNewObject);
|
||||
this.authTypeContainer = this.createLabelInputContainer(localizedConstants.AuthTypeText, this.authTypeDropdown);
|
||||
this.disposables.push(this.authTypeDropdown.onValueChanged(async () => {
|
||||
this.objectInfo.authenticationType = getAuthenticationTypeByDisplayName(<string>this.authTypeDropdown.value);
|
||||
|
||||
Reference in New Issue
Block a user