85 lines
3.3 KiB
C++
85 lines
3.3 KiB
C++
#pragma once
|
|
|
|
#include <Definitions.h>
|
|
#include <PermissionManager.h>
|
|
#include <vector>
|
|
#include <memory>
|
|
|
|
namespace ts {
|
|
class BasicChannel;
|
|
}
|
|
|
|
namespace ts::server {
|
|
class DataClient;
|
|
class VirtualServer;
|
|
|
|
namespace groups {
|
|
class ChannelGroup;
|
|
class ServerGroup;
|
|
class GroupManager;
|
|
}
|
|
|
|
/**
|
|
* Helper for calculating the client permissions for a certain channel.
|
|
* Note: All functions are not thread save!
|
|
*/
|
|
class ClientPermissionCalculator {
|
|
public:
|
|
explicit ClientPermissionCalculator(DataClient* /* client */, const std::shared_ptr<BasicChannel>& /* target channel */);
|
|
explicit ClientPermissionCalculator(DataClient* /* client */, ChannelId /* target channel id */);
|
|
explicit ClientPermissionCalculator(
|
|
const std::shared_ptr<VirtualServer>& /* server */,
|
|
ClientDbId /* client database id */,
|
|
ClientType /* client type */,
|
|
ChannelId /* target channel id */
|
|
);
|
|
|
|
/**
|
|
* Calculate the given permissions.
|
|
* This method can be called from everywhere without any locking needed.
|
|
* @param granted
|
|
* @return
|
|
*/
|
|
permission::v2::PermissionFlaggedValue calculate_permission(
|
|
permission::PermissionType,
|
|
bool granted = false
|
|
);
|
|
|
|
/**
|
|
* Calculate the given permissions.
|
|
* This method can be called from everywhere without any locking needed.
|
|
* @param channel
|
|
* @param calculate_granted
|
|
* @return
|
|
*/
|
|
std::vector<std::pair<permission::PermissionType, permission::v2::PermissionFlaggedValue>> calculate_permissions(
|
|
const std::deque<permission::PermissionType>&,
|
|
bool calculate_granted = false
|
|
);
|
|
private:
|
|
/* given fields */
|
|
ServerId virtual_server_id;
|
|
ClientDbId client_database_id;
|
|
ClientType client_type;
|
|
ChannelId channel_id_;
|
|
std::shared_ptr<groups::GroupManager> group_manager_{};
|
|
std::shared_ptr<permission::v2::PermissionManager> channel_permissions{};
|
|
std::function<std::shared_ptr<groups::ChannelGroup>()> default_channel_group{[]{ return nullptr; }};
|
|
std::function<std::shared_ptr<groups::ServerGroup>()> default_server_group{[]{ return nullptr; }};
|
|
|
|
/* fields which will be set when calculating permissions */
|
|
std::shared_ptr<permission::v2::PermissionManager> client_permissions{};
|
|
|
|
bool global_skip{false};
|
|
bool global_skip_set{false};
|
|
|
|
std::optional<std::shared_ptr<groups::ChannelGroup>> assigned_channel_group_{};
|
|
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();
|
|
};
|
|
} |