Skip to content

Commit

Permalink
Add users
Browse files Browse the repository at this point in the history
  • Loading branch information
jdochoa committed Jan 5, 2024
1 parent 8640fcb commit 1afa38f
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 25 deletions.
21 changes: 21 additions & 0 deletions html-templates/USER.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<html>
<head>
<title>User</title>
</head>
<body>
{%header:Summary%}
<br>
<br>
<font size=+2>{%object_name%}</font>
<br>{%object_description%} [<a
href="fr://edit_description?parent_window={%parent_window%}&amp;object_handle={%object_handle%}&amp;object_type=USER&amp;object_name={%object_name%}">edit</a>]|
<br><br>
<table cellspacing=1 cellpadding=3 border=0 width="98%" bgcolor="black">
<tr><td bgcolor="navy"><font color=white><b>User info</b>[<a
href="fr://edit_collation?parent_window={%parent_window%}&amp;object_handle={%object_handle%}"><font
color="yellow">edit</font></a>]</font></td>
</tr>
<tr><td bgcolor="#DDDDFF"><font size=-1><pre>{%userinfo:source%}</pre></font></td></tr>
</table>
</body>
</html>
5 changes: 3 additions & 2 deletions src/gui/MetadataItemPropertiesFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,8 @@ wxIcon getMetadataItemIcon(NodeType type)
return wxArtProvider::GetIcon(ART_Function, wxART_OTHER, sz);
case ntGenerator:
return wxArtProvider::GetIcon(ART_Generator, wxART_OTHER, sz);
// TODO: replace package art
case ntPackage:
return wxArtProvider::GetIcon(ART_Procedure, wxART_OTHER, sz);
return wxArtProvider::GetIcon(ART_Package, wxART_OTHER, sz);
case ntProcedure:
return wxArtProvider::GetIcon(ART_Procedure, wxART_OTHER, sz);
case ntServer:
Expand All @@ -414,6 +413,8 @@ wxIcon getMetadataItemIcon(NodeType type)
return wxArtProvider::GetIcon(ART_Trigger, wxART_OTHER, sz);
case ntView:
return wxArtProvider::GetIcon(ART_View, wxART_OTHER, sz);
case ntUser:
return wxArtProvider::GetIcon(ART_User, wxART_OTHER, sz);
default:
break;
}
Expand Down
13 changes: 13 additions & 0 deletions src/metadata/MetadataItemDescriptionVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "metadata/relation.h"
#include "metadata/role.h"
#include "metadata/trigger.h"
#include "metadata/user.h"


// class LoadDescriptionVisitor
Expand Down Expand Up @@ -221,6 +222,13 @@ void LoadDescriptionVisitor::visitTrigger(Trigger& trigger)
"where RDB$TRIGGER_NAME = ?");
}

void LoadDescriptionVisitor::visitUser(User& user)
{
loadDescription(&user,
"select SEC$DESCRIPTION from SEC$USERS "
"where SEC$USER_NAME = ?");
}

// class SaveDescriptionVisitor
SaveDescriptionVisitor::SaveDescriptionVisitor(wxString description)
: MetadataItemVisitor(), descriptionM(description)
Expand Down Expand Up @@ -429,3 +437,8 @@ void SaveDescriptionVisitor::visitTrigger(Trigger& trigger)
"where RDB$TRIGGER_NAME = ?");
}

void SaveDescriptionVisitor::visitUser(User& user)
{
saveDescription(&user, "comment on trigger %s is '%s'");
}

2 changes: 2 additions & 0 deletions src/metadata/MetadataItemDescriptionVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class LoadDescriptionVisitor : public MetadataItemVisitor
virtual void visitRelation(Relation& relation);
virtual void visitRole(Role& role);
virtual void visitTrigger(Trigger& trigger);
virtual void visitUser(User& user);

bool descriptionAvailable() const;
wxString getDescription() const;
Expand Down Expand Up @@ -82,6 +83,7 @@ class SaveDescriptionVisitor : public MetadataItemVisitor
virtual void visitRelation(Relation& relation);
virtual void visitRole(Role& role);
virtual void visitTrigger(Trigger& trigger);
virtual void visitUser(User& user);
};

#endif // FR_DESCRIPTIONVISITOR_H
9 changes: 6 additions & 3 deletions src/metadata/MetadataTemplateCmdHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,9 @@ void MetadataTemplateCmdHandler::handleTemplateCmd(TemplateProcessor *tp,
processedText << u->getUserId();
else if (cmdParams[0] == "unix_group")
processedText << u->getGroupId();
else if (cmdParams[0] == "source")
processedText += tp->escapeChars(u->getSource(), false);

}
// {%sql_security%}
// If the current object is a data base, procedure, relation,
Expand Down Expand Up @@ -1001,11 +1004,11 @@ void MetadataTemplateCmdHandler::handleTemplateCmd(TemplateProcessor *tp,
}
else if ((cmdName == "collationinfo") && (cmdParams.Count() >= 1))
{
Collation* p = dynamic_cast<Collation*>(object);
if (!p)
Collation* c = dynamic_cast<Collation*>(object);
if (!c)
return;
if (cmdParams[0] == "source")
processedText += tp->escapeChars(p->getSource(), false);
processedText += tp->escapeChars(c->getSource(), false);

}

Expand Down
179 changes: 168 additions & 11 deletions src/metadata/User.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@
#include "wx/wx.h"
#endif

#include <ibpp.h>

#include "core/FRError.h"
#include "core/StringUtils.h"
#include "engine/MetadataLoader.h"
#include "metadata/MetadataItemVisitor.h"
#include "metadata/server.h"
#include "metadata/User.h"

void User::loadProperties()
{
}

