Added the permission mapping file
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "music/MusicClient.h"
|
||||
#include "query/QueryClient.h"
|
||||
#include "../weblist/WebListManager.h"
|
||||
#include "../manager/PermissionNameMapper.h"
|
||||
#include <experimental/filesystem>
|
||||
#include <cstdint>
|
||||
#include <StringVariable.h>
|
||||
@@ -42,6 +43,7 @@ extern ts::server::InstanceHandler *serverInstance;
|
||||
|
||||
#define QUERY_PASSWORD_LENGTH 12
|
||||
|
||||
//TODO: Map permsid!
|
||||
#define PARSE_PERMISSION(cmd) \
|
||||
permission::PermissionType permType = permission::PermissionType::unknown; \
|
||||
bool grant = false; \
|
||||
@@ -830,10 +832,10 @@ CommandResult ConnectedClient::handleCommandChannelUnsubscribeAll(Command &cmd)
|
||||
CommandResult ConnectedClient::handleCommandPermissionList(Command &cmd) {
|
||||
CMD_CHK_AND_INC_FLOOD_POINTS(5);
|
||||
|
||||
static std::string permission_list_string;
|
||||
static std::string permission_list_string[ClientType::MAX];
|
||||
static std::mutex permission_list_string_lock;
|
||||
|
||||
static auto build_permission_list = [](const std::string& command) {
|
||||
static auto build_permission_list = [](const std::string& command, const ClientType& type) {
|
||||
Command list_builder(command);
|
||||
int index = 0;
|
||||
for (auto group : permission::availableGroups)
|
||||
@@ -843,28 +845,31 @@ CommandResult ConnectedClient::handleCommandPermissionList(Command &cmd) {
|
||||
std::sort(avPerms.begin(), avPerms.end(), [](const std::shared_ptr<permission::PermissionTypeEntry> &a, const std::shared_ptr<permission::PermissionTypeEntry> &b) {
|
||||
return a->type < b->type;
|
||||
});
|
||||
|
||||
auto mapper = serverInstance->getPermissionMapper();
|
||||
for (const auto& permission : avPerms) {
|
||||
if (!permission->clientSupported) continue;
|
||||
|
||||
auto &blk = list_builder[index++];
|
||||
blk["permname"] = permission->name;
|
||||
blk["permname"] = mapper->permission_name(type, permission->type);
|
||||
blk["permdesc"] = permission->description;
|
||||
blk["permid"] = permission->type;
|
||||
}
|
||||
return list_builder;
|
||||
};
|
||||
|
||||
if(this->getType() == CLIENT_TEASPEAK || this->getType() == CLIENT_TEAMSPEAK || this->getType() == CLIENT_QUERY) {
|
||||
auto type = this->getType();
|
||||
if(type == CLIENT_TEASPEAK || type == CLIENT_TEAMSPEAK || type == CLIENT_QUERY) {
|
||||
Command response(this->getExternalType() == CLIENT_TEAMSPEAK ? "notifypermissionlist" : "");
|
||||
{
|
||||
lock_guard lock(permission_list_string_lock);
|
||||
if(permission_list_string.empty())
|
||||
permission_list_string = build_permission_list("").build();
|
||||
response[0][""] = permission_list_string;
|
||||
if(permission_list_string[type].empty())
|
||||
permission_list_string[type] = build_permission_list("", type).build();
|
||||
response[0][""] = permission_list_string[type];
|
||||
}
|
||||
this->sendCommand(response);
|
||||
} else {
|
||||
this->sendCommand(build_permission_list(this->getExternalType() == CLIENT_TEAMSPEAK ? "notifypermissionlist" : ""));
|
||||
this->sendCommand(build_permission_list(this->getExternalType() == CLIENT_TEAMSPEAK ? "notifypermissionlist" : "", type));
|
||||
}
|
||||
return CommandResult::Success;
|
||||
}
|
||||
@@ -2255,12 +2260,14 @@ CommandResult ConnectedClient::handleCommandChannelPermList(Command &cmd) {
|
||||
int index = 0;
|
||||
result["cid"] = channel->channelId();
|
||||
|
||||
auto permission_mapper = serverInstance->getPermissionMapper();
|
||||
auto type = this->getType();
|
||||
auto permission_manager = channel->permissions();
|
||||
for (const auto &permission_data : permission_manager->permissions()) {
|
||||
auto& permission = std::get<1>(permission_data);
|
||||
if(permission.flags.value_set) {
|
||||
if(sids) {
|
||||
result[index]["permsid"] = permission::resolvePermissionData(std::get<0>(permission_data))->name;
|
||||
result[index]["permsid"] = permission_mapper->permission_name(type, std::get<0>(permission_data));
|
||||
} else {
|
||||
result[index]["permid"] = std::get<0>(permission_data);
|
||||
}
|
||||
@@ -2272,7 +2279,7 @@ CommandResult ConnectedClient::handleCommandChannelPermList(Command &cmd) {
|
||||
}
|
||||
if(permission.flags.grant_set) {
|
||||
if(sids) {
|
||||
result[index]["permsid"] = permission::resolvePermissionData(std::get<0>(permission_data))->grant_name;
|
||||
result[index]["permsid"] = permission_mapper->permission_name_grant(type, std::get<0>(permission_data));
|
||||
} else {
|
||||
result[index]["permid"] = (uint16_t) (std::get<0>(permission_data) | PERM_ID_GRANT);
|
||||
}
|
||||
@@ -4904,11 +4911,14 @@ CommandResult ConnectedClient::handleCommandChannelClientPermList(Command &cmd)
|
||||
res[index]["cldbid"] = cmd["cldbid"].as<ClientDbId>();
|
||||
|
||||
auto sids = cmd.hasParm("permsid");
|
||||
auto permission_mapper = serverInstance->getPermissionMapper();
|
||||
auto type = this->getType();
|
||||
|
||||
for (const auto &permission_data : permissions) {
|
||||
auto& permission = std::get<1>(permission_data);
|
||||
if(permission.flags.value_set) {
|
||||
if (sids)
|
||||
res[index]["permsid"] = permission::resolvePermissionData(get<0>(permission_data))->name;
|
||||
res[index]["permsid"] = permission_mapper->permission_name(type, get<0>(permission_data));
|
||||
else
|
||||
res[index]["permid"] = get<0>(permission_data);
|
||||
res[index]["permvalue"] = permission.values.value;
|
||||
@@ -4921,7 +4931,7 @@ CommandResult ConnectedClient::handleCommandChannelClientPermList(Command &cmd)
|
||||
|
||||
if(permission.flags.grant_set) {
|
||||
if (sids)
|
||||
res[index]["permsid"] = permission::resolvePermissionData(get<0>(permission_data))->grant_name;
|
||||
res[index]["permsid"] = permission_mapper->permission_name_grant(type, get<0>(permission_data));
|
||||
else
|
||||
res[index]["permid"] = (get<0>(permission_data) | PERM_ID_GRANT);
|
||||
res[index]["permvalue"] = permission.values.grant;
|
||||
@@ -5349,12 +5359,14 @@ CommandResult ConnectedClient::handleCommandPermGet(Command &cmd) {
|
||||
Command res("");
|
||||
|
||||
deque<permission::PermissionType> requrested;
|
||||
auto permission_mapper = serverInstance->getPermissionMapper();
|
||||
auto type = this->getType();
|
||||
for (int index = 0; index < cmd.bulkCount(); index++) {
|
||||
permission::PermissionType permType = permission::unknown;
|
||||
if (cmd[index].has("permid"))
|
||||
permType = cmd[index]["permid"].as<permission::PermissionType>();
|
||||
else if (cmd[index].has("permsid"))
|
||||
permType = permission::resolvePermissionData(cmd[index]["permsid"].as<string>())->type;
|
||||
permType = permission::resolvePermissionData(cmd[index]["permsid"].as<string>())->type; //TODO: Map the other way around!
|
||||
if (permission::resolvePermissionData(permType)->type == permission::PermissionType::unknown) return {findError("parameter_invalid"), "could not resolve permission"};
|
||||
|
||||
requrested.push_back(permType);
|
||||
@@ -5362,7 +5374,7 @@ CommandResult ConnectedClient::handleCommandPermGet(Command &cmd) {
|
||||
|
||||
int index = 0;
|
||||
for(const auto& entry : this->permissionValues(permission::PERMTEST_ORDERED, requrested, this->currentChannel)) {
|
||||
res[index]["permsid"] = permission::resolvePermissionData(entry.first)->name;
|
||||
res[index]["permsid"] = permission_mapper->permission_name(type, entry.first);;
|
||||
res[index]["permid"] = entry.first;
|
||||
res[index++]["permvalue"] = entry.second;
|
||||
}
|
||||
@@ -5372,7 +5384,7 @@ CommandResult ConnectedClient::handleCommandPermGet(Command &cmd) {
|
||||
}
|
||||
|
||||
CommandResult ConnectedClient::handleCommandPermIdGetByName(Command &cmd) {
|
||||
auto found = permission::resolvePermissionData(cmd["permsid"].as<string>());
|
||||
auto found = permission::resolvePermissionData(cmd["permsid"].as<string>()); //TODO: Map the other way around
|
||||
Command res("");
|
||||
res["permid"] = found->type;
|
||||
this->sendCommand(res);
|
||||
@@ -5409,7 +5421,7 @@ CommandResult ConnectedClient::handleCommandPermFind(Command &cmd) {
|
||||
if(permission->type == permission::PermissionType::unknown)
|
||||
return {findError("parameter_invalid"), "could not resolve permission (id=" + cmd[index]["permid"].string() + ")"};
|
||||
} else if (cmd[index].has("permsid")) {
|
||||
permission = permission::resolvePermissionData(cmd[index]["permsid"].as<string>());
|
||||
permission = permission::resolvePermissionData(cmd[index]["permsid"].as<string>()); //TODO: Map the other way around
|
||||
granted = permission->grant_name == cmd[index]["permsid"].as<string>();
|
||||
|
||||
if(permission->type == permission::PermissionType::unknown)
|
||||
|
||||
Reference in New Issue
Block a user