Fixed query permission calculation
This commit is contained in:
parent
968cd7172b
commit
d6ec52b25b
@ -15,7 +15,9 @@ using ts::permission::PermissionType;
|
|||||||
using ts::permission::v2::PermissionFlaggedValue;
|
using ts::permission::v2::PermissionFlaggedValue;
|
||||||
|
|
||||||
ClientPermissionCalculator::ClientPermissionCalculator(DataClient *client, ChannelId channel_id) {
|
ClientPermissionCalculator::ClientPermissionCalculator(DataClient *client, ChannelId channel_id) {
|
||||||
|
/* Note: Order matters! */
|
||||||
this->initialize_client(client);
|
this->initialize_client(client);
|
||||||
|
this->initialize_default_groups(client->getServer());
|
||||||
|
|
||||||
auto server = client->getServer();
|
auto server = client->getServer();
|
||||||
if(server && channel_id > 0) {
|
if(server && channel_id > 0) {
|
||||||
@ -31,6 +33,7 @@ ClientPermissionCalculator::ClientPermissionCalculator(DataClient *client, Chann
|
|||||||
/* tree already write locked, no need to lock it again */
|
/* tree already write locked, no need to lock it again */
|
||||||
channel = server->getChannelTree()->findChannel(channel_id);
|
channel = server->getChannelTree()->findChannel(channel_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(channel) {
|
if(channel) {
|
||||||
this->channel_permissions = channel->permissions();
|
this->channel_permissions = channel->permissions();
|
||||||
}
|
}
|
||||||
@ -39,7 +42,10 @@ ClientPermissionCalculator::ClientPermissionCalculator(DataClient *client, Chann
|
|||||||
}
|
}
|
||||||
|
|
||||||
ClientPermissionCalculator::ClientPermissionCalculator(DataClient *client, const std::shared_ptr<BasicChannel> &channel) {
|
ClientPermissionCalculator::ClientPermissionCalculator(DataClient *client, const std::shared_ptr<BasicChannel> &channel) {
|
||||||
|
/* Note: Order matters! */
|
||||||
this->initialize_client(client);
|
this->initialize_client(client);
|
||||||
|
this->initialize_default_groups(client->getServer());
|
||||||
|
|
||||||
if(channel) {
|
if(channel) {
|
||||||
this->channel_id_ = channel->channelId();
|
this->channel_id_ = channel->channelId();
|
||||||
this->channel_permissions = channel->permissions();
|
this->channel_permissions = channel->permissions();
|
||||||
@ -62,8 +68,7 @@ ClientPermissionCalculator::ClientPermissionCalculator(
|
|||||||
if(server) {
|
if(server) {
|
||||||
this->virtual_server_id = server->getServerId();
|
this->virtual_server_id = server->getServerId();
|
||||||
this->group_manager_ = server->group_manager();
|
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{};
|
std::shared_ptr<BasicChannel> channel{};
|
||||||
try {
|
try {
|
||||||
std::shared_lock channel_lock{server->get_channel_tree_lock()};
|
std::shared_lock channel_lock{server->get_channel_tree_lock()};
|
||||||
@ -82,8 +87,9 @@ 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(); };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->initialize_default_groups(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPermissionCalculator::initialize_client(DataClient* client) {
|
void ClientPermissionCalculator::initialize_client(DataClient* client) {
|
||||||
@ -95,11 +101,20 @@ void ClientPermissionCalculator::initialize_client(DataClient* client) {
|
|||||||
auto server = client->getServer();
|
auto server = client->getServer();
|
||||||
if(server) {
|
if(server) {
|
||||||
this->group_manager_ = server->group_manager();
|
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 {
|
} else {
|
||||||
this->group_manager_ = serverInstance->group_manager();
|
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(); };
|
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(); };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ namespace ts::server {
|
|||||||
std::optional<std::vector<std::shared_ptr<groups::ServerGroup>>> assigned_server_groups_{};
|
std::optional<std::vector<std::shared_ptr<groups::ServerGroup>>> assigned_server_groups_{};
|
||||||
|
|
||||||
void initialize_client(DataClient* /* client */);
|
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::vector<std::shared_ptr<groups::ServerGroup>>& assigned_server_groups();
|
||||||
[[nodiscard]] const std::shared_ptr<groups::ChannelGroup>& assigned_channel_group();
|
[[nodiscard]] const std::shared_ptr<groups::ChannelGroup>& assigned_channel_group();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user