Skip to content

Commit

Permalink
user FB2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdochoa committed Jan 6, 2024
1 parent 1afa38f commit 007c633
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/gui/ContextMenuMetadataItemVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ void MainObjectMenuMetadataItemVisitor::addActiveItem(MetadataItem& metadataItem
}

}

void MainObjectMenuMetadataItemVisitor::addCreateItem()
{
// This menu command is redundant in the main Object menu.
Expand Down
89 changes: 82 additions & 7 deletions src/gui/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand Down Expand Up @@ -1731,6 +1771,41 @@ void MainFrame::OnMenuAlterObject(wxCommandEvent& WXUNUSED(event))
sql = pk->getAlterSql();
else if (FunctionSQL* fn = dynamic_cast<FunctionSQL*>(mi))
sql = fn->getAlterSql();
else if (User* u = dynamic_cast<User*>(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);
Expand Down
12 changes: 8 additions & 4 deletions src/metadata/MetadataItemDescriptionVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'");
}
}

5 changes: 3 additions & 2 deletions src/metadata/User.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 007c633

Please sign in to comment.