diff --git a/server/src/PermissionCalculator.cpp b/server/src/PermissionCalculator.cpp index 71d83ee..83b26ba 100644 --- a/server/src/PermissionCalculator.cpp +++ b/server/src/PermissionCalculator.cpp @@ -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 &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 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 &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(); }; } } diff --git a/server/src/PermissionCalculator.h b/server/src/PermissionCalculator.h index ff8faab..f3cce9e 100644 --- a/server/src/PermissionCalculator.h +++ b/server/src/PermissionCalculator.h @@ -77,6 +77,7 @@ namespace ts::server { std::optional>> assigned_server_groups_{}; void initialize_client(DataClient* /* client */); + void initialize_default_groups(const std::shared_ptr& /* server */); [[nodiscard]] const std::vector>& assigned_server_groups(); [[nodiscard]] const std::shared_ptr& assigned_channel_group();