From 76148ccf33b3c85e73b3ed9103f3cb209c93fb49 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Sat, 29 Mar 2008 02:32:14 +0100 Subject: [PATCH] Use the new explicit KeyValue system to retreive Permissions. --- UnsignedByte/Core/Command.cpp | 39 ++++++++++++++++++--------------------- UnsignedByte/Core/Command.h | 4 ++-- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/UnsignedByte/Core/Command.cpp b/UnsignedByte/Core/Command.cpp index 48fe42f..74e3e41 100644 --- a/UnsignedByte/Core/Command.cpp +++ b/UnsignedByte/Core/Command.cpp @@ -27,6 +27,7 @@ #include "Account.h" #include "Exceptions.h" #include "Permission.h" +#include "TableImpls.h" using mud::Command; @@ -51,7 +52,7 @@ const std::string& Command::getHelp() const return m_command->getfield(db::CommandsFields::Get()->HELP)->getStringValue(); } -long Command::getGrantGroup() const +value_type Command::getGrantGroup() const { return m_command->getfield(db::CommandsFields::Get()->GRANTGROUP)->getIntegerValue(); } @@ -84,7 +85,7 @@ void Command::setHelp(const std::string& name) m_command->setvalue(value); } -void Command::setGrantGroup(long grantgroup) +void Command::setGrantGroup(value_type grantgroup) { ValuePtr value(new Value(db::CommandsFields::Get()->GRANTGROUP, grantgroup)); m_command->setvalue(value); @@ -113,15 +114,14 @@ bool Command::getGrant(UBSocket* sock) { try { - long gid = getGrantGroup(); - long aid = sock->GetAccount()->getID(); + RelationPtr relation(new Relation(db::TableImpls::Get()->PERMISSIONS)); + relation->addKey(db::PermissionsFields::Get()->FKGRANTGROUPS, getGrantGroup()); + relation->addKey(db::PermissionsFields::Get()->FKACCOUNTS, sock->GetAccount()->getID()); - PermissionPtr prm = mud::PermissionManager::Get()->GetByKeys(aid, gid); - return prm->hasGrant(); - } - catch(RowNotFoundException& e) - { - Global::Get()->bug(e.what()); + PermissionPtr permission = mud::PermissionManager::Get()->GetByKeys(relation->getKeys()); + + return permission->hasGrant(); + } catch(RowNotFoundException& e) { return getDefaultGrant(); } } @@ -134,9 +134,7 @@ bool Command::getDefaultGrant() GrantGroupPtr grp = mud::GrantGroupManager::Get()->GetByKey(id); return grp->getDefaultGrant(); } - catch(RowNotFoundException& e) - { - Global::Get()->bug(e.what()); + catch(RowNotFoundException& e) { return mud::PermissionManager::Get()->defaultGrant; } } @@ -145,15 +143,14 @@ bool Command::getLog(UBSocket* sock) { try { - long gid = getGrantGroup(); - long aid = sock->GetAccount()->getID(); + RelationPtr relation(new Relation(db::TableImpls::Get()->PERMISSIONS)); + relation->addKey(db::PermissionsFields::Get()->FKGRANTGROUPS, getGrantGroup()); + relation->addKey(db::PermissionsFields::Get()->FKACCOUNTS, sock->GetAccount()->getID()); - PermissionPtr prm = mud::PermissionManager::Get()->GetByKeys(aid, gid); - return prm->hasLog(); - } - catch(RowNotFoundException& e) - { - Global::Get()->bug(e.what()); + PermissionPtr permission = mud::PermissionManager::Get()->GetByKeys(relation->getKeys()); + + return permission->hasLog(); + } catch(RowNotFoundException& e) { return getDefaultLog(); } } diff --git a/UnsignedByte/Core/Command.h b/UnsignedByte/Core/Command.h index 0aa8dbf..9bca0db 100644 --- a/UnsignedByte/Core/Command.h +++ b/UnsignedByte/Core/Command.h @@ -36,7 +36,7 @@ namespace mud */ const std::string& getName() const; const std::string& getHelp() const; - long getGrantGroup() const; + value_type getGrantGroup() const; bool canHighForce() const; bool canForce() const; bool canLowForce() const; @@ -52,7 +52,7 @@ namespace mud */ void setName(const std::string& name); void setHelp(const std::string& name); - void setGrantGroup(long grantgroup); + void setGrantGroup(value_type grantgroup); void setHighForce(bool highforce); void setForce(bool force); void setLowForce(bool lowforce); -- 2.11.4.GIT