2020-03-04 22:27:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Access/SettingsProfileElement.h>
|
2021-07-22 16:07:03 +00:00
|
|
|
#include <Core/UUID.h>
|
2020-04-29 19:35:56 +00:00
|
|
|
#include <boost/container/flat_set.hpp>
|
2020-03-04 22:27:03 +00:00
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-07-22 16:07:03 +00:00
|
|
|
struct SettingsProfilesInfo;
|
|
|
|
|
2020-03-04 22:27:03 +00:00
|
|
|
/// Watches settings profiles for a specific user and roles.
|
|
|
|
class EnabledSettings
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Params
|
|
|
|
{
|
|
|
|
UUID user_id;
|
2020-04-29 19:35:56 +00:00
|
|
|
boost::container::flat_set<UUID> enabled_roles;
|
2020-03-04 22:27:03 +00:00
|
|
|
SettingsProfileElements settings_from_enabled_roles;
|
|
|
|
SettingsProfileElements settings_from_user;
|
|
|
|
|
|
|
|
auto toTuple() const { return std::tie(user_id, enabled_roles, settings_from_enabled_roles, settings_from_user); }
|
|
|
|
friend bool operator ==(const Params & lhs, const Params & rhs) { return lhs.toTuple() == rhs.toTuple(); }
|
|
|
|
friend bool operator !=(const Params & lhs, const Params & rhs) { return !(lhs == rhs); }
|
|
|
|
friend bool operator <(const Params & lhs, const Params & rhs) { return lhs.toTuple() < rhs.toTuple(); }
|
|
|
|
friend bool operator >(const Params & lhs, const Params & rhs) { return rhs < lhs; }
|
|
|
|
friend bool operator <=(const Params & lhs, const Params & rhs) { return !(rhs < lhs); }
|
|
|
|
friend bool operator >=(const Params & lhs, const Params & rhs) { return !(lhs < rhs); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Returns the default settings come from settings profiles defined for the user
|
|
|
|
/// and the roles passed in the constructor.
|
2021-07-22 16:07:03 +00:00
|
|
|
std::shared_ptr<const SettingsProfilesInfo> getInfo() const;
|
2020-03-04 22:27:03 +00:00
|
|
|
|
2021-07-22 16:07:03 +00:00
|
|
|
~EnabledSettings();
|
2021-03-05 14:57:16 +00:00
|
|
|
|
2020-03-04 22:27:03 +00:00
|
|
|
private:
|
|
|
|
friend class SettingsProfilesCache;
|
|
|
|
EnabledSettings(const Params & params_);
|
2021-07-22 16:07:03 +00:00
|
|
|
void setInfo(const std::shared_ptr<const SettingsProfilesInfo> & info_);
|
2020-03-04 22:27:03 +00:00
|
|
|
|
|
|
|
const Params params;
|
2021-07-22 16:07:03 +00:00
|
|
|
std::shared_ptr<const SettingsProfilesInfo> info;
|
2020-03-04 22:27:03 +00:00
|
|
|
mutable std::mutex mutex;
|
|
|
|
};
|
|
|
|
}
|