mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-13 17:22:15 -05:00
simplify object management feature APIs (#22781)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
|
||||
"version": "4.7.0.12",
|
||||
"version": "4.7.0.14",
|
||||
"downloadFileNames": {
|
||||
"Windows_86": "win-x86-net7.0.zip",
|
||||
"Windows_64": "win-x64-net7.0.zip",
|
||||
|
||||
@@ -73,14 +73,9 @@
|
||||
"title": "%title.changeNotebookConnection%"
|
||||
},
|
||||
{
|
||||
"command": "mssql.newLogin",
|
||||
"command": "mssql.newObject",
|
||||
"category": "MSSQL",
|
||||
"title": "%title.newLogin%"
|
||||
},
|
||||
{
|
||||
"command": "mssql.newUser",
|
||||
"category": "MSSQL",
|
||||
"title": "%title.newUser%"
|
||||
"title": "%title.newObject%"
|
||||
},
|
||||
{
|
||||
"command": "mssql.objectProperties",
|
||||
@@ -469,11 +464,7 @@
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "mssql.newLogin",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "mssql.newUser",
|
||||
"command": "mssql.newObject",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
@@ -502,13 +493,8 @@
|
||||
"group": "0_query@1"
|
||||
},
|
||||
{
|
||||
"command": "mssql.newLogin",
|
||||
"when": "connectionProvider == MSSQL && nodeType == Folder && objectType == ServerLevelLogins && config.workbench.enablePreviewFeatures",
|
||||
"group": "0_query@1"
|
||||
},
|
||||
{
|
||||
"command": "mssql.newUser",
|
||||
"when": "connectionProvider == MSSQL && nodeType == Folder && objectType == Users && config.workbench.enablePreviewFeatures",
|
||||
"command": "mssql.newObject",
|
||||
"when": "connectionProvider == MSSQL && nodeType == Folder && objectType =~ /^(ServerLevelLogins|Users)$/ && config.workbench.enablePreviewFeatures",
|
||||
"group": "0_query@1"
|
||||
},
|
||||
{
|
||||
@@ -553,13 +539,8 @@
|
||||
"group": "connection@1"
|
||||
},
|
||||
{
|
||||
"command": "mssql.newLogin",
|
||||
"when": "connectionProvider == MSSQL && nodeType == Folder && objectType == ServerLevelLogins && config.workbench.enablePreviewFeatures",
|
||||
"group": "connection@1"
|
||||
},
|
||||
{
|
||||
"command": "mssql.newUser",
|
||||
"when": "connectionProvider == MSSQL && nodeType == Folder && objectType == Users && config.workbench.enablePreviewFeatures",
|
||||
"command": "mssql.newObject",
|
||||
"when": "connectionProvider == MSSQL && nodeType == Folder && objectType =~ /^(ServerLevelLogins|Users)$/ && config.workbench.enablePreviewFeatures",
|
||||
"group": "connection@1"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -183,11 +183,7 @@
|
||||
"mssql.objectExplorer.enableGroupBySchemaTitle": "SQL Server: Enable Group By Schema",
|
||||
"mssql.objectExplorer.disableGroupBySchemaTitle": "SQL Server: Disable Group By Schema",
|
||||
"mssql.objectExplorer.expandTimeout": "The timeout in seconds for expanding a node in Object Explorer. The default value is 45 seconds.",
|
||||
"title.newServerRole": "New Server Role",
|
||||
"title.newLogin": "New Login",
|
||||
"title.newDatabaseRole": "New Database Role",
|
||||
"title.newApplicationRole": "New Application Role",
|
||||
"title.newUser": "New User",
|
||||
"title.newObject": "New",
|
||||
"title.objectProperties": "Properties (Preview)",
|
||||
"title.deleteObject": "Delete",
|
||||
"title.renameObject": "Rename"
|
||||
|
||||
@@ -1534,103 +1534,51 @@ export namespace ExecutionPlanComparisonRequest {
|
||||
// ------------------------------- < Execution Plan > ------------------------------------
|
||||
|
||||
// ------------------------------- < Object Management > ------------------------------------
|
||||
export interface InitializeLoginViewRequestParams {
|
||||
export interface InitializeViewRequestParams {
|
||||
connectionUri: string;
|
||||
contextId: string;
|
||||
isNewObject: boolean;
|
||||
name: string | undefined;
|
||||
}
|
||||
|
||||
export namespace InitializeLoginViewRequest {
|
||||
export const type = new RequestType<InitializeLoginViewRequestParams, mssql.ObjectManagement.LoginViewInfo, void, void>('objectManagement/initializeLoginView');
|
||||
}
|
||||
|
||||
export interface CreateLoginRequestParams {
|
||||
contextId: string;
|
||||
login: mssql.ObjectManagement.Login;
|
||||
}
|
||||
|
||||
export namespace CreateLoginRequest {
|
||||
export const type = new RequestType<CreateLoginRequestParams, void, void, void>('objectManagement/createLogin');
|
||||
}
|
||||
|
||||
export interface ScriptLoginRequestParams {
|
||||
contextId: string;
|
||||
login: mssql.ObjectManagement.Login;
|
||||
}
|
||||
|
||||
export namespace ScriptLoginRequest {
|
||||
export const type = new RequestType<ScriptLoginRequestParams, string, void, void>('objectManagement/scriptLogin');
|
||||
}
|
||||
|
||||
export interface UpdateLoginRequestParams {
|
||||
contextId: string;
|
||||
login: mssql.ObjectManagement.Login;
|
||||
}
|
||||
|
||||
export namespace UpdateLoginRequest {
|
||||
export const type = new RequestType<UpdateLoginRequestParams, void, void, void>('objectManagement/updateLogin');
|
||||
}
|
||||
|
||||
export interface DisposeLoginViewRequestParams {
|
||||
contextId: string;
|
||||
}
|
||||
|
||||
export namespace DisposeLoginViewRequest {
|
||||
export const type = new RequestType<DisposeLoginViewRequestParams, void, void, void>('objectManagement/disposeLoginView');
|
||||
}
|
||||
|
||||
export interface InitializeUserViewRequestParams {
|
||||
connectionUri: string;
|
||||
contextId: string;
|
||||
isNewObject: boolean;
|
||||
database: string;
|
||||
name: string | undefined;
|
||||
}
|
||||
|
||||
export namespace InitializeUserViewRequest {
|
||||
export const type = new RequestType<InitializeUserViewRequestParams, mssql.ObjectManagement.UserViewInfo, void, void>('objectManagement/initializeUserView');
|
||||
}
|
||||
|
||||
export interface CreateUserRequestParams {
|
||||
contextId: string;
|
||||
user: mssql.ObjectManagement.User;
|
||||
isNewObject: boolean;
|
||||
objectType: string;
|
||||
parentUrn: string;
|
||||
objectUrn?: string;
|
||||
}
|
||||
|
||||
export namespace CreateUserRequest {
|
||||
export const type = new RequestType<CreateUserRequestParams, void, void, void>('objectManagement/createUser');
|
||||
export namespace InitializeViewRequest {
|
||||
export const type = new RequestType<InitializeViewRequestParams, mssql.ObjectManagement.ObjectViewInfo<mssql.ObjectManagement.SqlObject>, void, void>('objectManagement/initializeView');
|
||||
}
|
||||
|
||||
export interface ScriptUserRequestParams {
|
||||
export interface SaveObjectRequestParams {
|
||||
contextId: string;
|
||||
user: mssql.ObjectManagement.User;
|
||||
object: mssql.ObjectManagement.SqlObject;
|
||||
}
|
||||
|
||||
export namespace ScriptUserRequest {
|
||||
export const type = new RequestType<ScriptUserRequestParams, string, void, void>('objectManagement/scriptUser');
|
||||
export namespace SaveObjectRequest {
|
||||
export const type = new RequestType<SaveObjectRequestParams, void, void, void>('objectManagement/save');
|
||||
}
|
||||
|
||||
export interface UpdateUserRequestParams {
|
||||
export interface ScriptObjectRequestParams {
|
||||
contextId: string;
|
||||
user: mssql.ObjectManagement.User;
|
||||
object: mssql.ObjectManagement.SqlObject;
|
||||
}
|
||||
|
||||
export namespace UpdateUserRequest {
|
||||
export const type = new RequestType<UpdateUserRequestParams, void, void, void>('objectManagement/updateUser');
|
||||
export namespace ScriptObjectRequest {
|
||||
export const type = new RequestType<ScriptObjectRequestParams, string, void, void>('objectManagement/script');
|
||||
}
|
||||
|
||||
export interface DisposeUserViewRequestParams {
|
||||
export interface DisposeViewRequestParams {
|
||||
contextId: string;
|
||||
}
|
||||
|
||||
export namespace DisposeUserViewRequest {
|
||||
export const type = new RequestType<DisposeUserViewRequestParams, void, void, void>('objectManagement/disposeUserView');
|
||||
export namespace DisposeViewRequest {
|
||||
export const type = new RequestType<DisposeViewRequestParams, void, void, void>('objectManagement/disposeView');
|
||||
}
|
||||
|
||||
export interface RenameObjectRequestParams {
|
||||
connectionUri: string;
|
||||
newName: string;
|
||||
objectUrn: string;
|
||||
objectType: mssql.ObjectManagement.NodeType;
|
||||
}
|
||||
|
||||
export namespace RenameObjectRequest {
|
||||
@@ -1640,11 +1588,13 @@ export namespace RenameObjectRequest {
|
||||
export interface DropObjectRequestParams {
|
||||
connectionUri: string;
|
||||
objectUrn: string;
|
||||
objectType: mssql.ObjectManagement.NodeType;
|
||||
}
|
||||
|
||||
export namespace DropObjectRequest {
|
||||
export const type = new RequestType<DropObjectRequestParams, void, void, void>('objectManagement/drop');
|
||||
}
|
||||
|
||||
// ------------------------------- < Object Management > ------------------------------------
|
||||
|
||||
// ------------------------------- < Encryption IV/KEY updation Event > ------------------------------------
|
||||
|
||||
94
extensions/mssql/src/mssql.d.ts
vendored
94
extensions/mssql/src/mssql.d.ts
vendored
@@ -875,6 +875,19 @@ declare module 'mssql' {
|
||||
|
||||
// Object Management - Begin.
|
||||
export namespace ObjectManagement {
|
||||
|
||||
/**
|
||||
* Object types.
|
||||
*/
|
||||
export const enum NodeType {
|
||||
Column = "Column",
|
||||
Database = "Database",
|
||||
ServerLevelLogin = "ServerLevelLogin",
|
||||
Table = "Table",
|
||||
User = "User",
|
||||
View = "View"
|
||||
}
|
||||
|
||||
/**
|
||||
* Base interface for all the objects.
|
||||
*/
|
||||
@@ -963,7 +976,7 @@ declare module 'mssql' {
|
||||
/**
|
||||
* The authentication types.
|
||||
*/
|
||||
export enum AuthenticationType {
|
||||
export const enum AuthenticationType {
|
||||
Windows = 'Windows',
|
||||
Sql = 'Sql',
|
||||
AzureActiveDirectory = 'AAD'
|
||||
@@ -1086,7 +1099,7 @@ declare module 'mssql' {
|
||||
/**
|
||||
* User types.
|
||||
*/
|
||||
export enum UserType {
|
||||
export const enum UserType {
|
||||
/**
|
||||
* User with a server level login.
|
||||
*/
|
||||
@@ -1188,81 +1201,48 @@ declare module 'mssql' {
|
||||
|
||||
export interface IObjectManagementService {
|
||||
/**
|
||||
* Initialize the login view and return the information to render the view.
|
||||
* Initialize the object view and return the information to render the view.
|
||||
* @param contextId The context id of the view, generated by the extension and will be used in subsequent save/script/dispose operations.
|
||||
* @param objectType The object type.
|
||||
* @param connectionUri The original connection's URI.
|
||||
* @param contextId The context id of the view, generated by the extension and will be used in subsequent create/update/dispose operations.
|
||||
* @param isNewObject Whether the view is for creating a new login object.
|
||||
* @param name Name of the login. Only applicable when isNewObject is false.
|
||||
* @param database The target database.
|
||||
* @param isNewObject Whether the view is for creating a new object.
|
||||
* @param parentUrn The parent object's URN.
|
||||
* @param objectUrn The object's URN.
|
||||
*/
|
||||
initializeLoginView(connectionUri: string, contextId: string, isNewObject: boolean, name: string | undefined): Thenable<ObjectManagement.LoginViewInfo>;
|
||||
initializeView(contextId: string, objectType: ObjectManagement.NodeType, connectionUri: string, database: string, isNewObject: boolean, parentUrn: string, objectUrn: string): Thenable<ObjectManagement.ObjectViewInfo<ObjectManagement.SqlObject>>;
|
||||
/**
|
||||
* Create a login.
|
||||
* @param contextId The login view's context id.
|
||||
* @param login The login information.
|
||||
* Save an object.
|
||||
* @param contextId The object view's context id.
|
||||
* @param object The object to be saved.
|
||||
*/
|
||||
createLogin(contextId: string, login: ObjectManagement.Login): Thenable<void>;
|
||||
save(contextId: string, object: ObjectManagement.SqlObject): Thenable<void>;
|
||||
/**
|
||||
* Update a login.
|
||||
* @param contextId The login view's context id.
|
||||
* @param login The login information.
|
||||
* Script an object.
|
||||
* @param contextId The object view's context id.
|
||||
* @param object The object to be scripted.
|
||||
*/
|
||||
updateLogin(contextId: string, login: ObjectManagement.Login): Thenable<void>;
|
||||
script(contextId: string, object: ObjectManagement.SqlObject): Thenable<string>;
|
||||
/**
|
||||
* Script a login.
|
||||
* @param contextId The login view's context id.
|
||||
* @param login The login information.
|
||||
*/
|
||||
scriptLogin(contextId: string, login: ObjectManagement.Login): Thenable<string>;
|
||||
/**
|
||||
* Dispose the login view.
|
||||
* Dispose a view.
|
||||
* @param contextId The id of the view.
|
||||
*/
|
||||
disposeLoginView(contextId: string): Thenable<void>;
|
||||
/**
|
||||
* Initialize the user view and return the information to render the view.
|
||||
* @param connectionUri The original connection's URI.
|
||||
* @param database Name of the database.
|
||||
* @param contextId The id of the view, generated by the extension and will be used in subsequent create/update/dispose operations.
|
||||
* @param isNewObject Whether the view is for creating a new user object.
|
||||
* @param name Name of the user. Only applicable when isNewObject is false.
|
||||
*/
|
||||
initializeUserView(connectionUri: string, database: string, contextId: string, isNewObject: boolean, name: string | undefined): Thenable<ObjectManagement.UserViewInfo>;
|
||||
/**
|
||||
* Create a user.
|
||||
* @param contextId Id of the view.
|
||||
* @param user The user information.
|
||||
*/
|
||||
createUser(contextId: string, user: ObjectManagement.User): Thenable<void>;
|
||||
/**
|
||||
* Update a user.
|
||||
* @param contextId Id of the view.
|
||||
* @param user The user information.
|
||||
*/
|
||||
updateUser(contextId: string, user: ObjectManagement.User): Thenable<void>;
|
||||
/**
|
||||
* Script a user.
|
||||
* @param contextId Id of the view.
|
||||
* @param user The user information.
|
||||
*/
|
||||
scriptUser(contextId: string, user: ObjectManagement.User): Thenable<string>;
|
||||
/**
|
||||
* Dispose the user view.
|
||||
* @param contextId The id of the view.
|
||||
*/
|
||||
disposeUserView(contextId: string): Thenable<void>;
|
||||
disposeView(contextId: string): Thenable<void>;
|
||||
/**
|
||||
* Rename an object.
|
||||
* @param connectionUri The URI of the server connection.
|
||||
* @param objectType The object type.
|
||||
* @param objectUrn SMO Urn of the object to be renamed. More information: https://learn.microsoft.com/sql/relational-databases/server-management-objects-smo/overview-smo
|
||||
* @param newName The new name of the object.
|
||||
*/
|
||||
rename(connectionUri: string, objectUrn: string, newName: string): Thenable<void>;
|
||||
rename(connectionUri: string, objectType: ObjectManagement.NodeType, objectUrn: string, newName: string): Thenable<void>;
|
||||
/**
|
||||
* Drop an object.
|
||||
* @param connectionUri The URI of the server connection.
|
||||
* @param objectType The object type.
|
||||
* @param objectUrn SMO Urn of the object to be dropped. More information: https://learn.microsoft.com/sql/relational-databases/server-management-objects-smo/overview-smo
|
||||
*/
|
||||
drop(connectionUri: string, objectUrn: string): Thenable<void>;
|
||||
drop(connectionUri: string, objectType: ObjectManagement.NodeType, objectUrn: string): Thenable<void>;
|
||||
}
|
||||
// Object Management - End.
|
||||
}
|
||||
|
||||
@@ -9,22 +9,20 @@ import * as vscode from 'vscode';
|
||||
import { LoginDialog } from './ui/loginDialog';
|
||||
import { TestObjectManagementService } from './objectManagementService';
|
||||
import { getErrorMessage } from '../utils';
|
||||
import { NodeType, TelemetryActions, TelemetryViews } from './constants';
|
||||
import { FolderType, TelemetryActions, ObjectManagementViewName } from './constants';
|
||||
import * as localizedConstants from './localizedConstants';
|
||||
import { UserDialog } from './ui/userDialog';
|
||||
import { IObjectManagementService } from 'mssql';
|
||||
import { IObjectManagementService, ObjectManagement } from 'mssql';
|
||||
import * as constants from '../constants';
|
||||
import { getNodeTypeDisplayName, refreshParentNode } from './utils';
|
||||
import { TelemetryReporter } from '../telemetry';
|
||||
import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './ui/objectManagementDialogBase';
|
||||
|
||||
export function registerObjectManagementCommands(appContext: AppContext) {
|
||||
// Notes: Change the second parameter to false to use the actual object management service.
|
||||
const service = getObjectManagementService(appContext, false);
|
||||
appContext.extensionContext.subscriptions.push(vscode.commands.registerCommand('mssql.newLogin', async (context: azdata.ObjectExplorerContext) => {
|
||||
await handleNewLoginDialogCommand(context, service);
|
||||
}));
|
||||
appContext.extensionContext.subscriptions.push(vscode.commands.registerCommand('mssql.newUser', async (context: azdata.ObjectExplorerContext) => {
|
||||
await handleNewUserDialogCommand(context, service);
|
||||
appContext.extensionContext.subscriptions.push(vscode.commands.registerCommand('mssql.newObject', async (context: azdata.ObjectExplorerContext) => {
|
||||
await handleNewObjectDialogCommand(context, service);
|
||||
}));
|
||||
appContext.extensionContext.subscriptions.push(vscode.commands.registerCommand('mssql.objectProperties', async (context: azdata.ObjectExplorerContext) => {
|
||||
await handleObjectPropertiesDialogCommand(context, service);
|
||||
@@ -45,41 +43,45 @@ function getObjectManagementService(appContext: AppContext, useTestService: bool
|
||||
}
|
||||
}
|
||||
|
||||
async function handleNewLoginDialogCommand(context: azdata.ObjectExplorerContext, service: IObjectManagementService): Promise<void> {
|
||||
async function handleNewObjectDialogCommand(context: azdata.ObjectExplorerContext, service: IObjectManagementService): Promise<void> {
|
||||
const connectionUri = await getConnectionUri(context);
|
||||
if (!connectionUri) {
|
||||
return;
|
||||
}
|
||||
let newObjectType: ObjectManagement.NodeType;
|
||||
switch (context.nodeInfo!.objectType) {
|
||||
case FolderType.ServerLevelLogins:
|
||||
newObjectType = ObjectManagement.NodeType.ServerLevelLogin;
|
||||
break;
|
||||
case FolderType.Users:
|
||||
newObjectType = ObjectManagement.NodeType.User;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported folder type: ${context.nodeInfo!.objectType}`);
|
||||
}
|
||||
|
||||
try {
|
||||
const dialog = new LoginDialog(service, connectionUri, true, undefined, context);
|
||||
const parentUrn = await getParentUrn(context);
|
||||
const options: ObjectManagementDialogOptions = {
|
||||
connectionUri: connectionUri,
|
||||
isNewObject: true,
|
||||
database: context.connectionProfile!.databaseName!,
|
||||
objectType: newObjectType,
|
||||
objectName: '',
|
||||
parentUrn: parentUrn,
|
||||
objectExplorerContext: context
|
||||
};
|
||||
const dialog = getDialog(service, options);
|
||||
await dialog.open();
|
||||
}
|
||||
catch (err) {
|
||||
TelemetryReporter.createErrorEvent2(TelemetryViews.ObjectManagement, TelemetryActions.OpenNewObjectDialog, err).withAdditionalProperties({
|
||||
objectType: NodeType.Login
|
||||
TelemetryReporter.createErrorEvent2(ObjectManagementViewName, TelemetryActions.OpenNewObjectDialog, err).withAdditionalProperties({
|
||||
objectType: context.nodeInfo!.nodeType
|
||||
}).send();
|
||||
await vscode.window.showErrorMessage(localizedConstants.OpenNewObjectDialogError(localizedConstants.LoginTypeDisplayName, getErrorMessage(err)));
|
||||
}
|
||||
}
|
||||
|
||||
async function handleNewUserDialogCommand(context: azdata.ObjectExplorerContext, service: IObjectManagementService): Promise<void> {
|
||||
const connectionUri = await getConnectionUri(context);
|
||||
if (!connectionUri) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const dialog = new UserDialog(service, connectionUri, context.connectionProfile!.databaseName!, true, undefined, context);
|
||||
await dialog.open();
|
||||
}
|
||||
catch (err) {
|
||||
TelemetryReporter.createErrorEvent2(TelemetryViews.ObjectManagement, TelemetryActions.OpenNewObjectDialog, err).withAdditionalProperties({
|
||||
objectType: NodeType.User
|
||||
}).send();
|
||||
await vscode.window.showErrorMessage(localizedConstants.OpenNewObjectDialogError(localizedConstants.UserTypeDisplayName, getErrorMessage(err)));
|
||||
}
|
||||
}
|
||||
|
||||
async function handleObjectPropertiesDialogCommand(context: azdata.ObjectExplorerContext, service: IObjectManagementService): Promise<void> {
|
||||
const connectionUri = await getConnectionUri(context);
|
||||
if (!connectionUri) {
|
||||
@@ -87,23 +89,22 @@ async function handleObjectPropertiesDialogCommand(context: azdata.ObjectExplore
|
||||
}
|
||||
const nodeTypeDisplayName = getNodeTypeDisplayName(context.nodeInfo!.nodeType);
|
||||
try {
|
||||
let dialog;
|
||||
switch (context.nodeInfo!.nodeType) {
|
||||
case NodeType.Login:
|
||||
dialog = new LoginDialog(service, connectionUri, false, context.nodeInfo!.label);
|
||||
break;
|
||||
case NodeType.User:
|
||||
dialog = new UserDialog(service, connectionUri, context.connectionProfile!.databaseName!, false, context.nodeInfo!.label);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (dialog) {
|
||||
await dialog.open();
|
||||
}
|
||||
const parentUrn = await getParentUrn(context);
|
||||
const options: ObjectManagementDialogOptions = {
|
||||
connectionUri: connectionUri,
|
||||
isNewObject: false,
|
||||
database: context.connectionProfile!.databaseName!,
|
||||
objectType: context.nodeInfo.nodeType as ObjectManagement.NodeType,
|
||||
objectName: context.nodeInfo.label,
|
||||
parentUrn: parentUrn,
|
||||
objectUrn: context.nodeInfo!.metadata!.urn,
|
||||
objectExplorerContext: context
|
||||
};
|
||||
const dialog = getDialog(service, options);
|
||||
await dialog.open();
|
||||
}
|
||||
catch (err) {
|
||||
TelemetryReporter.createErrorEvent2(TelemetryViews.ObjectManagement, TelemetryActions.OpenPropertiesDialog, err).withAdditionalProperties({
|
||||
TelemetryReporter.createErrorEvent2(ObjectManagementViewName, TelemetryActions.OpenPropertiesDialog, err).withAdditionalProperties({
|
||||
objectType: context.nodeInfo!.nodeType
|
||||
}).send();
|
||||
await vscode.window.showErrorMessage(localizedConstants.OpenObjectPropertiesDialogError(nodeTypeDisplayName, context.nodeInfo!.label, getErrorMessage(err)));
|
||||
@@ -117,7 +118,7 @@ async function handleDeleteObjectCommand(context: azdata.ObjectExplorerContext,
|
||||
}
|
||||
let additionalConfirmationMessage: string | undefined = undefined;
|
||||
switch (context.nodeInfo!.nodeType) {
|
||||
case NodeType.Login:
|
||||
case ObjectManagement.NodeType.ServerLevelLogin:
|
||||
additionalConfirmationMessage = localizedConstants.DeleteLoginConfirmationText;
|
||||
break;
|
||||
default:
|
||||
@@ -139,7 +140,7 @@ async function handleDeleteObjectCommand(context: azdata.ObjectExplorerContext,
|
||||
operation: async (operation) => {
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
await service.drop(connectionUri, context.nodeInfo!.metadata!.urn);
|
||||
await service.drop(connectionUri, context.nodeInfo.nodeType as ObjectManagement.NodeType, context.nodeInfo!.metadata!.urn);
|
||||
TelemetryReporter.sendTelemetryEvent(TelemetryActions.DeleteObject, {
|
||||
objectType: context.nodeInfo!.nodeType
|
||||
}, {
|
||||
@@ -148,7 +149,7 @@ async function handleDeleteObjectCommand(context: azdata.ObjectExplorerContext,
|
||||
}
|
||||
catch (err) {
|
||||
operation.updateStatus(azdata.TaskStatus.Failed, localizedConstants.DeleteObjectError(nodeTypeDisplayName, context.nodeInfo!.label, getErrorMessage(err)));
|
||||
TelemetryReporter.createErrorEvent2(TelemetryViews.ObjectManagement, TelemetryActions.DeleteObject, err).withAdditionalProperties({
|
||||
TelemetryReporter.createErrorEvent2(ObjectManagementViewName, TelemetryActions.DeleteObject, err).withAdditionalProperties({
|
||||
objectType: context.nodeInfo!.nodeType
|
||||
}).send();
|
||||
return;
|
||||
@@ -191,7 +192,7 @@ async function handleRenameObjectCommand(context: azdata.ObjectExplorerContext,
|
||||
operation: async (operation) => {
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
await service.rename(connectionUri, context.nodeInfo!.metadata!.urn, newName);
|
||||
await service.rename(connectionUri, context.nodeInfo.nodeType as ObjectManagement.NodeType, context.nodeInfo!.metadata!.urn, newName);
|
||||
TelemetryReporter.sendTelemetryEvent(TelemetryActions.RenameObject, {
|
||||
objectType: context.nodeInfo!.nodeType
|
||||
}, {
|
||||
@@ -200,7 +201,7 @@ async function handleRenameObjectCommand(context: azdata.ObjectExplorerContext,
|
||||
}
|
||||
catch (err) {
|
||||
operation.updateStatus(azdata.TaskStatus.Failed, localizedConstants.RenameObjectError(nodeTypeDisplayName, originalName, newName, getErrorMessage(err)));
|
||||
TelemetryReporter.createErrorEvent2(TelemetryViews.ObjectManagement, TelemetryActions.RenameObject, err).withAdditionalProperties({
|
||||
TelemetryReporter.createErrorEvent2(ObjectManagementViewName, TelemetryActions.RenameObject, err).withAdditionalProperties({
|
||||
objectType: context.nodeInfo!.nodeType
|
||||
}).send();
|
||||
return;
|
||||
@@ -211,6 +212,17 @@ async function handleRenameObjectCommand(context: azdata.ObjectExplorerContext,
|
||||
});
|
||||
}
|
||||
|
||||
function getDialog(service: IObjectManagementService, dialogOptions: ObjectManagementDialogOptions): ObjectManagementDialogBase<ObjectManagement.SqlObject, ObjectManagement.ObjectViewInfo<ObjectManagement.SqlObject>> {
|
||||
switch (dialogOptions.objectType) {
|
||||
case ObjectManagement.NodeType.ServerLevelLogin:
|
||||
return new LoginDialog(service, dialogOptions);
|
||||
case ObjectManagement.NodeType.User:
|
||||
return new UserDialog(service, dialogOptions);
|
||||
default:
|
||||
throw new Error(`Unsupported object type: ${dialogOptions.objectType}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function getConnectionUri(context: azdata.ObjectExplorerContext): Promise<string> {
|
||||
const connectionUri = await azdata.connection.getUriForConnection(context.connectionProfile!.id);
|
||||
if (!connectionUri) {
|
||||
@@ -218,3 +230,13 @@ async function getConnectionUri(context: azdata.ObjectExplorerContext): Promise<
|
||||
}
|
||||
return connectionUri;
|
||||
}
|
||||
|
||||
async function getParentUrn(context: azdata.ObjectExplorerContext): Promise<string> {
|
||||
let node = undefined;
|
||||
let currentNodePath = context.nodeInfo!.parentNodePath;
|
||||
do {
|
||||
node = await azdata.objectexplorer.getNode(context.connectionProfile!.id, currentNodePath);
|
||||
currentNodePath = node?.parentNodePath;
|
||||
} while (node && currentNodePath && !node.metadata?.urn);
|
||||
return node?.metadata?.urn;
|
||||
}
|
||||
|
||||
@@ -4,56 +4,21 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* The object types in object explorer's node context.
|
||||
* The folder types in object explorer.
|
||||
*/
|
||||
export enum NodeType {
|
||||
Column = 'Column',
|
||||
Database = 'Database',
|
||||
Login = 'ServerLevelLogin',
|
||||
Table = 'Table',
|
||||
User = 'User',
|
||||
View = 'View'
|
||||
export const enum FolderType {
|
||||
ServerLevelLogins = 'ServerLevelLogins',
|
||||
Users = 'Users'
|
||||
}
|
||||
|
||||
export const PublicServerRoleName = 'public';
|
||||
|
||||
/**
|
||||
* User types.
|
||||
*/
|
||||
export enum UserType {
|
||||
/**
|
||||
* User with a server level login.
|
||||
*/
|
||||
WithLogin = 'WithLogin',
|
||||
/**
|
||||
* User based on a Windows user/group that has no login, but can connect to the Database Engine through membership in a Windows group.
|
||||
*/
|
||||
WithWindowsGroupLogin = 'WithWindowsGroupLogin',
|
||||
/**
|
||||
* Contained user, authentication is done within the database.
|
||||
*/
|
||||
Contained = 'Contained',
|
||||
/**
|
||||
* User that cannot authenticate.
|
||||
*/
|
||||
NoConnectAccess = 'NoConnectAccess'
|
||||
}
|
||||
|
||||
/**
|
||||
* The authentication types.
|
||||
*/
|
||||
export enum AuthenticationType {
|
||||
Windows = 'Windows',
|
||||
Sql = 'Sql',
|
||||
AzureActiveDirectory = 'AAD'
|
||||
}
|
||||
|
||||
export const CreateUserDocUrl = 'https://learn.microsoft.com/en-us/sql/t-sql/statements/create-user-transact-sql';
|
||||
export const AlterUserDocUrl = 'https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-user-transact-sql';
|
||||
export const CreateLoginDocUrl = 'https://learn.microsoft.com/en-us/sql/t-sql/statements/create-login-transact-sql';
|
||||
export const AlterLoginDocUrl = 'https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-login-transact-sql';
|
||||
|
||||
export enum TelemetryActions {
|
||||
export const enum TelemetryActions {
|
||||
CreateObject = 'CreateObject',
|
||||
DeleteObject = 'DeleteObject',
|
||||
OpenNewObjectDialog = 'OpenNewObjectDialog',
|
||||
@@ -62,6 +27,4 @@ export enum TelemetryActions {
|
||||
UpdateObject = 'UpdateObject'
|
||||
}
|
||||
|
||||
export enum TelemetryViews {
|
||||
ObjectManagement = 'ObjectManagement'
|
||||
}
|
||||
export const ObjectManagementViewName = 'ObjectManagement';
|
||||
|
||||
@@ -24,6 +24,7 @@ export const LoadingDialogText: string = localize('objectManagement.loadingDialo
|
||||
export const FailedToRetrieveConnectionInfoErrorMessage: string = localize('objectManagement.noConnectionUriError', "Failed to retrieve the connection information, please reconnect and try again.")
|
||||
export const RenameObjectDialogTitle: string = localize('objectManagement.renameObjectDialogTitle', "Enter new name");
|
||||
export const ScriptText: string = localize('objectManagement.scriptText', "Script");
|
||||
export const NoActionScriptedMessage: string = localize('objectManagement.noActionScriptedMessage', "There is no action to be scripted.");
|
||||
export const ScriptGeneratedText: string = localize('objectManagement.scriptGenerated', "Script has been generated successfully. You can close the dialog to view it in the newly opened editor.")
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import { BaseService, ISqlOpsFeature, SqlOpsDataClient } from 'dataprotocol-clie
|
||||
import { ObjectManagement, IObjectManagementService } from 'mssql';
|
||||
import { ClientCapabilities } from 'vscode-languageclient';
|
||||
import { AppContext } from '../appContext';
|
||||
import { AuthenticationType, UserType } from './constants';
|
||||
|
||||
export class ObjectManagementService extends BaseService implements IObjectManagementService {
|
||||
public static asFeature(context: AppContext): ISqlOpsFeature {
|
||||
@@ -29,235 +28,190 @@ export class ObjectManagementService extends BaseService implements IObjectManag
|
||||
};
|
||||
}
|
||||
|
||||
async initializeView(contextId: string, objectType: ObjectManagement.NodeType, connectionUri: string, database: string, isNewObject: boolean, parentUrn: string, objectUrn: string): Promise<ObjectManagement.ObjectViewInfo<ObjectManagement.SqlObject>> {
|
||||
const params: contracts.InitializeViewRequestParams = { connectionUri, contextId, isNewObject, objectType, database, parentUrn, objectUrn };
|
||||
return this.runWithErrorHandling(contracts.InitializeViewRequest.type, params);
|
||||
}
|
||||
|
||||
private constructor(context: AppContext, client: SqlOpsDataClient) {
|
||||
super(client);
|
||||
context.registerService(constants.ObjectManagementService, this);
|
||||
}
|
||||
|
||||
async initializeLoginView(connectionUri: string, contextId: string, isNewObject: boolean, name: string | undefined): Promise<ObjectManagement.LoginViewInfo> {
|
||||
const params: contracts.InitializeLoginViewRequestParams = { connectionUri, contextId, isNewObject, name };
|
||||
return this.runWithErrorHandling(contracts.InitializeLoginViewRequest.type, params);
|
||||
async save(contextId: string, object: ObjectManagement.SqlObject): Promise<void> {
|
||||
const params: contracts.SaveObjectRequestParams = { contextId, object };
|
||||
return this.runWithErrorHandling(contracts.SaveObjectRequest.type, params);
|
||||
}
|
||||
|
||||
async createLogin(contextId: string, login: ObjectManagement.Login): Promise<void> {
|
||||
const params: contracts.CreateLoginRequestParams = { contextId, login };
|
||||
return this.runWithErrorHandling(contracts.CreateLoginRequest.type, params);
|
||||
async script(contextId: string, object: ObjectManagement.SqlObject): Promise<string> {
|
||||
const params: contracts.ScriptObjectRequestParams = { contextId, object };
|
||||
return this.runWithErrorHandling(contracts.ScriptObjectRequest.type, params);
|
||||
}
|
||||
|
||||
async updateLogin(contextId: string, login: ObjectManagement.Login): Promise<void> {
|
||||
const params: contracts.UpdateLoginRequestParams = { contextId, login };
|
||||
return this.runWithErrorHandling(contracts.UpdateLoginRequest.type, params);
|
||||
async disposeView(contextId: string): Promise<void> {
|
||||
const params: contracts.DisposeViewRequestParams = { contextId };
|
||||
return this.runWithErrorHandling(contracts.DisposeViewRequest.type, params);
|
||||
}
|
||||
|
||||
async scriptLogin(contextId: string, login: ObjectManagement.Login): Promise<string> {
|
||||
const params: contracts.ScriptLoginRequestParams = { contextId, login };
|
||||
return this.runWithErrorHandling(contracts.ScriptLoginRequest.type, params);
|
||||
}
|
||||
|
||||
async disposeLoginView(contextId: string): Promise<void> {
|
||||
const params: contracts.DisposeLoginViewRequestParams = { contextId };
|
||||
return this.runWithErrorHandling(contracts.DisposeLoginViewRequest.type, params);
|
||||
}
|
||||
|
||||
async initializeUserView(connectionUri: string, database: string, contextId: string, isNewObject: boolean, name: string | undefined): Promise<ObjectManagement.UserViewInfo> {
|
||||
const params: contracts.InitializeUserViewRequestParams = { connectionUri, database, contextId, isNewObject, name };
|
||||
return this.runWithErrorHandling(contracts.InitializeUserViewRequest.type, params);
|
||||
}
|
||||
|
||||
async createUser(contextId: string, user: ObjectManagement.User): Promise<void> {
|
||||
const params: contracts.CreateUserRequestParams = { contextId, user };
|
||||
return this.runWithErrorHandling(contracts.CreateUserRequest.type, params);
|
||||
}
|
||||
|
||||
async updateUser(contextId: string, user: ObjectManagement.User): Promise<void> {
|
||||
const params: contracts.UpdateUserRequestParams = { contextId, user };
|
||||
return this.runWithErrorHandling(contracts.UpdateUserRequest.type, params);
|
||||
}
|
||||
|
||||
async scriptUser(contextId: string, user: ObjectManagement.User): Promise<string> {
|
||||
const params: contracts.ScriptUserRequestParams = { contextId, user };
|
||||
return this.runWithErrorHandling(contracts.ScriptUserRequest.type, params);
|
||||
}
|
||||
|
||||
async disposeUserView(contextId: string): Promise<void> {
|
||||
const params: contracts.DisposeUserViewRequestParams = { contextId };
|
||||
return this.runWithErrorHandling(contracts.DisposeUserViewRequest.type, params);
|
||||
}
|
||||
|
||||
async rename(connectionUri: string, objectUrn: string, newName: string): Promise<void> {
|
||||
const params: contracts.RenameObjectRequestParams = { connectionUri, objectUrn, newName };
|
||||
async rename(connectionUri: string, objectType: ObjectManagement.NodeType, objectUrn: string, newName: string): Promise<void> {
|
||||
const params: contracts.RenameObjectRequestParams = { connectionUri, objectUrn, newName, objectType };
|
||||
return this.runWithErrorHandling(contracts.RenameObjectRequest.type, params);
|
||||
}
|
||||
async drop(connectionUri: string, objectUrn: string): Promise<void> {
|
||||
const params: contracts.DropObjectRequestParams = { connectionUri, objectUrn };
|
||||
async drop(connectionUri: string, objectType: ObjectManagement.NodeType, objectUrn: string): Promise<void> {
|
||||
const params: contracts.DropObjectRequestParams = { connectionUri, objectUrn, objectType };
|
||||
return this.runWithErrorHandling(contracts.DropObjectRequest.type, params);
|
||||
}
|
||||
}
|
||||
|
||||
export class TestObjectManagementService implements IObjectManagementService {
|
||||
initializeLoginView(connectionUri: string, contextId: string, isNewObject: boolean, name: string | undefined): Promise<ObjectManagement.LoginViewInfo> {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
const serverRoles = ['sysadmin', 'public', 'bulkadmin', 'dbcreator', 'diskadmin', 'processadmin', 'securityadmin', 'serveradmin'];
|
||||
const languages = ['<default>', 'English'];
|
||||
const databases = ['master', 'db1', 'db2'];
|
||||
let login: ObjectManagement.LoginViewInfo;
|
||||
if (isNewObject) {
|
||||
login = <ObjectManagement.LoginViewInfo>{
|
||||
objectInfo: {
|
||||
name: '',
|
||||
authenticationType: AuthenticationType.Sql,
|
||||
enforcePasswordPolicy: true,
|
||||
enforcePasswordExpiration: true,
|
||||
mustChangePassword: true,
|
||||
defaultDatabase: 'master',
|
||||
defaultLanguage: '<default>',
|
||||
serverRoles: ['public', 'bulkadmin'],
|
||||
connectPermission: true,
|
||||
isEnabled: true,
|
||||
isLockedOut: false
|
||||
},
|
||||
supportAADAuthentication: true,
|
||||
supportSQLAuthentication: true,
|
||||
supportWindowsAuthentication: true,
|
||||
supportAdvancedOptions: true,
|
||||
supportAdvancedPasswordOptions: true,
|
||||
canEditLockedOutState: false,
|
||||
languages: languages,
|
||||
databases: databases,
|
||||
serverRoles: serverRoles
|
||||
};
|
||||
} else {
|
||||
login = <ObjectManagement.LoginViewInfo>{
|
||||
objectInfo: {
|
||||
name: name,
|
||||
authenticationType: AuthenticationType.Sql,
|
||||
enforcePasswordPolicy: true,
|
||||
enforcePasswordExpiration: true,
|
||||
mustChangePassword: true,
|
||||
defaultDatabase: 'master',
|
||||
defaultLanguage: '<default>',
|
||||
serverRoles: ['public'],
|
||||
connectPermission: true,
|
||||
isEnabled: true,
|
||||
isLockedOut: false,
|
||||
password: '******************'
|
||||
},
|
||||
supportAADAuthentication: true,
|
||||
supportSQLAuthentication: true,
|
||||
supportWindowsAuthentication: true,
|
||||
supportAdvancedOptions: true,
|
||||
supportAdvancedPasswordOptions: true,
|
||||
canEditLockedOutState: false,
|
||||
languages: languages,
|
||||
databases: databases,
|
||||
serverRoles: serverRoles
|
||||
};
|
||||
}
|
||||
resolve(login);
|
||||
}, 3000);
|
||||
});
|
||||
initializeView(contextId: string, objectType: ObjectManagement.NodeType, connectionUri: string, database: string, isNewObject: boolean, parentUrn: string, objectUrn: string): Thenable<ObjectManagement.ObjectViewInfo<ObjectManagement.SqlObject>> {
|
||||
if (objectType === ObjectManagement.NodeType.ServerLevelLogin) {
|
||||
return Promise.resolve(this.getLoginView(isNewObject, objectUrn));
|
||||
} else if (objectType === ObjectManagement.NodeType.User) {
|
||||
return Promise.resolve(this.getUserView(isNewObject, objectUrn));
|
||||
}
|
||||
else {
|
||||
throw Error('Not implemented');
|
||||
}
|
||||
}
|
||||
async createLogin(contextId: string, login: ObjectManagement.Login): Promise<void> {
|
||||
save(contextId: string, object: ObjectManagement.SqlObject): Thenable<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
async updateLogin(contextId: string, login: ObjectManagement.Login): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
async scriptLogin(contextId: string, login: ObjectManagement.Login): Promise<string> {
|
||||
script(contextId: string, object: ObjectManagement.SqlObject): Thenable<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve('test script');
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
async disposeLoginView(contextId: string): Promise<void> {
|
||||
}
|
||||
async initializeUserView(connectionUri: string, database: string, contextId: string, isNewObject: boolean, name: string): Promise<ObjectManagement.UserViewInfo> {
|
||||
disposeView(contextId: string): Thenable<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
let viewInfo: ObjectManagement.UserViewInfo;
|
||||
const languages = ['<default>', 'English'];
|
||||
const schemas = ['dbo', 'sys', 'alanren'];
|
||||
const logins = ['sa', 'alanren', 'alanren@microsoft.com'];
|
||||
const databaseRoles = ['dbmanager', 'loginmanager', 'bulkadmin', 'sysadmin', 'tablemanager', 'viewmanager'];
|
||||
resolve();
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
async rename(connectionUri: string, objectType: ObjectManagement.NodeType, objectUrn: string, newName: string): Promise<void> {
|
||||
return this.delayAndResolve();
|
||||
}
|
||||
async drop(connectionUri: string, objectType: ObjectManagement.NodeType, objectUrn: string): Promise<void> {
|
||||
return this.delayAndResolve();
|
||||
}
|
||||
private getLoginView(isNewObject: boolean, name: string): ObjectManagement.LoginViewInfo {
|
||||
const serverRoles = ['sysadmin', 'public', 'bulkadmin', 'dbcreator', 'diskadmin', 'processadmin', 'securityadmin', 'serveradmin'];
|
||||
const languages = ['<default>', 'English'];
|
||||
const databases = ['master', 'db1', 'db2'];
|
||||
let login: ObjectManagement.LoginViewInfo;
|
||||
if (isNewObject) {
|
||||
login = <ObjectManagement.LoginViewInfo>{
|
||||
objectInfo: {
|
||||
name: '',
|
||||
authenticationType: ObjectManagement.AuthenticationType.Sql,
|
||||
enforcePasswordPolicy: true,
|
||||
enforcePasswordExpiration: true,
|
||||
mustChangePassword: true,
|
||||
defaultDatabase: 'master',
|
||||
defaultLanguage: '<default>',
|
||||
serverRoles: ['public', 'bulkadmin'],
|
||||
connectPermission: true,
|
||||
isEnabled: true,
|
||||
isLockedOut: false
|
||||
},
|
||||
supportAADAuthentication: true,
|
||||
supportSQLAuthentication: true,
|
||||
supportWindowsAuthentication: true,
|
||||
supportAdvancedOptions: true,
|
||||
supportAdvancedPasswordOptions: true,
|
||||
canEditLockedOutState: false,
|
||||
languages: languages,
|
||||
databases: databases,
|
||||
serverRoles: serverRoles
|
||||
};
|
||||
} else {
|
||||
login = <ObjectManagement.LoginViewInfo>{
|
||||
objectInfo: {
|
||||
name: name,
|
||||
authenticationType: ObjectManagement.AuthenticationType.Sql,
|
||||
enforcePasswordPolicy: true,
|
||||
enforcePasswordExpiration: true,
|
||||
mustChangePassword: true,
|
||||
defaultDatabase: 'master',
|
||||
defaultLanguage: '<default>',
|
||||
serverRoles: ['public'],
|
||||
connectPermission: true,
|
||||
isEnabled: true,
|
||||
isLockedOut: false,
|
||||
password: '******************'
|
||||
},
|
||||
supportAADAuthentication: true,
|
||||
supportSQLAuthentication: true,
|
||||
supportWindowsAuthentication: true,
|
||||
supportAdvancedOptions: true,
|
||||
supportAdvancedPasswordOptions: true,
|
||||
canEditLockedOutState: false,
|
||||
languages: languages,
|
||||
databases: databases,
|
||||
serverRoles: serverRoles
|
||||
};
|
||||
}
|
||||
return login;
|
||||
}
|
||||
private getUserView(isNewObject: boolean, name: string): ObjectManagement.UserViewInfo {
|
||||
let viewInfo: ObjectManagement.UserViewInfo;
|
||||
const languages = ['<default>', 'English'];
|
||||
const schemas = ['dbo', 'sys', 'alanren'];
|
||||
const logins = ['sa', 'alanren', 'alanren@microsoft.com'];
|
||||
const databaseRoles = ['dbmanager', 'loginmanager', 'bulkadmin', 'sysadmin', 'tablemanager', 'viewmanager'];
|
||||
|
||||
if (isNewObject) {
|
||||
viewInfo = {
|
||||
objectInfo: <ObjectManagement.User>{
|
||||
name: '',
|
||||
type: UserType.WithLogin,
|
||||
defaultSchema: 'dbo',
|
||||
defaultLanguage: '<default>',
|
||||
authenticationType: AuthenticationType.Sql,
|
||||
loginName: 'sa',
|
||||
ownedSchemas: [],
|
||||
databaseRoles: [],
|
||||
password: ''
|
||||
},
|
||||
languages: languages,
|
||||
schemas: schemas,
|
||||
logins: logins,
|
||||
databaseRoles: databaseRoles,
|
||||
supportContainedUser: true,
|
||||
supportAADAuthentication: true,
|
||||
supportSQLAuthentication: true,
|
||||
supportWindowsAuthentication: true
|
||||
};
|
||||
} else {
|
||||
viewInfo = {
|
||||
objectInfo: <ObjectManagement.User>{
|
||||
name: name,
|
||||
type: UserType.WithLogin,
|
||||
defaultSchema: 'dbo',
|
||||
defaultLanguage: '<default>',
|
||||
loginName: 'sa',
|
||||
authenticationType: AuthenticationType.Sql,
|
||||
ownedSchemas: ['dbo'],
|
||||
databaseRoles: ['dbmanager', 'bulkadmin']
|
||||
},
|
||||
languages: languages,
|
||||
schemas: schemas,
|
||||
logins: logins,
|
||||
databaseRoles: databaseRoles,
|
||||
supportContainedUser: true,
|
||||
supportAADAuthentication: true,
|
||||
supportSQLAuthentication: true,
|
||||
supportWindowsAuthentication: true
|
||||
};
|
||||
}
|
||||
resolve(viewInfo);
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
async createUser(contextId: string, user: ObjectManagement.User): Promise<void> {
|
||||
return this.delayAndResolve();
|
||||
}
|
||||
async updateUser(contextId: string, login: ObjectManagement.User): Promise<void> {
|
||||
return this.delayAndResolve();
|
||||
}
|
||||
async scriptUser(contextId: string, login: ObjectManagement.User): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
reject('generate script for user not supported');
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
async disposeUserView(contextId: string): Promise<void> {
|
||||
}
|
||||
async rename(connectionUri: string, objectUrn: string, newName: string): Promise<void> {
|
||||
return this.delayAndResolve();
|
||||
}
|
||||
async drop(connectionUri: string, objectUrn: string): Promise<void> {
|
||||
return this.delayAndResolve();
|
||||
if (isNewObject) {
|
||||
viewInfo = {
|
||||
objectInfo: <ObjectManagement.User>{
|
||||
name: '',
|
||||
type: ObjectManagement.UserType.WithLogin,
|
||||
defaultSchema: 'dbo',
|
||||
defaultLanguage: '<default>',
|
||||
authenticationType: ObjectManagement.AuthenticationType.Sql,
|
||||
loginName: 'sa',
|
||||
ownedSchemas: [],
|
||||
databaseRoles: [],
|
||||
password: ''
|
||||
},
|
||||
languages: languages,
|
||||
schemas: schemas,
|
||||
logins: logins,
|
||||
databaseRoles: databaseRoles,
|
||||
supportContainedUser: true,
|
||||
supportAADAuthentication: true,
|
||||
supportSQLAuthentication: true,
|
||||
supportWindowsAuthentication: true
|
||||
};
|
||||
} else {
|
||||
viewInfo = {
|
||||
objectInfo: <ObjectManagement.User>{
|
||||
name: name,
|
||||
type: ObjectManagement.UserType.WithLogin,
|
||||
defaultSchema: 'dbo',
|
||||
defaultLanguage: '<default>',
|
||||
loginName: 'sa',
|
||||
authenticationType: ObjectManagement.AuthenticationType.Sql,
|
||||
ownedSchemas: ['dbo'],
|
||||
databaseRoles: ['dbmanager', 'bulkadmin']
|
||||
},
|
||||
languages: languages,
|
||||
schemas: schemas,
|
||||
logins: logins,
|
||||
databaseRoles: databaseRoles,
|
||||
supportContainedUser: true,
|
||||
supportAADAuthentication: true,
|
||||
supportSQLAuthentication: true,
|
||||
supportWindowsAuthentication: true
|
||||
};
|
||||
}
|
||||
return viewInfo;
|
||||
}
|
||||
private delayAndResolve(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import { getErrorMessage } from '../utils';
|
||||
import { AuthenticationType, NodeType, UserType } from './constants';
|
||||
import { ObjectManagement } from 'mssql';
|
||||
import { AADAuthenticationTypeDisplayText, ColumnTypeDisplayName, ContainedUserText, DatabaseTypeDisplayName, LoginTypeDisplayName, LoginTypeDisplayNameInTitle, RefreshObjectExplorerError, SQLAuthenticationTypeDisplayText, TableTypeDisplayName, UserTypeDisplayName, UserTypeDisplayNameInTitle, UserWithLoginText, UserWithNoConnectAccess, UserWithWindowsGroupLoginText, ViewTypeDisplayName, WindowsAuthenticationTypeDisplayText } from './localizedConstants';
|
||||
|
||||
export function deepClone<T>(obj: T): T {
|
||||
@@ -55,70 +55,70 @@ export async function refreshNode(context: azdata.ObjectExplorerContext): Promis
|
||||
|
||||
export function getNodeTypeDisplayName(type: string, inTitle: boolean = false): string {
|
||||
switch (type) {
|
||||
case NodeType.Login:
|
||||
case ObjectManagement.NodeType.ServerLevelLogin:
|
||||
return inTitle ? LoginTypeDisplayNameInTitle : LoginTypeDisplayName;
|
||||
case NodeType.User:
|
||||
case ObjectManagement.NodeType.User:
|
||||
return inTitle ? UserTypeDisplayNameInTitle : UserTypeDisplayName;
|
||||
case NodeType.Table:
|
||||
case ObjectManagement.NodeType.Table:
|
||||
return TableTypeDisplayName;
|
||||
case NodeType.View:
|
||||
case ObjectManagement.NodeType.View:
|
||||
return ViewTypeDisplayName;
|
||||
case NodeType.Column:
|
||||
case ObjectManagement.NodeType.Column:
|
||||
return ColumnTypeDisplayName;
|
||||
case NodeType.Database:
|
||||
case ObjectManagement.NodeType.Database:
|
||||
return DatabaseTypeDisplayName;
|
||||
default:
|
||||
throw new Error(`Unkown node type: ${type}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function getAuthenticationTypeDisplayName(authType: AuthenticationType | undefined): string | undefined {
|
||||
export function getAuthenticationTypeDisplayName(authType: ObjectManagement.AuthenticationType | undefined): string | undefined {
|
||||
if (authType === undefined) { return undefined; }
|
||||
|
||||
switch (authType) {
|
||||
case AuthenticationType.Windows:
|
||||
case ObjectManagement.AuthenticationType.Windows:
|
||||
return WindowsAuthenticationTypeDisplayText;
|
||||
case AuthenticationType.AzureActiveDirectory:
|
||||
case ObjectManagement.AuthenticationType.AzureActiveDirectory:
|
||||
return AADAuthenticationTypeDisplayText;
|
||||
default:
|
||||
return SQLAuthenticationTypeDisplayText;
|
||||
}
|
||||
}
|
||||
|
||||
export function getAuthenticationTypeByDisplayName(displayValue: string): AuthenticationType {
|
||||
export function getAuthenticationTypeByDisplayName(displayValue: string): ObjectManagement.AuthenticationType {
|
||||
switch (displayValue) {
|
||||
case WindowsAuthenticationTypeDisplayText:
|
||||
return AuthenticationType.Windows;
|
||||
return ObjectManagement.AuthenticationType.Windows;
|
||||
case AADAuthenticationTypeDisplayText:
|
||||
return AuthenticationType.AzureActiveDirectory;
|
||||
return ObjectManagement.AuthenticationType.AzureActiveDirectory;
|
||||
default:
|
||||
return AuthenticationType.Sql;
|
||||
return ObjectManagement.AuthenticationType.Sql;
|
||||
}
|
||||
}
|
||||
|
||||
export function getUserTypeDisplayName(userType: UserType): string {
|
||||
export function getUserTypeDisplayName(userType: ObjectManagement.UserType): string {
|
||||
switch (userType) {
|
||||
case UserType.WithLogin:
|
||||
case ObjectManagement.UserType.WithLogin:
|
||||
return UserWithLoginText;
|
||||
case UserType.WithWindowsGroupLogin:
|
||||
case ObjectManagement.UserType.WithWindowsGroupLogin:
|
||||
return UserWithWindowsGroupLoginText;
|
||||
case UserType.Contained:
|
||||
case ObjectManagement.UserType.Contained:
|
||||
return ContainedUserText;
|
||||
default:
|
||||
return UserWithNoConnectAccess;
|
||||
}
|
||||
}
|
||||
|
||||
export function getUserTypeByDisplayName(userTypeDisplayName: string): UserType {
|
||||
export function getUserTypeByDisplayName(userTypeDisplayName: string): ObjectManagement.UserType {
|
||||
switch (userTypeDisplayName) {
|
||||
case UserWithLoginText:
|
||||
return UserType.WithLogin;
|
||||
return ObjectManagement.UserType.WithLogin;
|
||||
case UserWithWindowsGroupLoginText:
|
||||
return UserType.WithWindowsGroupLogin;
|
||||
return ObjectManagement.UserType.WithWindowsGroupLogin;
|
||||
case ContainedUserText:
|
||||
return UserType.Contained;
|
||||
return ObjectManagement.UserType.Contained;
|
||||
default:
|
||||
return UserType.NoConnectAccess;
|
||||
return ObjectManagement.UserType.NoConnectAccess;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,8 @@ export class TreeNode {
|
||||
label: this.label,
|
||||
isLeaf: this.isAlwaysLeaf,
|
||||
metadata: this.metadata,
|
||||
errorMessage: this.errorStateMessage
|
||||
errorMessage: this.errorStateMessage,
|
||||
objectType: this.objectType
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user