From 007c63366371d2067a787f524ec06b3b06ebce68 Mon Sep 17 00:00:00 2001 From: jdochoa Date: Sat, 6 Jan 2024 09:42:58 -0600 Subject: [PATCH] user FB2.0 --- src/gui/ContextMenuMetadataItemVisitor.cpp | 1 - src/gui/MainFrame.cpp | 89 +++++++++++++++++-- .../MetadataItemDescriptionVisitor.cpp | 12 ++- src/metadata/User.cpp | 5 +- 4 files changed, 93 insertions(+), 14 deletions(-) diff --git a/src/gui/ContextMenuMetadataItemVisitor.cpp b/src/gui/ContextMenuMetadataItemVisitor.cpp index d2433a34..7af962f0 100644 --- a/src/gui/ContextMenuMetadataItemVisitor.cpp +++ b/src/gui/ContextMenuMetadataItemVisitor.cpp @@ -577,7 +577,6 @@ void MainObjectMenuMetadataItemVisitor::addActiveItem(MetadataItem& metadataItem } } - void MainObjectMenuMetadataItemVisitor::addCreateItem() { // This menu command is redundant in the main Object menu. diff --git a/src/gui/MainFrame.cpp b/src/gui/MainFrame.cpp index c6df8376..35cea30a 100644 --- a/src/gui/MainFrame.cpp +++ b/src/gui/MainFrame.cpp @@ -63,6 +63,7 @@ #include "gui/SimpleHtmlFrame.h" #include "gui/ShutdownFrame.h" #include "gui/StartupFrame.h" +#include "gui/UserDialog.h" #include "main.h" #include "metadata/column.h" #include "metadata/domain.h" @@ -1497,8 +1498,40 @@ void MainFrame::OnMenuCreateUDF(wxCommandEvent& WXUNUSED(event)) void MainFrame::OnMenuCreateUser(wxCommandEvent& WXUNUSED(event)) { - showCreateTemplate( - MetadataItemCreateStatementVisitor::getCreateUserStatement()); + DatabasePtr db = getDatabase(treeMainM->getSelectedMetadataItem()); + if (db->getInfo().getODSVersionIsHigherOrEqualTo(12, 0)) { + showCreateTemplate( + MetadataItemCreateStatementVisitor::getCreateUserStatement()); + } + else + { + ServerPtr server = getServer(treeMainM->getSelectedMetadataItem()); + UserPtr user (new User(server)); + + UserDialog d(this, _("Create New User"), true); + d.setUser(user); + if (d.ShowModal() == wxID_OK) + { + ProgressDialog pd(this, _("Connecting to Server..."), 1); + pd.doShow(); + IBPP::Service svc; + if (!getService(server.get(), svc, &pd, true)) // true = need SYSDBA password + return; + + try + { + IBPP::User u; + user->assignTo(u); + svc->AddUser(u); + server->notifyObservers(); + } + catch (IBPP::Exception& e) + { + wxMessageBox(e.what(), _("Error"), + wxOK | wxICON_WARNING); + } + } + } } void MainFrame::OnMenuCreateView(wxCommandEvent& WXUNUSED(event)) @@ -1507,15 +1540,22 @@ void MainFrame::OnMenuCreateView(wxCommandEvent& WXUNUSED(event)) MetadataItemCreateStatementVisitor::getCreateViewStatement()); } -void MainFrame::OnMenuCreateObject(wxCommandEvent& WXUNUSED(event)) +void MainFrame::OnMenuCreateObject(wxCommandEvent& event) { MetadataItem* item = treeMainM->getSelectedMetadataItem(); if (!item) return; - - MetadataItemCreateStatementVisitor csv; - item->acceptVisitor(&csv); - showCreateTemplate(csv.getStatement()); + switch (item->getType()) + { + case ntUsers: + OnMenuCreateUser(event); + break; + default: + MetadataItemCreateStatementVisitor csv; + item->acceptVisitor(&csv); + showCreateTemplate(csv.getStatement()); + break; + } } void MainFrame::showCreateTemplate(const wxString& statement) @@ -1731,6 +1771,41 @@ void MainFrame::OnMenuAlterObject(wxCommandEvent& WXUNUSED(event)) sql = pk->getAlterSql(); else if (FunctionSQL* fn = dynamic_cast(mi)) sql = fn->getAlterSql(); + else if (User* u = dynamic_cast(mi)) { + /*if (db->getInfo().getODSVersionIsHigherOrEqualTo(12, 0)) { + sql = u->getAlterSql(); + } + else*/{ + ServerPtr server = getServer(treeMainM->getSelectedMetadataItem()); + u->ensurePropertiesLoaded(); + IBPP::User usr1 = u->getUserIBPP(); + UserPtr user (new User(server, usr1)); + + UserDialog d(this, _("Modify User"), true); + d.setUser(user); + if (d.ShowModal() == wxID_OK) + { + ProgressDialog pd(this, _("Connecting to Server..."), 1); + pd.doShow(); + IBPP::Service svc; + if (!getService(server.get(), svc, &pd, true)) // true = need SYSDBA password + return; + + try + { + IBPP::User usr = user->getUserIBPP(); + svc->ModifyUser (usr); + server->notifyObservers(); + } + catch (IBPP::Exception& e) + { + wxMessageBox(e.what(), _("Error"), + wxOK | wxICON_WARNING); + } + } + + } + } if (!sql.empty()) showSql(this, wxString(_("Alter object")), db, sql); diff --git a/src/metadata/MetadataItemDescriptionVisitor.cpp b/src/metadata/MetadataItemDescriptionVisitor.cpp index aef11f78..4bfcb993 100644 --- a/src/metadata/MetadataItemDescriptionVisitor.cpp +++ b/src/metadata/MetadataItemDescriptionVisitor.cpp @@ -224,9 +224,11 @@ void LoadDescriptionVisitor::visitTrigger(Trigger& trigger) void LoadDescriptionVisitor::visitUser(User& user) { - loadDescription(&user, - "select SEC$DESCRIPTION from SEC$USERS " - "where SEC$USER_NAME = ?"); + if (user.getDatabase()->getInfo().getODSVersionIsHigherOrEqualTo(12, 0)) { + loadDescription(&user, + "select SEC$DESCRIPTION from SEC$USERS " + "where SEC$USER_NAME = ?"); + } } // class SaveDescriptionVisitor @@ -439,6 +441,8 @@ void SaveDescriptionVisitor::visitTrigger(Trigger& trigger) void SaveDescriptionVisitor::visitUser(User& user) { - saveDescription(&user, "comment on trigger %s is '%s'"); + if (user.getDatabase()->getInfo().getODSVersionIsHigherOrEqualTo(12, 0)) { + saveDescription(&user, "comment on trigger %s is '%s'"); + } } diff --git a/src/metadata/User.cpp b/src/metadata/User.cpp index 70b2bb7b..75cf7b7d 100644 --- a/src/metadata/User.cpp +++ b/src/metadata/User.cpp @@ -106,8 +106,9 @@ uint32_t User::getGroupId() const IBPP::User& User::getUserIBPP() const { - IBPP::User usr; - + + IBPP::User usr; + usr.username = wx2std(usernameM); usr.password = wx2std(passwordM); usr.firstname = wx2std(firstnameM);