aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-07-18 19:21:15 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-07-18 19:21:18 +0200
commit6ac05b4598f4b9133384bb586b50a9c1b2753796 (patch)
tree7468b7aefc4443626fe90eafd849acf5f10d523c /src
parent92217f9654284d2b3db4c4e17c154658a2125458 (diff)
Add method to get user lowest permission level
Diffstat (limited to 'src')
-rw-r--r--src/Database.cpp5
-rw-r--r--src/DatabaseStorage.cpp14
2 files changed, 19 insertions, 0 deletions
diff --git a/src/Database.cpp b/src/Database.cpp
index a05aae6..564b3d6 100644
--- a/src/Database.cpp
+++ b/src/Database.cpp
@@ -714,6 +714,11 @@ namespace odhtdb
{
return databaseStorage.getUserGroups(nodeHash, userPublicKey);
}
+
+ int Database::getUserLowestPermissionLevel(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const
+ {
+ return databaseStorage.getUserLowestPermissionLevel(nodeHash, userPublicKey);
+ }
std::future<size_t> Database::receiveCustomMessage(const dht::InfoHash &receiveMessageKey, ReceiveCustomMessageCallbackFunc callbackFunc)
{
diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp
index 407aa5c..9398254 100644
--- a/src/DatabaseStorage.cpp
+++ b/src/DatabaseStorage.cpp
@@ -825,6 +825,20 @@ namespace odhtdb
{ DataView(nodeHash.getData(), nodeHash.getSize()), DataView((void*)userPublicKey.getData(), userPublicKey.getSize()), groupToAddPermissionLevel, (i64)PermissionType::ADD_USER_SAME_LEVEL, groupToAddPermissionLevel, (i64)PermissionType::ADD_USER_HIGHER_LEVEL });
return queryCreatorGroupWithRightsToAddUserToGroup.next();
}
+
+ int DatabaseStorage::getUserLowestPermissionLevel(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const
+ {
+ SqlQuery query(sqliteDb, "SELECT MIN(nodeGroup.permissionLevel) FROM NodeUserGroupAssoc AS userGroupAssoc"
+ " INNER JOIN NodeGroup AS nodeGroup ON nodeGroup.groupId = userGroupAssoc.groupId"
+ " WHERE userGroupAssoc.node = ? AND userGroupAssoc.userPublicKey = ?",
+ { DataView(nodeHash.getData(), nodeHash.getSize()), DataView((void*)userPublicKey.getData(), userPublicKey.getSize()) });
+ if(!query.next())
+ {
+ Log::error("There is no node %s, no user %s in that node or user does not belong to any groups", nodeHash.toString().c_str(), userPublicKey.toString().c_str());
+ return -1;
+ }
+ return query.getInt(0);
+ }
u64 DatabaseStorage::getUserActionCounter(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const
{