check settings constraints in setProfile(...)

This commit is contained in:
Alexander Tokmakov 2020-12-24 20:48:54 +03:00
parent 5fbfc1935c
commit 21c3fc0e16
2 changed files with 11 additions and 17 deletions

View File

@ -157,23 +157,7 @@ bool SettingsConstraints::checkImpl(const Settings & current_settings, SettingCh
const String & setting_name = change.name;
if (setting_name == "profile")
{
/// TODO Check profile settings in Context::setProfile(...), not here. It will be backward incompatible.
const String & profile_name = change.value.safeGet<String>();
const auto & profile_settings_changes = manager->getProfileSettings(profile_name);
try
{
/// NOTE We cannot use CLAMP_ON_VIOLATION here, because we cannot modify elements of profile_settings_changes
for (auto change_copy : *profile_settings_changes)
checkImpl(current_settings, change_copy, THROW_ON_VIOLATION);
}
catch (Exception & e)
{
e.addMessage(", while trying to set settings profile {}", profile_name);
throw;
}
return true;
}
bool cannot_cast;
auto cast_value = [&](const Field & x) -> Field

View File

@ -849,7 +849,17 @@ std::optional<QuotaUsage> Context::getQuotaUsage() const
void Context::setProfile(const String & profile_name)
{
applySettingsChanges(*getAccessControlManager().getProfileSettings(profile_name));
SettingsChanges profile_settings_changes = *getAccessControlManager().getProfileSettings(profile_name);
try
{
checkSettingsConstraints(profile_settings_changes);
}
catch (Exception & e)
{
e.addMessage(", while trying to set settings profile {}", profile_name);
throw;
}
applySettingsChanges(profile_settings_changes);
}