Fixed guest server queries
This commit is contained in:
parent
41f5b30f56
commit
90fcc074f2
@ -948,4 +948,7 @@ bool InstanceHandler::validate_default_groups() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
InstancePermissionHelper::InstancePermissionHelper(InstanceHandler *instance) : instance{instance} {}
|
std::shared_ptr<groups::ServerGroup> InstanceHandler::guest_query_group() {
|
||||||
|
auto group_id = this->properties()[property::SERVERINSTANCE_GUEST_SERVERQUERY_GROUP].as_or(0);
|
||||||
|
return this->group_manager_->server_groups()->find_group(groups::GroupCalculateMode::GLOBAL, group_id);
|
||||||
|
}
|
@ -39,32 +39,6 @@ namespace ts {
|
|||||||
class ServerCommandExecutor;
|
class ServerCommandExecutor;
|
||||||
class InstanceHandler;
|
class InstanceHandler;
|
||||||
|
|
||||||
struct InstancePermissionHelper {
|
|
||||||
public:
|
|
||||||
explicit InstancePermissionHelper(InstanceHandler*);
|
|
||||||
|
|
||||||
permission::v2::PermissionFlaggedValue calculate_permission(
|
|
||||||
permission::PermissionType,
|
|
||||||
ClientDbId,
|
|
||||||
ClientType type,
|
|
||||||
ChannelId channel,
|
|
||||||
bool granted = false,
|
|
||||||
std::shared_ptr<CalculateCache> cache = nullptr
|
|
||||||
) const;
|
|
||||||
|
|
||||||
std::vector<std::pair<permission::PermissionType, permission::v2::PermissionFlaggedValue>> calculate_permissions(
|
|
||||||
const std::deque<permission::PermissionType>&,
|
|
||||||
ClientDbId,
|
|
||||||
ClientType type,
|
|
||||||
ChannelId channel,
|
|
||||||
bool granted = false,
|
|
||||||
std::shared_ptr<CalculateCache> cache = nullptr
|
|
||||||
) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
InstanceHandler* instance;
|
|
||||||
};
|
|
||||||
|
|
||||||
class InstanceHandler {
|
class InstanceHandler {
|
||||||
public:
|
public:
|
||||||
explicit InstanceHandler(SqlDataManager*);
|
explicit InstanceHandler(SqlDataManager*);
|
||||||
@ -79,6 +53,12 @@ namespace ts {
|
|||||||
std::shared_ptr<ts::server::InternalClient> getInitialServerAdmin(){ return globalServerAdmin; }
|
std::shared_ptr<ts::server::InternalClient> getInitialServerAdmin(){ return globalServerAdmin; }
|
||||||
const auto& group_manager(){ return this->group_manager_; }
|
const auto& group_manager(){ return this->group_manager_; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default instance server query group.
|
||||||
|
* @return the default group or `nullptr` if the group doesn't exists any more.
|
||||||
|
*/
|
||||||
|
[[nodiscard]] std::shared_ptr<groups::ServerGroup> guest_query_group();
|
||||||
|
|
||||||
std::shared_ptr<ts::ServerChannelTree> getChannelTree() { return this->default_tree; }
|
std::shared_ptr<ts::ServerChannelTree> getChannelTree() { return this->default_tree; }
|
||||||
std::shared_mutex& getChannelTreeLock() { return this->default_tree_lock; }
|
std::shared_mutex& getChannelTreeLock() { return this->default_tree_lock; }
|
||||||
|
|
||||||
|
@ -8,28 +8,3 @@
|
|||||||
|
|
||||||
using namespace ts;
|
using namespace ts;
|
||||||
using namespace ts::server;
|
using namespace ts::server;
|
||||||
|
|
||||||
permission::v2::PermissionFlaggedValue InstancePermissionHelper::calculate_permission(
|
|
||||||
permission::PermissionType permission,
|
|
||||||
ClientDbId cldbid,
|
|
||||||
ClientType type,
|
|
||||||
ChannelId channel,
|
|
||||||
bool granted,
|
|
||||||
std::shared_ptr<CalculateCache> cache
|
|
||||||
) const {
|
|
||||||
auto result = this->calculate_permissions({permission}, cldbid, type, channel, granted, cache);
|
|
||||||
if(result.empty()) return {0, false};
|
|
||||||
return result.front().second;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::pair<permission::PermissionType, permission::v2::PermissionFlaggedValue> > InstancePermissionHelper::calculate_permissions(
|
|
||||||
const std::deque<permission::PermissionType> &permissions,
|
|
||||||
ClientDbId cldbid,
|
|
||||||
ClientType type,
|
|
||||||
ChannelId channel,
|
|
||||||
bool granted,
|
|
||||||
std::shared_ptr<CalculateCache> /* cache */
|
|
||||||
) const {
|
|
||||||
ClientPermissionCalculator calculator{nullptr, cldbid, type, channel};
|
|
||||||
return calculator.calculate_permissions(permissions, granted);
|
|
||||||
}
|
|
@ -82,6 +82,7 @@ ClientPermissionCalculator::ClientPermissionCalculator(
|
|||||||
} else {
|
} else {
|
||||||
this->virtual_server_id = 0;
|
this->virtual_server_id = 0;
|
||||||
this->group_manager_ = serverInstance->group_manager();
|
this->group_manager_ = serverInstance->group_manager();
|
||||||
|
this->default_server_group = []{ return serverInstance->guest_query_group(); };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +99,7 @@ void ClientPermissionCalculator::initialize_client(DataClient* client) {
|
|||||||
this->default_channel_group = [server]{ return server->default_channel_group(); };
|
this->default_channel_group = [server]{ return server->default_channel_group(); };
|
||||||
} else {
|
} else {
|
||||||
this->group_manager_ = serverInstance->group_manager();
|
this->group_manager_ = serverInstance->group_manager();
|
||||||
|
this->default_server_group = []{ return serverInstance->guest_query_group(); };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1047,9 +1047,23 @@ void ConnectedClient::update_displayed_client_groups(bool& server_groups_changed
|
|||||||
|
|
||||||
if(!server_group_assignments.empty()) {
|
if(!server_group_assignments.empty()) {
|
||||||
server_group_assignments = server_group_assignments.substr(1);
|
server_group_assignments = server_group_assignments.substr(1);
|
||||||
} else if(auto default_group{ref_server->default_server_group()}; default_group) {
|
|
||||||
server_group_assignments = std::to_string(default_group->group_id());
|
|
||||||
} else {
|
} else {
|
||||||
|
if(this->getType() == ClientType::CLIENT_QUERY) {
|
||||||
|
if(auto default_group{serverInstance->guest_query_group()}; default_group) {
|
||||||
|
server_group_assignments = std::to_string(default_group->group_id());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(ref_server) {
|
||||||
|
if(auto default_group{ref_server->default_server_group()}; default_group) {
|
||||||
|
server_group_assignments = std::to_string(default_group->group_id());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* This should (in theory never happen). (But it maybe does with InternalClients idk) */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(server_group_assignments.empty()) {
|
||||||
server_group_assignments = "0";
|
server_group_assignments = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user