mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:21:16 +02:00
code review
This commit is contained in:
parent
148793011d
commit
bc2ded2f97
6 changed files with 33 additions and 68 deletions
|
@ -315,8 +315,6 @@ SharedNodePointer DomainGatekeeper::processAgentConnectRequest(const NodeConnect
|
||||||
sendConnectionTokenPacket(username, nodeConnection.senderSockAddr);
|
sendConnectionTokenPacket(username, nodeConnection.senderSockAddr);
|
||||||
// ask for their public key right now to make sure we have it
|
// ask for their public key right now to make sure we have it
|
||||||
requestUserPublicKey(username);
|
requestUserPublicKey(username);
|
||||||
getGroupMemberships(username); // optimistically get started on group memberships
|
|
||||||
getDomainOwnerFriendsList();
|
|
||||||
return SharedNodePointer();
|
return SharedNodePointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,7 +324,6 @@ SharedNodePointer DomainGatekeeper::processAgentConnectRequest(const NodeConnect
|
||||||
userPerms.setVerifiedUserName(username);
|
userPerms.setVerifiedUserName(username);
|
||||||
verifiedUsername = username;
|
verifiedUsername = username;
|
||||||
getGroupMemberships(username);
|
getGroupMemberships(username);
|
||||||
getDomainOwnerFriendsList();
|
|
||||||
} else if (!username.isEmpty()) {
|
} else if (!username.isEmpty()) {
|
||||||
// they sent us a username, but it didn't check out
|
// they sent us a username, but it didn't check out
|
||||||
requestUserPublicKey(username);
|
requestUserPublicKey(username);
|
||||||
|
@ -725,6 +722,14 @@ void DomainGatekeeper::getGroupMemberships(const QString& username) {
|
||||||
// loop through the groups mentioned on the settings page and ask if this user is in each. The replies
|
// loop through the groups mentioned on the settings page and ask if this user is in each. The replies
|
||||||
// will be received asynchronously and permissions will be updated as the answers come in.
|
// will be received asynchronously and permissions will be updated as the answers come in.
|
||||||
|
|
||||||
|
// if we've already asked, wait for the answer before asking again
|
||||||
|
QString lowerUsername = username.toLower();
|
||||||
|
if (_inFlightGroupMembershipsRequests.contains(lowerUsername)) {
|
||||||
|
// public-key request for this username is already flight, not rerequesting
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_inFlightGroupMembershipsRequests += lowerUsername;
|
||||||
|
|
||||||
QJsonObject json;
|
QJsonObject json;
|
||||||
QSet<QString> groupIDSet;
|
QSet<QString> groupIDSet;
|
||||||
foreach (QUuid groupID, _server->_settingsManager.getGroupIDs() + _server->_settingsManager.getBlacklistGroupIDs()) {
|
foreach (QUuid groupID, _server->_settingsManager.getGroupIDs() + _server->_settingsManager.getBlacklistGroupIDs()) {
|
||||||
|
@ -747,7 +752,16 @@ void DomainGatekeeper::getGroupMemberships(const QString& username) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString extractUsernameFromGroupMembershipsReply(QNetworkReply& requestReply) {
|
||||||
|
// extract the username from the request url
|
||||||
|
QString username;
|
||||||
|
const QString GROUP_MEMBERSHIPS_URL_REGEX_STRING = "api\\/v1\\/groups\\/members\\/([A-Za-z0-9_\\.]+)";
|
||||||
|
QRegExp usernameRegex(GROUP_MEMBERSHIPS_URL_REGEX_STRING);
|
||||||
|
if (usernameRegex.indexIn(requestReply.url().toString()) != -1) {
|
||||||
|
username = usernameRegex.cap(1);
|
||||||
|
}
|
||||||
|
return username.toLower();
|
||||||
|
}
|
||||||
|
|
||||||
void DomainGatekeeper::getIsGroupMemberJSONCallback(QNetworkReply& requestReply) {
|
void DomainGatekeeper::getIsGroupMemberJSONCallback(QNetworkReply& requestReply) {
|
||||||
// {
|
// {
|
||||||
|
@ -781,10 +795,13 @@ void DomainGatekeeper::getIsGroupMemberJSONCallback(QNetworkReply& requestReply)
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "getIsGroupMember api call returned:" << QJsonDocument(jsonObject).toJson(QJsonDocument::Compact);
|
qDebug() << "getIsGroupMember api call returned:" << QJsonDocument(jsonObject).toJson(QJsonDocument::Compact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_inFlightGroupMembershipsRequests.remove(extractUsernameFromGroupMembershipsReply(requestReply));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainGatekeeper::getIsGroupMemberErrorCallback(QNetworkReply& requestReply) {
|
void DomainGatekeeper::getIsGroupMemberErrorCallback(QNetworkReply& requestReply) {
|
||||||
qDebug() << "getIsGroupMember api call failed:" << requestReply.error();
|
qDebug() << "getIsGroupMember api call failed:" << requestReply.error();
|
||||||
|
_inFlightGroupMembershipsRequests.remove(extractUsernameFromGroupMembershipsReply(requestReply));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainGatekeeper::getDomainOwnerFriendsList() {
|
void DomainGatekeeper::getDomainOwnerFriendsList() {
|
||||||
|
@ -825,7 +842,6 @@ void DomainGatekeeper::refreshGroupsCache() {
|
||||||
// if agents are connected to this domain, refresh our cached information about groups and memberships in such.
|
// if agents are connected to this domain, refresh our cached information about groups and memberships in such.
|
||||||
getDomainOwnerFriendsList();
|
getDomainOwnerFriendsList();
|
||||||
|
|
||||||
int agentCount = 0;
|
|
||||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||||
nodeList->eachNode([&](const SharedNodePointer& node) {
|
nodeList->eachNode([&](const SharedNodePointer& node) {
|
||||||
if (!node->getPermissions().isAssignment) {
|
if (!node->getPermissions().isAssignment) {
|
||||||
|
@ -834,13 +850,10 @@ void DomainGatekeeper::refreshGroupsCache() {
|
||||||
if (verifiedUserName.isEmpty()) {
|
if (verifiedUserName.isEmpty()) {
|
||||||
getGroupMemberships(verifiedUserName);
|
getGroupMemberships(verifiedUserName);
|
||||||
}
|
}
|
||||||
agentCount++;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (agentCount > 0) {
|
_server->_settingsManager.apiRefreshGroupInformation();
|
||||||
_server->_settingsManager.apiRefreshGroupInformation();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateNodePermissions();
|
updateNodePermissions();
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,7 @@ private:
|
||||||
QHash<QString, QByteArray> _userPublicKeys;
|
QHash<QString, QByteArray> _userPublicKeys;
|
||||||
QSet<QString> _inFlightPublicKeyRequests; // keep track of which we've already asked for
|
QSet<QString> _inFlightPublicKeyRequests; // keep track of which we've already asked for
|
||||||
QSet<QString> _domainOwnerFriends; // keep track of friends of the domain owner
|
QSet<QString> _domainOwnerFriends; // keep track of friends of the domain owner
|
||||||
|
QSet<QString> _inFlightGroupMembershipsRequests; // keep track of which we've already asked for
|
||||||
|
|
||||||
NodePermissions applyPermissionsForUser(bool isLocalUser, NodePermissions userPerms, QString verifiedUsername);
|
NodePermissions applyPermissionsForUser(bool isLocalUser, NodePermissions userPerms, QString verifiedUsername);
|
||||||
void getGroupMemberships(const QString& username);
|
void getGroupMemberships(const QString& username);
|
||||||
|
|
|
@ -346,7 +346,7 @@ void DomainServerSettingsManager::initializeGroupPermissions(NodePermissionsMap&
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
permissionsRows[nameKey]->setAll(false);
|
permissionsRows[nameKey]->setAll(false);
|
||||||
permissionsRows[nameKey] |= perms;
|
*(permissionsRows[nameKey]) |= *perms;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,7 +480,7 @@ void DomainServerSettingsManager::unpackPermissions() {
|
||||||
foundFriends |= (idKey == NodePermissions::standardNameFriends);
|
foundFriends |= (idKey == NodePermissions::standardNameFriends);
|
||||||
if (_standardAgentPermissions.contains(idKey)) {
|
if (_standardAgentPermissions.contains(idKey)) {
|
||||||
qDebug() << "duplicate name in standard permissions table: " << id;
|
qDebug() << "duplicate name in standard permissions table: " << id;
|
||||||
_standardAgentPermissions[idKey] |= perms;
|
*(_standardAgentPermissions[idKey]) |= *perms;
|
||||||
needPack = true;
|
needPack = true;
|
||||||
} else {
|
} else {
|
||||||
_standardAgentPermissions[idKey] = perms;
|
_standardAgentPermissions[idKey] = perms;
|
||||||
|
@ -494,7 +494,7 @@ void DomainServerSettingsManager::unpackPermissions() {
|
||||||
NodePermissionsKey idKey = NodePermissionsKey(id, 0);
|
NodePermissionsKey idKey = NodePermissionsKey(id, 0);
|
||||||
if (_agentPermissions.contains(idKey)) {
|
if (_agentPermissions.contains(idKey)) {
|
||||||
qDebug() << "duplicate name in permissions table: " << id;
|
qDebug() << "duplicate name in permissions table: " << id;
|
||||||
_agentPermissions[idKey] |= perms;
|
*(_agentPermissions[idKey]) |= *perms;
|
||||||
needPack = true;
|
needPack = true;
|
||||||
} else {
|
} else {
|
||||||
_agentPermissions[idKey] = perms;
|
_agentPermissions[idKey] = perms;
|
||||||
|
@ -508,10 +508,10 @@ void DomainServerSettingsManager::unpackPermissions() {
|
||||||
NodePermissionsKey idKey = perms->getKey();
|
NodePermissionsKey idKey = perms->getKey();
|
||||||
if (_groupPermissions.contains(idKey)) {
|
if (_groupPermissions.contains(idKey)) {
|
||||||
qDebug() << "duplicate name in group permissions table: " << id;
|
qDebug() << "duplicate name in group permissions table: " << id;
|
||||||
_groupPermissions[idKey] |= perms;
|
*(_groupPermissions[idKey]) |= *perms;
|
||||||
needPack = true;
|
needPack = true;
|
||||||
} else {
|
} else {
|
||||||
_groupPermissions[idKey] = perms;
|
*(_groupPermissions[idKey]) = *perms;
|
||||||
}
|
}
|
||||||
if (perms->isGroup()) {
|
if (perms->isGroup()) {
|
||||||
// the group-id was cached. hook-up the uuid in the uuid->group hash
|
// the group-id was cached. hook-up the uuid in the uuid->group hash
|
||||||
|
@ -527,7 +527,7 @@ void DomainServerSettingsManager::unpackPermissions() {
|
||||||
NodePermissionsKey idKey = perms->getKey();
|
NodePermissionsKey idKey = perms->getKey();
|
||||||
if (_groupForbiddens.contains(idKey)) {
|
if (_groupForbiddens.contains(idKey)) {
|
||||||
qDebug() << "duplicate name in group forbiddens table: " << id;
|
qDebug() << "duplicate name in group forbiddens table: " << id;
|
||||||
_groupForbiddens[idKey] |= perms;
|
*(_groupForbiddens[idKey]) |= *perms;
|
||||||
needPack = true;
|
needPack = true;
|
||||||
} else {
|
} else {
|
||||||
_groupForbiddens[idKey] = perms;
|
_groupForbiddens[idKey] = perms;
|
||||||
|
@ -1367,7 +1367,7 @@ void DomainServerSettingsManager::apiGetGroupRanksJSONCallback(QNetworkReply& re
|
||||||
QHash<QUuid, bool> idsFromThisUpdate;
|
QHash<QUuid, bool> idsFromThisUpdate;
|
||||||
|
|
||||||
for (int rankIndex = 0; rankIndex < ranks.size(); rankIndex++) {
|
for (int rankIndex = 0; rankIndex < ranks.size(); rankIndex++) {
|
||||||
QJsonObject rank = ranks.at(rankIndex).toObject();
|
QJsonObject rank = ranks[rankIndex].toObject();
|
||||||
|
|
||||||
QUuid rankID = QUuid(rank["id"].toString());
|
QUuid rankID = QUuid(rank["id"].toString());
|
||||||
int rankOrder = rank["order"].toInt();
|
int rankOrder = rank["order"].toInt();
|
||||||
|
|
|
@ -14,14 +14,14 @@
|
||||||
|
|
||||||
class GroupRank {
|
class GroupRank {
|
||||||
public:
|
public:
|
||||||
GroupRank() : id(QUuid()), order(-1), name(""), membersCount(-1) {}
|
GroupRank() {}
|
||||||
GroupRank(QUuid id, unsigned int order, QString name, unsigned int membersCount) :
|
GroupRank(QUuid id, unsigned int order, QString name, unsigned int membersCount) :
|
||||||
id(id), order(order), name(name), membersCount(membersCount) {}
|
id(id), order(order), name(name), membersCount(membersCount) {}
|
||||||
|
|
||||||
QUuid id;
|
QUuid id;
|
||||||
int order;
|
int order { -1 };
|
||||||
QString name;
|
QString name;
|
||||||
int membersCount;
|
int membersCount { -1 };
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const GroupRank& lhs, const GroupRank& rhs) {
|
inline bool operator==(const GroupRank& lhs, const GroupRank& rhs) {
|
||||||
|
|
|
@ -77,47 +77,11 @@ NodePermissions& NodePermissions::operator|=(const NodePermissions& rhs) {
|
||||||
permissions |= rhs.permissions;
|
permissions |= rhs.permissions;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
NodePermissions& NodePermissions::operator|=(const NodePermissionsPointer& rhs) {
|
|
||||||
if (rhs) {
|
|
||||||
*this |= *rhs.get();
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
NodePermissionsPointer& operator|=(NodePermissionsPointer& lhs, const NodePermissionsPointer& rhs) {
|
|
||||||
if (lhs && rhs) {
|
|
||||||
*lhs.get() |= rhs;
|
|
||||||
}
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
NodePermissionsPointer& operator|=(NodePermissionsPointer& lhs, NodePermissions::Permission rhs) {
|
|
||||||
if (lhs) {
|
|
||||||
lhs.get()->permissions |= rhs;
|
|
||||||
}
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
NodePermissions& NodePermissions::operator&=(const NodePermissions& rhs) {
|
NodePermissions& NodePermissions::operator&=(const NodePermissions& rhs) {
|
||||||
permissions &= rhs.permissions;
|
permissions &= rhs.permissions;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
NodePermissions& NodePermissions::operator&=(const NodePermissionsPointer& rhs) {
|
|
||||||
if (rhs) {
|
|
||||||
*this &= *rhs.get();
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
NodePermissionsPointer& operator&=(NodePermissionsPointer& lhs, const NodePermissionsPointer& rhs) {
|
|
||||||
if (lhs && rhs) {
|
|
||||||
*lhs.get() &= rhs;
|
|
||||||
}
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
NodePermissionsPointer& operator&=(NodePermissionsPointer& lhs, NodePermissions::Permission rhs) {
|
|
||||||
if (lhs) {
|
|
||||||
lhs.get()->permissions &= rhs;
|
|
||||||
}
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
NodePermissions NodePermissions::operator~() {
|
NodePermissions NodePermissions::operator~() {
|
||||||
NodePermissions result = *this;
|
NodePermissions result = *this;
|
||||||
|
@ -125,15 +89,6 @@ NodePermissions NodePermissions::operator~() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodePermissionsPointer operator~(NodePermissionsPointer& lhs) {
|
|
||||||
if (lhs) {
|
|
||||||
NodePermissionsPointer result { new NodePermissions };
|
|
||||||
(*result.get()) = ~(*lhs.get());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDataStream& operator<<(QDataStream& out, const NodePermissions& perms) {
|
QDataStream& operator<<(QDataStream& out, const NodePermissions& perms) {
|
||||||
out << (uint)perms.permissions;
|
out << (uint)perms.permissions;
|
||||||
return out;
|
return out;
|
||||||
|
|
|
@ -72,9 +72,7 @@ public:
|
||||||
void setAll(bool value);
|
void setAll(bool value);
|
||||||
|
|
||||||
NodePermissions& operator|=(const NodePermissions& rhs);
|
NodePermissions& operator|=(const NodePermissions& rhs);
|
||||||
NodePermissions& operator|=(const NodePermissionsPointer& rhs);
|
|
||||||
NodePermissions& operator&=(const NodePermissions& rhs);
|
NodePermissions& operator&=(const NodePermissions& rhs);
|
||||||
NodePermissions& operator&=(const NodePermissionsPointer& rhs);
|
|
||||||
NodePermissions operator~();
|
NodePermissions operator~();
|
||||||
friend QDataStream& operator<<(QDataStream& out, const NodePermissions& perms);
|
friend QDataStream& operator<<(QDataStream& out, const NodePermissions& perms);
|
||||||
friend QDataStream& operator>>(QDataStream& in, NodePermissions& perms);
|
friend QDataStream& operator>>(QDataStream& in, NodePermissions& perms);
|
||||||
|
@ -128,8 +126,6 @@ const NodePermissions DEFAULT_AGENT_PERMISSIONS;
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, const NodePermissions& perms);
|
QDebug operator<<(QDebug debug, const NodePermissions& perms);
|
||||||
QDebug operator<<(QDebug debug, const NodePermissionsPointer& perms);
|
QDebug operator<<(QDebug debug, const NodePermissionsPointer& perms);
|
||||||
NodePermissionsPointer& operator|=(NodePermissionsPointer& lhs, const NodePermissionsPointer& rhs);
|
|
||||||
NodePermissionsPointer& operator|=(NodePermissionsPointer& lhs, NodePermissions::Permission rhs);
|
|
||||||
NodePermissionsPointer& operator&=(NodePermissionsPointer& lhs, const NodePermissionsPointer& rhs);
|
NodePermissionsPointer& operator&=(NodePermissionsPointer& lhs, const NodePermissionsPointer& rhs);
|
||||||
NodePermissionsPointer& operator&=(NodePermissionsPointer& lhs, NodePermissions::Permission rhs);
|
NodePermissionsPointer& operator&=(NodePermissionsPointer& lhs, NodePermissions::Permission rhs);
|
||||||
NodePermissionsPointer operator~(NodePermissionsPointer& lhs);
|
NodePermissionsPointer operator~(NodePermissionsPointer& lhs);
|
||||||
|
|
Loading…
Reference in a new issue