mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Support multiple objects selected in user manager > add object.
This commit is contained in:
@ -34,13 +34,13 @@ type
|
|||||||
private
|
private
|
||||||
{ Private declarations }
|
{ Private declarations }
|
||||||
FConnection: TDBConnection;
|
FConnection: TDBConnection;
|
||||||
function GetSelectedObject: TDBObject;
|
function GetSelectedObjects: TDBObjectList;
|
||||||
public
|
public
|
||||||
{ Public declarations }
|
{ Public declarations }
|
||||||
property SelectedObject: TDBObject read GetSelectedObject;
|
property SelectedObjects: TDBObjectList read GetSelectedObjects;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SelectDBO: TDBObject;
|
function SelectDBObjects: TDBObjectList;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -48,14 +48,14 @@ uses main, helpers;
|
|||||||
|
|
||||||
{$R *.dfm}
|
{$R *.dfm}
|
||||||
|
|
||||||
function SelectDBO: TDBObject;
|
function SelectDBObjects: TDBObjectList;
|
||||||
var
|
var
|
||||||
Dialog: TfrmSelectDBObject;
|
Dialog: TfrmSelectDBObject;
|
||||||
begin
|
begin
|
||||||
Dialog := TfrmSelectDBObject.Create(Mainform);
|
Dialog := TfrmSelectDBObject.Create(Mainform);
|
||||||
Result := nil;
|
Result := nil;
|
||||||
if Dialog.ShowModal = mrOK then
|
if Dialog.ShowModal = mrOK then
|
||||||
Result := Dialog.SelectedObject;
|
Result := Dialog.SelectedObjects;
|
||||||
Dialog.Free;
|
Dialog.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -67,6 +67,7 @@ begin
|
|||||||
Height := AppSettings.ReadInt(asSelectDBOWindowHeight);
|
Height := AppSettings.ReadInt(asSelectDBOWindowHeight);
|
||||||
InheritFont(Font);
|
InheritFont(Font);
|
||||||
TreeDBO.TreeOptions := MainForm.DBtree.TreeOptions;
|
TreeDBO.TreeOptions := MainForm.DBtree.TreeOptions;
|
||||||
|
TreeDBO.TreeOptions.SelectionOptions := TreeDBO.TreeOptions.SelectionOptions + [toMultiSelect];
|
||||||
FixVT(TreeDBO);
|
FixVT(TreeDBO);
|
||||||
FConnection := MainForm.ActiveConnection;
|
FConnection := MainForm.ActiveConnection;
|
||||||
end;
|
end;
|
||||||
@ -101,29 +102,37 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TfrmSelectDBObject.GetSelectedObject: TDBObject;
|
function TfrmSelectDBObject.GetSelectedObjects: TDBObjectList;
|
||||||
var
|
var
|
||||||
|
Obj: TDBObject;
|
||||||
DBObj: PDBObject;
|
DBObj: PDBObject;
|
||||||
|
Node: PVirtualNode;
|
||||||
begin
|
begin
|
||||||
// Return currently selected object, either from tree node or from edit boxes
|
// Return currently selected object, either from tree node or from edit boxes
|
||||||
Result := nil;
|
Result := TDBObjectList.Create;
|
||||||
if editDb.Modified then begin
|
if editDb.Modified then begin
|
||||||
Result := TDBObject.Create(FConnection);
|
Obj := TDBObject.Create(FConnection);
|
||||||
Result.Database := editDb.Text;
|
Obj.Database := editDb.Text;
|
||||||
Result.NodeType := lntDb;
|
Obj.NodeType := lntDb;
|
||||||
end else if Assigned(TreeDBO.FocusedNode) then begin
|
Result.Add(Obj);
|
||||||
DBObj := TreeDBO.GetNodeData(TreeDBO.FocusedNode);
|
end else if TreeDBO.SelectedCount > 0 then begin
|
||||||
Result := TDBObject.Create(DBObj.Connection);
|
Node := GetNextNode(TreeDBO, nil, True);
|
||||||
Result.Assign(DBObj^);
|
while Assigned(Node) do begin
|
||||||
// Database privileges can be wildcarded. Tables/columns not so.
|
DBObj := TreeDBO.GetNodeData(Node);
|
||||||
if Result.NodeType = lntDb then
|
Obj := TDBObject.Create(DBObj.Connection);
|
||||||
Result.Database := esc(Result.Database, True, False);
|
Obj.Assign(DBObj^);
|
||||||
if Result.NodeType = lntNone then begin
|
// Database privileges can be wildcarded. Tables/columns not so.
|
||||||
Result.NodeType := lntDb;
|
if Obj.NodeType = lntDb then
|
||||||
Result.Database := '%';
|
Obj.Database := esc(Obj.Database, True, False);
|
||||||
|
if Obj.NodeType = lntNone then begin
|
||||||
|
Obj.NodeType := lntDb;
|
||||||
|
Obj.Database := '%';
|
||||||
|
end;
|
||||||
|
Result.Add(Obj);
|
||||||
|
Node := GetNextNode(TreeDBO, Node, True);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
// Let the result be nil to indicate we have no selected node
|
// Let the result be empty to indicate we have no selected node
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TfrmSelectDBObject.TreeDBOFocusChanged(Sender: TBaseVirtualTree;
|
procedure TfrmSelectDBObject.TreeDBOFocusChanged(Sender: TBaseVirtualTree;
|
||||||
|
@ -1073,51 +1073,59 @@ end;
|
|||||||
|
|
||||||
procedure TUserManagerForm.btnAddObjectClick(Sender: TObject);
|
procedure TUserManagerForm.btnAddObjectClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
DBObj: TDBObject;
|
DBObjects: TDBObjectList;
|
||||||
|
DBObject: TDBObject;
|
||||||
Priv: TPrivObj;
|
Priv: TPrivObj;
|
||||||
Node, Child: PVirtualNode;
|
Node, Child: PVirtualNode;
|
||||||
|
ObjectExists: Boolean;
|
||||||
begin
|
begin
|
||||||
// Add new privilege object
|
// Add new privilege object(s)
|
||||||
DBObj := SelectDBO;
|
DBObjects := SelectDBObjects;
|
||||||
if not Assigned(DBObj) then
|
if (not Assigned(DBObjects)) or (DBObjects.Count = 0) then
|
||||||
Exit;
|
Exit;
|
||||||
// Check for unsupported object type, selectable in tree
|
for DBObject in DBObjects do begin
|
||||||
if not (DBObj.NodeType in [lntDb, lntTable, lntView, lntFunction, lntProcedure, lntColumn]) then begin
|
|
||||||
ErrorDialog(f_('Objects of type %s cannot be part of privileges.', [_(DBObj.ObjType)]));
|
|
||||||
Exit;
|
|
||||||
end;
|
|
||||||
// Check if this would be a duplicate object
|
|
||||||
for Priv in FPrivObjects do begin
|
|
||||||
if Priv.DBObj.IsSameAs(DBObj) then begin
|
|
||||||
ErrorDialog(_('Selected object is already accessible.'));
|
|
||||||
Exit;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
Priv := TPrivObj.Create;
|
// Check for unsupported object type, selectable in tree
|
||||||
Priv.DBObj := DBObj;
|
if not (DBObject.NodeType in [lntDb, lntTable, lntView, lntFunction, lntProcedure, lntColumn]) then begin
|
||||||
case Priv.DBObj.NodeType of
|
ErrorDialog(f_('Objects of type %s cannot be part of privileges.', [_(DBObject.ObjType)]));
|
||||||
lntNone: Priv.AllPrivileges := PrivsGlobal;
|
Continue;
|
||||||
lntDb: Priv.AllPrivileges := PrivsDb;
|
end;
|
||||||
lntTable, lntView: Priv.AllPrivileges := PrivsTable;
|
// Check if this would be a duplicate object
|
||||||
lntFunction, lntProcedure: Priv.AllPrivileges := PrivsRoutine;
|
ObjectExists := False;
|
||||||
lntColumn: Priv.AllPrivileges := PrivsColumn;
|
for Priv in FPrivObjects do begin
|
||||||
|
if Priv.DBObj.IsSameAs(DBObject) then
|
||||||
|
ObjectExists := True;
|
||||||
|
end;
|
||||||
|
if ObjectExists then begin
|
||||||
|
ErrorDialog(_('Selected object is already accessible.'));
|
||||||
|
Continue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Priv := TPrivObj.Create;
|
||||||
|
Priv.DBObj := DBObject;
|
||||||
|
case Priv.DBObj.NodeType of
|
||||||
|
lntNone: Priv.AllPrivileges := PrivsGlobal;
|
||||||
|
lntDb: Priv.AllPrivileges := PrivsDb;
|
||||||
|
lntTable, lntView: Priv.AllPrivileges := PrivsTable;
|
||||||
|
lntFunction, lntProcedure: Priv.AllPrivileges := PrivsRoutine;
|
||||||
|
lntColumn: Priv.AllPrivileges := PrivsColumn;
|
||||||
|
end;
|
||||||
|
// Assign minimum privileges
|
||||||
|
case Priv.DBObj.NodeType of
|
||||||
|
lntFunction, lntProcedure: Priv.AddedPrivs.Add('EXECUTE');
|
||||||
|
else Priv.AddedPrivs.Add('SELECT');
|
||||||
|
end;
|
||||||
|
Priv.Added := True;
|
||||||
|
FPrivObjects.Add(Priv);
|
||||||
|
Node := treePrivs.AddChild(nil);
|
||||||
|
Child := treePrivs.GetFirstChild(Node);
|
||||||
|
while Assigned(Child) do
|
||||||
|
Child := treePrivs.GetNextSibling(Child);
|
||||||
|
treePrivs.Expanded[Node] := True;
|
||||||
|
treePrivs.SetFocus;
|
||||||
|
SelectNode(treePrivs, Node);
|
||||||
|
Modified := True;
|
||||||
end;
|
end;
|
||||||
// Assign minimum privileges
|
|
||||||
case Priv.DBObj.NodeType of
|
|
||||||
lntFunction, lntProcedure: Priv.AddedPrivs.Add('EXECUTE');
|
|
||||||
else Priv.AddedPrivs.Add('SELECT');
|
|
||||||
end;
|
|
||||||
Priv.Added := True;
|
|
||||||
FPrivObjects.Add(Priv);
|
|
||||||
Node := treePrivs.AddChild(nil);
|
|
||||||
Child := treePrivs.GetFirstChild(Node);
|
|
||||||
while Assigned(Child) do
|
|
||||||
Child := treePrivs.GetNextSibling(Child);
|
|
||||||
treePrivs.Expanded[Node] := True;
|
|
||||||
treePrivs.SetFocus;
|
|
||||||
SelectNode(treePrivs, Node);
|
|
||||||
Modified := True;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user