User::User(ServerPtr server)
: MetadataItem(ntUnknown, server.get()), serverM(server)
{
Expand Down Expand Up @@ -96,6 +104,21 @@ uint32_t User::getGroupId() const
return groupidM;
}

IBPP::User& User::getUserIBPP() const
{
IBPP::User usr;

usr.username = wx2std(usernameM);
usr.password = wx2std(passwordM);
usr.firstname = wx2std(firstnameM);
usr.lastname = wx2std(lastnameM);
usr.middlename = wx2std(middlenameM);
usr.userid = useridM;
usr.groupid = groupidM;

return usr;
}

void User::setUsername(const wxString& value)
{
if (usernameM != value)
Expand Down Expand Up @@ -159,28 +182,52 @@ void User::setGroupId(uint32_t value)
}
}

void User::setUserIBPP(const IBPP::User& usr)
{
setUsername(usr.username);
setUsername(usr.username);
setPassword(usr.password);
setFirstName(usr.firstname);
setMiddleName(usr.middlename);
setLastName(usr.lastname);
setUserId(usr.userid);
setGroupId(usr.groupid);

notifyObservers();
}

void User::assignTo(IBPP::User& dest) const
{
dest.username = wx2std(usernameM);
dest.password = wx2std(passwordM);
dest.firstname = wx2std(firstnameM);
dest.lastname = wx2std(lastnameM);
dest.middlename = wx2std(middlenameM);
dest.userid = useridM;
dest.groupid = groupidM;
dest = getUserIBPP();
}

void User::acceptVisitor(MetadataItemVisitor* visitor)
{
visitor->visitUser(*this);
}

const wxString User::getTypeName() const
{
return "USER";
}

wxString User::getSource()
{
ensurePropertiesLoaded();
wxString sql = "FIRSTNAME '" + getFirstName() + "' \n" +
"MIDDLENAME '" + getMiddleName() + "' \n"
"LASTNAME '" + getLastName() + "' \n"
"USING PLUGIN "+" \n"

;
return sql;
}

bool User::isSystem() const
{
return usernameM == "SYSDBA";
}


void Users::loadChildren()
{
load(0);
Expand All @@ -199,7 +246,7 @@ void Users::acceptVisitor(MetadataItemVisitor* visitor)
void Users::load(ProgressIndicator* progressIndicator)
{

DatabasePtr db = getDatabase();
/*DatabasePtr db = getDatabase();
if (db->getInfo().getODSVersionIsHigherOrEqualTo(12, 0)) {
wxString stmt = "select sec$user_name from sec$users a order by 1 ";
setItems(db->loadIdentifiers(stmt, progressIndicator));
Expand All @@ -217,14 +264,15 @@ void Users::load(ProgressIndicator* progressIndicator)
}
}
}
}*/
}

const wxString Users::getTypeName() const
{
return "USERS_COLLECTION";
}


Users20::Users20(DatabasePtr database)
:Users(database)
{
Expand All @@ -243,6 +291,9 @@ void Users20::load(ProgressIndicator* progressIndicator)
{
insert(it->username);
}
notifyObservers();
setChildrenLoaded(true);

}

}
Expand All @@ -256,6 +307,112 @@ Users30::Users30(DatabasePtr database)
void Users30::load(ProgressIndicator* progressIndicator)
{
DatabasePtr db = getDatabase();
wxString stmt = "select sec$user_name from sec$users a order by 1 ";
wxString stmt = "select sec$user_name from sec$users order by 1 ";
setItems(db->loadIdentifiers(stmt, progressIndicator));
}

void User20::loadProperties()
{
setPropertiesLoaded(false);

DatabasePtr db = getDatabase();
IBPP::Service svc;
if (db->getServer()->getService(svc, NULL, true)) {
IBPP::User usr;
usr.username = getName_();
svc->GetUser(usr);
setUserIBPP(usr);
}

setPropertiesLoaded(true);
notifyObservers();
}

User20::User20(ServerPtr server)
: User(server)
{
}

User20::User20(ServerPtr server, const IBPP::User& src)
:User(server, src)
{
}

User20::User20(DatabasePtr database, const wxString& name)
:User(database, name)
{
}

void User30::loadProperties()
{

DatabasePtr db = getDatabase();

MetadataLoader* loader = db->getMetadataLoader();
MetadataLoaderTransaction tr(loader);
wxMBConv* converter = db->getCharsetConverter();

IBPP::Statement& st1 = loader->getStatement(
"select sec$user_name, "
"sec$first_name, "
"sec$middle_name, "
"sec$last_name, "
"sec$active, "
"sec$admin, "
"sec$description, "
"sec$plugin "
"from sec$users "
"where sec$user_name = ? "
);
st1->Set(1, wx2std(getName_(), converter));
st1->Execute();
if (!st1->Fetch())
throw FRError(_("User not found: ") + getName_());

setPropertiesLoaded(false);
std::string lstr;


if (st1->IsNull(2))
lstr = "";
else
st1->Get(2, lstr);
setFirstName(lstr);

if (st1->IsNull(3))
lstr = "";
else
st1->Get(3, lstr);
setMiddleName(lstr);

if (st1->IsNull(4))
lstr = "";
else
st1->Get(4, lstr);
setLastName(lstr);

if (st1->IsNull(4))
lstr = "";
else
st1->Get(4, lstr);
setLastName(lstr);

setPropertiesLoaded(true);
notifyObservers();
}

User30::User30(ServerPtr server)
: User(server)
{
}

User30::User30(ServerPtr server, const IBPP::User& src)
:User(server, src)
{
}

User30::User30(DatabasePtr database, const wxString& name)
:User(database, name)
{
}

Loading

0 comments on commit 1afa38f

Please sign in to comment.