Fixed query permission calculation

This commit is contained in:
WolverinDEV 2021-03-22 20:46:19 +01:00
parent 968cd7172b
commit d6ec52b25b
2 changed files with 21 additions and 5 deletions

View File

@ -15,7 +15,9 @@ using ts::permission::PermissionType;
using ts::permission::v2::PermissionFlaggedValue;
ClientPermissionCalculator::ClientPermissionCalculator(DataClient *client, ChannelId channel_id) {
/* Note: Order matters! */
this->initialize_client(client);
this->initialize_default_groups(client->getServer());
auto server = client->getServer();
if(server && channel_id > 0) {
@ -31,6 +33,7 @@ ClientPermissionCalculator::ClientPermissionCalculator(DataClient *client, Chann
/* tree already write locked, no need to lock it again */
channel = server->getChannelTree()->findChannel(channel_id);
}
if(channel) {
this->channel_permissions = channel->permissions();
}
@ -39,7 +42,10 @@ ClientPermissionCalculator::ClientPermissionCalculator(DataClient *client, Chann
}
ClientPermissionCalculator::ClientPermissionCalculator(DataClient *client, const std::shared_ptr<BasicChannel> &channel) {
/* Note: Order matters! */
this->initialize_client(client);
this->initialize_default_groups(client->getServer());
if(channel) {
this->channel_id_ = channel->channelId();
this->channel_permissions = channel->permissions();
@ -62,8 +68,7 @@ ClientPermissionCalculator::ClientPermissionCalculator(
if(server) {
this->virtual_server_id = server->getServerId();
this->group_manager_ = server->group_manager();
this->default_server_group = [server]{ return server->default_server_group(); };
this->default_channel_group = [server]{ return server->default_channel_group(); };
std::shared_ptr<BasicChannel> channel{};
try {
std::shared_lock channel_lock{server->get_channel_tree_lock()};
@ -82,8 +87,9 @@ ClientPermissionCalculator::ClientPermissionCalculator(
} else {
this->virtual_server_id = 0;
this->group_manager_ = serverInstance->group_manager();
this->default_server_group = []{ return serverInstance->guest_query_group(); };
}
this->initialize_default_groups(server);
}
void ClientPermissionCalculator::initialize_client(DataClient* client) {
@ -95,11 +101,20 @@ void ClientPermissionCalculator::initialize_client(DataClient* client) {
auto server = client->getServer();
if(server) {
this->group_manager_ = server->group_manager();
this->default_server_group = [server]{ return server->default_server_group(); };
this->default_channel_group = [server]{ return server->default_channel_group(); };
} else {
this->group_manager_ = serverInstance->group_manager();
}
}
void ClientPermissionCalculator::initialize_default_groups(const std::shared_ptr<VirtualServer> &server) {
if(this->client_type == ClientType::CLIENT_QUERY) {
this->default_server_group = []{ return serverInstance->guest_query_group(); };
} else if(server) {
this->default_server_group = [server]{ return server->default_server_group(); };
}
if(server) {
this->default_server_group = [server]{ return server->default_server_group(); };
}
}

View File

@ -77,6 +77,7 @@ namespace ts::server {
std::optional<std::vector<std::shared_ptr<groups::ServerGroup>>> assigned_server_groups_{};
void initialize_client(DataClient* /* client */);
void initialize_default_groups(const std::shared_ptr<VirtualServer>& /* server */);
[[nodiscard]] const std::vector<std::shared_ptr<groups::ServerGroup>>& assigned_server_groups();
[[nodiscard]] const std::shared_ptr<groups::ChannelGroup>& assigned_channel_group();